SlideShare a Scribd company logo
1 of 9
Download to read offline
Modify your solution for PLP04 to allow the user to choose the shape to compute and report. The
change should make the "look and feel" of the program cleaner and the user experience less
cumbersome. There are several selection structure implementations (if-else, switch) that can be
used in the solution. The user should be provided with a "menu of choices" that will allow them
to identify the shape they wish to work with. A typical session might look like this:
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice: 1
Enter the side (as a decimal): 10.5
The area is 110.25
The perimeter is: 42.0
Thank you
Procedure:
Locate your PLP04.java source file in your files and edit with Eclipse.
Add the comment // modified by: ... and supply your name and the current date.
Save the program with the file name xxPLP05.java where xx are your initials. Be sure to change
the class name to this as well (to avoid the run-time error "class not found" message).
Modify the program as indicated in the Problem Statement above.
Compile the program and correct any syntax errors detected by the compiler.
When the syntax errors have been corrected, test the program in Eclipe. Before testing, on paper,
create test data and perform the computations manually. These will serve as your control for
testing.
Compare the results produced by your program with your hand derived results.
Using the commenting facility, put your test data at the end of the program file.
Notes:
Modify your copy of PLP04.java for this assignment. The original should be stored on your
flashdrive.
Use the same "prompt and respond" dialog from your version of PLP04.java to collect the data
and report the results for each of the other three shapes. A refresher:
Should the user choose the rectangle (2):
Enter the first side (as a decimal): 10.5
Enter the second side (as a decimal): 15.5
The area is 162.75
The perimeter is: 52.0
Should the user choose the circle (3)
Enter the radius (decimal): 30.2
The area is:2,865.2557
The circumference is: 189.752
Should the user choose the triangle:
Enter the height of the triangle (decimal): 3.0
Enter the base of the triangle (decimal): 4.0
The area is: 6.0
The perimeter is 12.0
When deciding on the data type to use for your sides (rectangle), radius (circle), base and height
(triangle) consider how you will use them and the numeric types that will be used in the
computations.
Declare PI as a named constant and assign it the value of 3.14159 at the time of declaration.
Notice that the example above strongly suggests that your program will require a series of
interactions with the user in order to gather data for each set of shape calculations.
Assume you will be working with a right triangle (a triangle of 90 degrees).
Some calculations you may find useful:
for the perimeter of a rectangle:
perimeter = 2 * (side1 + side2)
for the circumference of a circle:
circumference = 2 * PI * radius
for the perimeter of a triangle:
perimeter = base + height + hypotenuse
to find the hypotenuse of the right triangle:
hyptenuse2 = base2 + height2
Here is the original, from what we should be working with.
import java.util.Scanner;
public class PLP04 {
public static void main (String[] args)
{
double side1 = 0.0;
double side2 = 0.0;
double radius = 0.0;
double base = 0.0;
double height = 0.0;
double hypotenuse = 0.0;
final double PI = 3.14159;
System.out.print("Enter the first side ");
Scanner inData; // A class that reads input
inData = new Scanner(System.in);
System.out.print(" Enter the length of a side ");
side1 = inData.nextDouble();
System.out.print(" Enter the length of second side ");
side2 = inData.nextDouble();
System.out.println(" The area is " + side1 * side2 + " ");
System.out.println("The perimeter is " + 2 * (side1 + side2));
System.out.print(" Enter the radius (decimal):");
radius = inData.nextDouble();
System.out.println("The area is:" + radius * radius * PI);
System.out.println("The circumference is:" + 2 * PI * radius);
System.out.print(" Enter the height of the triangle (decimal):");
height= inData.nextDouble();
System.out.print("Enter the base of the triangle (decimal):");
base = inData.nextDouble();
hypotenuse = Math.sqrt((base * base) + (height * height));
System.out.println(" The area is: " + (base * height)/2 + " ");
System.out.println(" The perimeter is " + (base + height + hypotenuse) + " ");
// Enter the first side (as a decimal): 20.5
// Enter the second side (as a decimal): 15.0
// The area is = 20.5 * 15.0 = 307.5
// The perimeter is = 2(20.5 + 15.0) = 71.0
//
// Enter the radius (decimal): 30.2
// The area is = 30.2 * 3.14 * 3.14 = 2,865.2557
// The circumference is = 2 * 30.2 * 3.14 = 189.752
//
// Enter the height of the triangle (decimal): 3.0
// Enter the base of the triangle (decimal): 4.0
// The area is = (3 * 4)/2 = 6.0
//
}
}
Solution
PLP04.java
import java.util.Scanner;
public class PLP04 {
//Declaring constant
public static final double PI = 3.14159;
public static void main(String[] args) {
//Declaring variable
int choice;
//Scanner class Obejct is used to read the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continues to execute until user enters choice '5'
do {
//Displaying the menu
System.out.println("  Choose the shape");
System.out.println("1. Square");
System.out.println("2. Rectangle");
System.out.println("3. Circle");
System.out.println("4. Triangle");
System.out.println("5. Quit");
System.out.print("Enter your choice:");
choice = sc.nextInt();
//Based on the User selection the corresponding case will be executed
switch (choice) {
//This case will calculate the area and perimeter of the square
case 1: {
//Declaring variables
double side, area, perimeter;
//Getting the side of the square entered by the user
System.out.print("Enter the side (as a decimal):");
side = sc.nextDouble();
//calculating the area of the square
area = side * side;
//calculating the perimeter of the square
perimeter = 4 * side;
//Displaying the area of the square
System.out.println("The area is " + area);
//Displaying the perimeter of the square;
System.out.println("The perimeter is " + perimeter);
break;
}
case 2: {
//Declaring variables
double firstside, secondside, area, perimeter;
//Getting the first side of the rectangle
System.out.print("Enter the first side (as a decimal):");
firstside = sc.nextDouble();
//Getting the second side of the rectangle
System.out.print("Enter the second side (as a decimal):");
secondside = sc.nextDouble();
//Calculating the area of the rectangle
area = firstside * secondside;
//Calculating the perimeter of the rectangle
perimeter = 2 * firstside + 2 * secondside;
//Displaying the area of the rectangle
System.out.println("The area is " + area);
//Displaying the perimeter of the rectangle
System.out.println("The perimeter is: " + perimeter);
break;
}
case 3: {
//Declaring variables
double radius, area, circumference;
//Getting the radius of the circle
System.out.print("Enter the radius (decimal):");
radius = sc.nextDouble();
//calculating the area of the circle
area = PI * radius * radius;
//calculating the circumference of the circle
circumference = 2 * PI * radius;
//displaying the area of the circle
System.out.printf("The area is %.2f ", area);
//displaying the circumference of the circle
System.out.printf(" The circumference is %.2f ", circumference);
break;
}
case 4: {
//Declaring variables
double height, base, area, perimeter, hypotenuse;
//Getting the height of the triangle
System.out.print("Enter the height of the triangle (decimal):");
height = sc.nextDouble();
//Getting the base of the triangle
System.out.print("Enter the base of the triangle (decimal):");
base = sc.nextDouble();
//calculating the area of the triangle
area = 0.5 * base * height;
//calculating the hypotenuse of the triangle
hypotenuse = Math.sqrt(Math.pow(base, 2) + Math.pow(height, 2));
//Calculating the perimeter of the triangle
perimeter = base + height + hypotenuse;
//Displaying the area of the triangle
System.out.printf("The area is %.2f", area);
//Displaying the perimeter of the triangle
System.out.printf(" The perimeter is %.2f", perimeter);
break;
}
case 5: {
break;
}
}
} while (choice != 5);
}
}
______________________________________
output:
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice:1
Enter the side (as a decimal):10.5
The area is 110.25
The perimeter is 42.0
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice:2
Enter the first side (as a decimal):10.5
Enter the second side (as a decimal):15.5
The area is 162.75
The perimeter is: 52.0
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice:3
Enter the radius (decimal):30.2
The area is 2865.26
The circumference is 189.75
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice:4
Enter the height of the triangle (decimal):3.0
Enter the base of the triangle (decimal):4.0
The area is 6.00
The perimeter is 12.00
Choose the shape
1. Square
2. Rectangle
3. Circle
4. Triangle
5. Quit
Enter your choice:5
________________Thank You

