Can you do this Java program pleas

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Can you do this Java program please

Project 3Pythagorean Triples
Due on Sunday, 2/26/2023, by 11:59pm
Lab Objectives
This lab was designed to reinforce programming concepts from Chapter 4 & 5 of Java How to
Program: 11/e. In this lab you will practice:
• Nested control structures
• Using counter-controlled repetition
• Using "brute force" techniques to solve a problem
• Using counters to determine the number of iterations a loop performs
The follow-up questions and activities will also give you practice:
•
Using break statement
• Using continue statement
Problem Description
A right triangle can have sides whose lengths are all integers. The set of three integer values for
the sides of a right triangle is called a Pythagorean triple. The lengths of three sides of a right
triangle must satisfy the relationship that the sum of the squares of two sides is equal to the
square of the hypotenuse.
Write a Java application Project3_PythagoreanTriples_YourName.java to find all Pythagorean
triples for side1, side2 and the hypotenuse, all no larger than 500. Use a triple-nested for loop
that tries all possibilities. This method is an example of "brute-force" computing.
Note: Brute force refers to a programming style that does not include any shortcuts to improve
performance, but instead relies on sheer computing power to try all possibilities until the
solution to a problem is found.
Sample Output
#1 sidel: 3, side2: 4, hypotenuse: 5
sidel: 4, side2: 3, hypotenuse: 5
#2
3
sidel: 5, side2: 12, hypotenuse: 13
#4
5
sidel: 6, side2: 8, hypotenuse: 10
sidel: 7, side2: 24, hypotenuse: 25
--Configuration: <Default>
#768
sidel: 480, side2: 31, hypotenuse: 481
#769 sidel: 480, side2: 88, hypotenuse: 488
770 sidel: 480, side2: 108, hypotenuse: 492
#771 sidel: 450, side2: 140, hypotenuse: 500
#772 sidel: 483, side2: 44, hypotenuse: 485
Process completed.
Transcribed Image Text:Project 3Pythagorean Triples Due on Sunday, 2/26/2023, by 11:59pm Lab Objectives This lab was designed to reinforce programming concepts from Chapter 4 & 5 of Java How to Program: 11/e. In this lab you will practice: • Nested control structures • Using counter-controlled repetition • Using "brute force" techniques to solve a problem • Using counters to determine the number of iterations a loop performs The follow-up questions and activities will also give you practice: • Using break statement • Using continue statement Problem Description A right triangle can have sides whose lengths are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. The lengths of three sides of a right triangle must satisfy the relationship that the sum of the squares of two sides is equal to the square of the hypotenuse. Write a Java application Project3_PythagoreanTriples_YourName.java to find all Pythagorean triples for side1, side2 and the hypotenuse, all no larger than 500. Use a triple-nested for loop that tries all possibilities. This method is an example of "brute-force" computing. Note: Brute force refers to a programming style that does not include any shortcuts to improve performance, but instead relies on sheer computing power to try all possibilities until the solution to a problem is found. Sample Output #1 sidel: 3, side2: 4, hypotenuse: 5 sidel: 4, side2: 3, hypotenuse: 5 #2 3 sidel: 5, side2: 12, hypotenuse: 13 #4 5 sidel: 6, side2: 8, hypotenuse: 10 sidel: 7, side2: 24, hypotenuse: 25 --Configuration: <Default> #768 sidel: 480, side2: 31, hypotenuse: 481 #769 sidel: 480, side2: 88, hypotenuse: 488 770 sidel: 480, side2: 108, hypotenuse: 492 #771 sidel: 450, side2: 140, hypotenuse: 500 #772 sidel: 483, side2: 44, hypotenuse: 485 Process completed.
Problem-solving Tips
1. This program does not require any input from the user.
2. The formula for the Pythagorean Theorem is hypotenuse² = side 1² + side2².
3. Use brute-force computing techniques try all possible values
a. side1, side2, & hypotenuse all start with 1, possible values are 1, 2, 3, ..., 500
b. check each possible value set of (side1, side2, hypotenuse)
4. Use an if statement to determine whether the sum of the two squared sides is equal to
the hypotenuse squared. If so, output side1, side2 and hypotenuse.
5. Use a counter to record the index for each set of Pythagorean triples.
Algorithm Optimization (Extra Credit)
1. Let size2>size1 to eliminate the duplicate records
a. For example, (3, 4, 5) and (4, 3, 5) are duplicate
2. Do not be concerned about trying values that do not make sense, such as a 1-500-1
triangle. That is, skip those sets of side1, side2 & hypotenuse that do not satisfy the
following conditions
a. side1+side2 > hypotenuse
b. side1-side2 | <hypotenuse
Write break and continue statements to skip those sets.
3. Once the program is done, run it and snapshot the whole compiler window to include
both source code and output (the last part only) (and the navigation column if using
GDB online compiler). Save the image to Project3_PythagoreanTriples_Your Name.png.
4. If you have any questions as you proceed, ask your lab instructor for assistance.
Submission
Submit the completed Java program Project3_PythagoreanTriples_Your Name.java (70%) and
the picture Project3_Pythagorean Triples_YourName.png (30%) to Blackboard via the link
Project3 in Assignments section on the course page.
Transcribed Image Text:Problem-solving Tips 1. This program does not require any input from the user. 2. The formula for the Pythagorean Theorem is hypotenuse² = side 1² + side2². 3. Use brute-force computing techniques try all possible values a. side1, side2, & hypotenuse all start with 1, possible values are 1, 2, 3, ..., 500 b. check each possible value set of (side1, side2, hypotenuse) 4. Use an if statement to determine whether the sum of the two squared sides is equal to the hypotenuse squared. If so, output side1, side2 and hypotenuse. 5. Use a counter to record the index for each set of Pythagorean triples. Algorithm Optimization (Extra Credit) 1. Let size2>size1 to eliminate the duplicate records a. For example, (3, 4, 5) and (4, 3, 5) are duplicate 2. Do not be concerned about trying values that do not make sense, such as a 1-500-1 triangle. That is, skip those sets of side1, side2 & hypotenuse that do not satisfy the following conditions a. side1+side2 > hypotenuse b. side1-side2 | <hypotenuse Write break and continue statements to skip those sets. 3. Once the program is done, run it and snapshot the whole compiler window to include both source code and output (the last part only) (and the navigation column if using GDB online compiler). Save the image to Project3_PythagoreanTriples_Your Name.png. 4. If you have any questions as you proceed, ask your lab instructor for assistance. Submission Submit the completed Java program Project3_PythagoreanTriples_Your Name.java (70%) and the picture Project3_Pythagorean Triples_YourName.png (30%) to Blackboard via the link Project3 in Assignments section on the course page.
Expert Solution
Step 1

The algorithm for the java program is:

Initialize a count variable to 0.

Start a triple nested loop, with variables side1, side2, and hypotenuse representing the three sides of a right triangle.

The outer loop iterates over side1 from 1 to 500.

The second loop iterates over side2 from 1 to 500.

The innermost loop iterates over hypotenuse from 1 to 500.

The innermost loop, check if the relationship between the three sides is a Pythagorean triple (side1^2 + side2^2 =

hypotenuse^2).

If the relationship is a Pythagorean triple, increment the count and print a message indicating the side lengths and the

triple number.

Repeat the innermost loop until all combinations of side1, side2, and hypotenuse have been checked.

Repeat the second and outer loops until all combinations of side1 and side2 have been checked with all values of

hypotenuse.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education