More Related Content

Similar to Modify your solution for PLP04 to allow the user to choose the shape.pdf

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfsudhinjv
 
Variants Density along DNA Sequence
Variants Density along DNA SequenceVariants Density along DNA Sequence
Variants Density along DNA SequenceYoann Pageaud
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
In this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdfIn this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdffathimafancy
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerAiman Hud
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfrajaratna4
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfarihantmum
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 

Similar to Modify your solution for PLP04 to allow the user to choose the shape.pdf (18)

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
srgoc
srgocsrgoc
srgoc
 
I worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdfI worte the code according to the requirement.And also I wrote the c.pdf
I worte the code according to the requirement.And also I wrote the c.pdf
 
Ch3
Ch3Ch3
Ch3
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
 
Variants Density along DNA Sequence
Variants Density along DNA SequenceVariants Density along DNA Sequence
Variants Density along DNA Sequence
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
In this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdfIn this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdf
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdf
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 

More from hullibergerr25980

Is the following set of vectors a linearly independent subset of M_2,.pdf
Is the following set of vectors a linearly independent subset of M_2,.pdfIs the following set of vectors a linearly independent subset of M_2,.pdf
Is the following set of vectors a linearly independent subset of M_2,.pdfhullibergerr25980
 
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdf
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdfImagine you are an Egyptian artist in the Old Kingdom. What characte.pdf
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdfhullibergerr25980
 
Please explain this in detail. Thank you1) Why do endosymbionts te.pdf
Please explain this in detail. Thank you1) Why do endosymbionts te.pdfPlease explain this in detail. Thank you1) Why do endosymbionts te.pdf
Please explain this in detail. Thank you1) Why do endosymbionts te.pdfhullibergerr25980
 
If S1^2 and S2^2 are the variances of independent random samples of s.pdf
If S1^2 and S2^2 are the variances of independent random samples of s.pdfIf S1^2 and S2^2 are the variances of independent random samples of s.pdf
If S1^2 and S2^2 are the variances of independent random samples of s.pdfhullibergerr25980
 
How do bacteria that use a flagellum for motion direct their movemen.pdf
How do bacteria that use a flagellum for motion direct their movemen.pdfHow do bacteria that use a flagellum for motion direct their movemen.pdf
How do bacteria that use a flagellum for motion direct their movemen.pdfhullibergerr25980
 
One can implement a priority queue by an unsorted array or a binary .pdf
One can implement a priority queue by an unsorted array or a binary .pdfOne can implement a priority queue by an unsorted array or a binary .pdf
One can implement a priority queue by an unsorted array or a binary .pdfhullibergerr25980
 
Match each stage in the database design life cycle to the correct des.pdf
Match each stage in the database design life cycle to the correct des.pdfMatch each stage in the database design life cycle to the correct des.pdf
Match each stage in the database design life cycle to the correct des.pdfhullibergerr25980
 
Why is the concept of randomness important in inferential statistics.pdf
Why is the concept of randomness important in inferential statistics.pdfWhy is the concept of randomness important in inferential statistics.pdf
Why is the concept of randomness important in inferential statistics.pdfhullibergerr25980
 
What kind of sensors are photogrammetry sensors Lidar, Pas.pdf
What kind of sensors are photogrammetry sensors Lidar, Pas.pdfWhat kind of sensors are photogrammetry sensors Lidar, Pas.pdf
What kind of sensors are photogrammetry sensors Lidar, Pas.pdfhullibergerr25980
 
What explains the rapid growth in private investment in e-commerce f.pdf
What explains the rapid growth in private investment in e-commerce f.pdfWhat explains the rapid growth in private investment in e-commerce f.pdf
What explains the rapid growth in private investment in e-commerce f.pdfhullibergerr25980
 
What is binary fission and how does it relatecompare to mitosis or .pdf
What is binary fission and how does it relatecompare to mitosis or .pdfWhat is binary fission and how does it relatecompare to mitosis or .pdf
What is binary fission and how does it relatecompare to mitosis or .pdfhullibergerr25980
 
What is a dynamic variable Compare the differences between dynamic v.pdf
What is a dynamic variable Compare the differences between dynamic v.pdfWhat is a dynamic variable Compare the differences between dynamic v.pdf
What is a dynamic variable Compare the differences between dynamic v.pdfhullibergerr25980
 
What are Database Access Types. Please give detailed explanation to .pdf
What are Database Access Types. Please give detailed explanation to .pdfWhat are Database Access Types. Please give detailed explanation to .pdf
What are Database Access Types. Please give detailed explanation to .pdfhullibergerr25980
 
What are the conditions that are favorable for extensive solid solubi.pdf
What are the conditions that are favorable for extensive solid solubi.pdfWhat are the conditions that are favorable for extensive solid solubi.pdf
What are the conditions that are favorable for extensive solid solubi.pdfhullibergerr25980
 
We are interested in determining whether leaf traits for the Totavi .pdf
We are interested in determining whether leaf traits for the Totavi .pdfWe are interested in determining whether leaf traits for the Totavi .pdf
We are interested in determining whether leaf traits for the Totavi .pdfhullibergerr25980
 
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdf
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdfStandardized in SD units; allows scores to be compared. (NOTE Two w.pdf
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdfhullibergerr25980
 

More from hullibergerr25980 (16)

Is the following set of vectors a linearly independent subset of M_2,.pdf
Is the following set of vectors a linearly independent subset of M_2,.pdfIs the following set of vectors a linearly independent subset of M_2,.pdf
Is the following set of vectors a linearly independent subset of M_2,.pdf
 
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdf
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdfImagine you are an Egyptian artist in the Old Kingdom. What characte.pdf
Imagine you are an Egyptian artist in the Old Kingdom. What characte.pdf
 
Please explain this in detail. Thank you1) Why do endosymbionts te.pdf
Please explain this in detail. Thank you1) Why do endosymbionts te.pdfPlease explain this in detail. Thank you1) Why do endosymbionts te.pdf
Please explain this in detail. Thank you1) Why do endosymbionts te.pdf
 
If S1^2 and S2^2 are the variances of independent random samples of s.pdf
If S1^2 and S2^2 are the variances of independent random samples of s.pdfIf S1^2 and S2^2 are the variances of independent random samples of s.pdf
If S1^2 and S2^2 are the variances of independent random samples of s.pdf
 
How do bacteria that use a flagellum for motion direct their movemen.pdf
How do bacteria that use a flagellum for motion direct their movemen.pdfHow do bacteria that use a flagellum for motion direct their movemen.pdf
How do bacteria that use a flagellum for motion direct their movemen.pdf
 
One can implement a priority queue by an unsorted array or a binary .pdf
One can implement a priority queue by an unsorted array or a binary .pdfOne can implement a priority queue by an unsorted array or a binary .pdf
One can implement a priority queue by an unsorted array or a binary .pdf
 
Match each stage in the database design life cycle to the correct des.pdf
Match each stage in the database design life cycle to the correct des.pdfMatch each stage in the database design life cycle to the correct des.pdf
Match each stage in the database design life cycle to the correct des.pdf
 
Why is the concept of randomness important in inferential statistics.pdf
Why is the concept of randomness important in inferential statistics.pdfWhy is the concept of randomness important in inferential statistics.pdf
Why is the concept of randomness important in inferential statistics.pdf
 
What kind of sensors are photogrammetry sensors Lidar, Pas.pdf
What kind of sensors are photogrammetry sensors Lidar, Pas.pdfWhat kind of sensors are photogrammetry sensors Lidar, Pas.pdf
What kind of sensors are photogrammetry sensors Lidar, Pas.pdf
 
What explains the rapid growth in private investment in e-commerce f.pdf
What explains the rapid growth in private investment in e-commerce f.pdfWhat explains the rapid growth in private investment in e-commerce f.pdf
What explains the rapid growth in private investment in e-commerce f.pdf
 
What is binary fission and how does it relatecompare to mitosis or .pdf
What is binary fission and how does it relatecompare to mitosis or .pdfWhat is binary fission and how does it relatecompare to mitosis or .pdf
What is binary fission and how does it relatecompare to mitosis or .pdf
 
What is a dynamic variable Compare the differences between dynamic v.pdf
What is a dynamic variable Compare the differences between dynamic v.pdfWhat is a dynamic variable Compare the differences between dynamic v.pdf
What is a dynamic variable Compare the differences between dynamic v.pdf
 
What are Database Access Types. Please give detailed explanation to .pdf
What are Database Access Types. Please give detailed explanation to .pdfWhat are Database Access Types. Please give detailed explanation to .pdf
What are Database Access Types. Please give detailed explanation to .pdf
 
What are the conditions that are favorable for extensive solid solubi.pdf
What are the conditions that are favorable for extensive solid solubi.pdfWhat are the conditions that are favorable for extensive solid solubi.pdf
What are the conditions that are favorable for extensive solid solubi.pdf
 
We are interested in determining whether leaf traits for the Totavi .pdf
We are interested in determining whether leaf traits for the Totavi .pdfWe are interested in determining whether leaf traits for the Totavi .pdf
We are interested in determining whether leaf traits for the Totavi .pdf
 
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdf
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdfStandardized in SD units; allows scores to be compared. (NOTE Two w.pdf
Standardized in SD units; allows scores to be compared. (NOTE Two w.pdf
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Modify your solution for PLP04 to allow the user to choose the shape.pdf

  • 1. Modify your solution for PLP04 to allow the user to choose the shape to compute and report. The change should make the "look and feel" of the program cleaner and the user experience less cumbersome. There are several selection structure implementations (if-else, switch) that can be used in the solution. The user should be provided with a "menu of choices" that will allow them to identify the shape they wish to work with. A typical session might look like this: Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle 5. Quit Enter your choice: 1 Enter the side (as a decimal): 10.5 The area is 110.25 The perimeter is: 42.0 Thank you Procedure: Locate your PLP04.java source file in your files and edit with Eclipse. Add the comment // modified by: ... and supply your name and the current date. Save the program with the file name xxPLP05.java where xx are your initials. Be sure to change the class name to this as well (to avoid the run-time error "class not found" message). Modify the program as indicated in the Problem Statement above. Compile the program and correct any syntax errors detected by the compiler. When the syntax errors have been corrected, test the program in Eclipe. Before testing, on paper, create test data and perform the computations manually. These will serve as your control for testing. Compare the results produced by your program with your hand derived results. Using the commenting facility, put your test data at the end of the program file. Notes: Modify your copy of PLP04.java for this assignment. The original should be stored on your flashdrive.
  • 2. Use the same "prompt and respond" dialog from your version of PLP04.java to collect the data and report the results for each of the other three shapes. A refresher: Should the user choose the rectangle (2): Enter the first side (as a decimal): 10.5 Enter the second side (as a decimal): 15.5 The area is 162.75 The perimeter is: 52.0 Should the user choose the circle (3) Enter the radius (decimal): 30.2 The area is:2,865.2557 The circumference is: 189.752 Should the user choose the triangle: Enter the height of the triangle (decimal): 3.0 Enter the base of the triangle (decimal): 4.0 The area is: 6.0 The perimeter is 12.0 When deciding on the data type to use for your sides (rectangle), radius (circle), base and height (triangle) consider how you will use them and the numeric types that will be used in the computations. Declare PI as a named constant and assign it the value of 3.14159 at the time of declaration. Notice that the example above strongly suggests that your program will require a series of interactions with the user in order to gather data for each set of shape calculations. Assume you will be working with a right triangle (a triangle of 90 degrees). Some calculations you may find useful: for the perimeter of a rectangle: perimeter = 2 * (side1 + side2) for the circumference of a circle: circumference = 2 * PI * radius for the perimeter of a triangle: perimeter = base + height + hypotenuse to find the hypotenuse of the right triangle:
  • 3. hyptenuse2 = base2 + height2 Here is the original, from what we should be working with. import java.util.Scanner; public class PLP04 { public static void main (String[] args) { double side1 = 0.0; double side2 = 0.0; double radius = 0.0; double base = 0.0; double height = 0.0; double hypotenuse = 0.0; final double PI = 3.14159; System.out.print("Enter the first side "); Scanner inData; // A class that reads input inData = new Scanner(System.in); System.out.print(" Enter the length of a side "); side1 = inData.nextDouble(); System.out.print(" Enter the length of second side "); side2 = inData.nextDouble(); System.out.println(" The area is " + side1 * side2 + " "); System.out.println("The perimeter is " + 2 * (side1 + side2)); System.out.print(" Enter the radius (decimal):"); radius = inData.nextDouble(); System.out.println("The area is:" + radius * radius * PI); System.out.println("The circumference is:" + 2 * PI * radius); System.out.print(" Enter the height of the triangle (decimal):"); height= inData.nextDouble(); System.out.print("Enter the base of the triangle (decimal):"); base = inData.nextDouble(); hypotenuse = Math.sqrt((base * base) + (height * height)); System.out.println(" The area is: " + (base * height)/2 + " "); System.out.println(" The perimeter is " + (base + height + hypotenuse) + " "); // Enter the first side (as a decimal): 20.5
  • 4. // Enter the second side (as a decimal): 15.0 // The area is = 20.5 * 15.0 = 307.5 // The perimeter is = 2(20.5 + 15.0) = 71.0 // // Enter the radius (decimal): 30.2 // The area is = 30.2 * 3.14 * 3.14 = 2,865.2557 // The circumference is = 2 * 30.2 * 3.14 = 189.752 // // Enter the height of the triangle (decimal): 3.0 // Enter the base of the triangle (decimal): 4.0 // The area is = (3 * 4)/2 = 6.0 // } } Solution PLP04.java import java.util.Scanner; public class PLP04 { //Declaring constant public static final double PI = 3.14159; public static void main(String[] args) { //Declaring variable int choice; //Scanner class Obejct is used to read the inputs entered by the user Scanner sc = new Scanner(System.in); //This loop continues to execute until user enters choice '5' do { //Displaying the menu System.out.println(" Choose the shape"); System.out.println("1. Square");
  • 5. System.out.println("2. Rectangle"); System.out.println("3. Circle"); System.out.println("4. Triangle"); System.out.println("5. Quit"); System.out.print("Enter your choice:"); choice = sc.nextInt(); //Based on the User selection the corresponding case will be executed switch (choice) { //This case will calculate the area and perimeter of the square case 1: { //Declaring variables double side, area, perimeter; //Getting the side of the square entered by the user System.out.print("Enter the side (as a decimal):"); side = sc.nextDouble(); //calculating the area of the square area = side * side; //calculating the perimeter of the square perimeter = 4 * side; //Displaying the area of the square System.out.println("The area is " + area); //Displaying the perimeter of the square; System.out.println("The perimeter is " + perimeter); break; } case 2: { //Declaring variables double firstside, secondside, area, perimeter;
  • 6. //Getting the first side of the rectangle System.out.print("Enter the first side (as a decimal):"); firstside = sc.nextDouble(); //Getting the second side of the rectangle System.out.print("Enter the second side (as a decimal):"); secondside = sc.nextDouble(); //Calculating the area of the rectangle area = firstside * secondside; //Calculating the perimeter of the rectangle perimeter = 2 * firstside + 2 * secondside; //Displaying the area of the rectangle System.out.println("The area is " + area); //Displaying the perimeter of the rectangle System.out.println("The perimeter is: " + perimeter); break; } case 3: { //Declaring variables double radius, area, circumference; //Getting the radius of the circle System.out.print("Enter the radius (decimal):"); radius = sc.nextDouble(); //calculating the area of the circle area = PI * radius * radius; //calculating the circumference of the circle circumference = 2 * PI * radius; //displaying the area of the circle
  • 7. System.out.printf("The area is %.2f ", area); //displaying the circumference of the circle System.out.printf(" The circumference is %.2f ", circumference); break; } case 4: { //Declaring variables double height, base, area, perimeter, hypotenuse; //Getting the height of the triangle System.out.print("Enter the height of the triangle (decimal):"); height = sc.nextDouble(); //Getting the base of the triangle System.out.print("Enter the base of the triangle (decimal):"); base = sc.nextDouble(); //calculating the area of the triangle area = 0.5 * base * height; //calculating the hypotenuse of the triangle hypotenuse = Math.sqrt(Math.pow(base, 2) + Math.pow(height, 2)); //Calculating the perimeter of the triangle perimeter = base + height + hypotenuse; //Displaying the area of the triangle System.out.printf("The area is %.2f", area); //Displaying the perimeter of the triangle System.out.printf(" The perimeter is %.2f", perimeter); break; } case 5: {
  • 8. break; } } } while (choice != 5); } } ______________________________________ output: Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle 5. Quit Enter your choice:1 Enter the side (as a decimal):10.5 The area is 110.25 The perimeter is 42.0 Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle 5. Quit Enter your choice:2 Enter the first side (as a decimal):10.5 Enter the second side (as a decimal):15.5 The area is 162.75 The perimeter is: 52.0 Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle
  • 9. 5. Quit Enter your choice:3 Enter the radius (decimal):30.2 The area is 2865.26 The circumference is 189.75 Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle 5. Quit Enter your choice:4 Enter the height of the triangle (decimal):3.0 Enter the base of the triangle (decimal):4.0 The area is 6.00 The perimeter is 12.00 Choose the shape 1. Square 2. Rectangle 3. Circle 4. Triangle 5. Quit Enter your choice:5 ________________Thank You