SlideShare a Scribd company logo
1 of 18
Download to read offline
I worte the code according to the requirement.And also I wrote the code to continue the program
until user enters 4 to quit the program.
If you want me to do any modifications other than these I will modify.
________________________________________
GeometricShape.java
public class GeometricShape
{
private double side1, side2, side3; //These are the variables necessary to calculat the perimeter
of a triangle
private double radius; //Radius is needed to calculate the perimeter of a circle
private double length, width; //Length and Width are needed to calculate the perimeter of a
rectangle
private boolean isTriangle = false;
private boolean isRectangle = false;
private boolean isCircle = false;
//Constructor for a triangle
public GeometricShape(double aSide1, double aSide2, double aSide3)
{
side1 = aSide1;
side2 = aSide2;
side3 = aSide3;
isTriangle = true;
}
//Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don't forget to set
isRectangle to true)
public GeometricShape(double aLength, double aWidth)
{
this.length=aLength;
this.width=aWidth;
isRectangle=true;
}
//Task #1b - Write an Overloaded Constructor for a circle here: (don't forget to set isCircle to
true)
public GeometricShape(double radius)
{
this.radius=radius;
isCircle=true;
}
public double getRadius()
{
return radius;
}
public double getSide1()
{
return side1;
}
public double getSide2()
{
return side2;
}
public double getSide3()
{
return side3;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public void setRadius(double aRadius)
{
radius = aRadius;
}
public void setSide1(double aSide1)
{
side1 = aSide1;
}
public void setSide2(double aSide2)
{
side2 = aSide2;
}
public void setSide3(double aSide3)
{
side3 = aSide3;
}
public void setLength(double aLength)
{
length = aLength;
}
public void setWidth(double aWidth)
{
width = aWidth;
}
public double getPerimeter()
{
double perimeter =0;
//Calculate the perimeter of the Geometric object depending on what the object is.
//Remember the following formulas:
//Perimeter of a Triangle = Side1 + Side2+ Side3
//Perimeter of a Rectangle = (2 * length) + (2 * width)
//Perimeter of a Circle = 2 * Math.PI * radius
if (isTriangle == true)
{
//Complete formula for triangle perimeter
perimeter = side1 + side2 + side3;
}
else if (isRectangle == true)
{
//Task 2a: Complete formula for rectangle perimeter
perimeter= (2 * length) + (2 * width);
}
else if (isCircle == true)
{
//Task 2b: Complete formula for circle perimeter
perimeter=2 * Math.PI * radius;
}
//Continue with the rest of the else if logic here.
//change return statement to match the perimeter of the shape
return perimeter;
}
public String toString()
{
if (isTriangle == true)
{
//Return "It's a Triangle: " and concatenate all the attributes of a triangle
return "It's a Triangle, with side1 = " + side1 + " side2 = " + side2 + " side3 = "+ side3;
}
else if (isRectangle == true)
{
//Task 3a: return "It's a Rectangle: " and concatenate all the attributes of a rectangle
return "It's a Rectangle, with Length = "+length+" Width = "+width;
}
else if (isCircle == true)
{
//Task 3b: return "It's a Circle: " and concatenate all the attributes of a circle
return "It's a Circle , with Radius = "+radius;
}
else
return "unknown shape";
}
}
___________________________________________
GeometryDriver.java
import java.util.Scanner;
public class GeometryDriver
{
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args)
{
int option;
do
{
//Display the following menu
displayMenu();
option = keyboard.nextInt();
processMenuSelection(option);
System.out.println("_________________________________");
}while(option!=4);
}
public static void displayMenu()
{
//Display the following menu
System.out.println("Welcome to the Geometry Calculator! "
+ "In this program we will use a menu to decide what kind of shape we will create. "
+ " 1.Create and Calculate Perimeter of a Circle"
+ " 2. Create and Calculate Perimeter of a Rectangle"
+ " 3. Create and Calculate Perimeter of a Triangle"
+ " 4. Exit");
}
public static void processMenuSelection(int option)
{
//Use a switch statement to determine the option that the user selected.
//Depending on the option that the user selected, ask the user for the appropriate information
needed to create the
//a specific geometric object. Then, call the getPerimeter() method to calculate the perimeter for
the geometric object created.
//Print the object created and its perimeter.
double userInputSide1, userInputSide2, userInputSide3; //These are the variables necessary to
calculat the perimeter of a triangle
double userInputRadius; //Radius is needed to calculate the perimeter of a circle
double userInputLength, userInputWidth;
switch (option)
{
case 1:
//ask user for the radius
System.out.print("Enter radius of circle: ");
userInputRadius = keyboard.nextDouble();
//create a GeometricShape with the radius
GeometricShape myCircle = new GeometricShape(userInputRadius);
//put logic here to call the perimeter method
System.out.println("Perimeter of the Circle :"+myCircle.getPerimeter());
System.out.println(myCircle);
break;
case 2:
//ask user for the length and width
System.out.print("Enter length of a rectangle: ");
userInputLength = keyboard.nextDouble();
System.out.print("Enter width of a rectangle: ");
userInputWidth = keyboard.nextDouble();
//create a GeometricShape with the length and width
GeometricShape myRectangle = new GeometricShape(userInputLength, userInputWidth);
//put logic here to call the perimeter method
System.out.println("Perimeter of the Rectangle :"+myRectangle.getPerimeter());
System.out.println(myRectangle);
break;
case 3:
//Using the constructors above as an example, complete the logic for a triangle:
//Task 4a: Ask user for side1, side2, and side3
System.out.print("Enter Trangle's Side 1 : ");
userInputSide1= keyboard.nextDouble();
System.out.print(" Enter Trangle's Side 2 : ");
userInputSide2= keyboard.nextDouble();
System.out.print(" Enter Trangle's Side 3 : ");
userInputSide3= keyboard.nextDouble();
//Task 4b: Create a GeometricShape with the the 3 sides
GeometricShape myTraingle=new GeometricShape(userInputSide1, userInputSide2,
userInputSide3);
//Task 4c: Put logic here to call the perimeter method
System.out.println("Perimeter of the Traingle :"+myTraingle.getPerimeter());
//Task 4d: Print the triangle object
System.out.println(myTraingle);
break;
case 4:
// Say goodbye to user.
System.out.println("Good bye!");
break;
default:
//Give message to user that option is not valid.
System.out.println("Invalid option selected. Only 1 - 4 are valid.");
}
}
}
__________________________________________________
Output:
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
1
Enter radius of circle: 5.5
Perimeter of the Circle :34.55751918948772
It's a Circle , with Radius = 5.5
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
2
Enter length of a rectangle: 5
Enter width of a rectangle: 6
Perimeter of the Rectangle :22.0
It's a Rectangle, with Length = 5.0 Width = 6.0
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
3
Enter Trangle's Side 1 : 4
Enter Trangle's Side 2 : 5
Enter Trangle's Side 3 : 6
Perimeter of the Traingle :15.0
It's a Triangle, with side1 = 4.0 side2 = 5.0 side3 = 6.0
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
4
Good bye!
_________________________________Thank You
Solution
I worte the code according to the requirement.And also I wrote the code to continue the program
until user enters 4 to quit the program.
If you want me to do any modifications other than these I will modify.
________________________________________
GeometricShape.java
public class GeometricShape
{
private double side1, side2, side3; //These are the variables necessary to calculat the perimeter
of a triangle
private double radius; //Radius is needed to calculate the perimeter of a circle
private double length, width; //Length and Width are needed to calculate the perimeter of a
rectangle
private boolean isTriangle = false;
private boolean isRectangle = false;
private boolean isCircle = false;
//Constructor for a triangle
public GeometricShape(double aSide1, double aSide2, double aSide3)
{
side1 = aSide1;
side2 = aSide2;
side3 = aSide3;
isTriangle = true;
}
//Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don't forget to set
isRectangle to true)
public GeometricShape(double aLength, double aWidth)
{
this.length=aLength;
this.width=aWidth;
isRectangle=true;
}
//Task #1b - Write an Overloaded Constructor for a circle here: (don't forget to set isCircle to
true)
public GeometricShape(double radius)
{
this.radius=radius;
isCircle=true;
}
public double getRadius()
{
return radius;
}
public double getSide1()
{
return side1;
}
public double getSide2()
{
return side2;
}
public double getSide3()
{
return side3;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public void setRadius(double aRadius)
{
radius = aRadius;
}
public void setSide1(double aSide1)
{
side1 = aSide1;
}
public void setSide2(double aSide2)
{
side2 = aSide2;
}
public void setSide3(double aSide3)
{
side3 = aSide3;
}
public void setLength(double aLength)
{
length = aLength;
}
public void setWidth(double aWidth)
{
width = aWidth;
}
public double getPerimeter()
{
double perimeter =0;
//Calculate the perimeter of the Geometric object depending on what the object is.
//Remember the following formulas:
//Perimeter of a Triangle = Side1 + Side2+ Side3
//Perimeter of a Rectangle = (2 * length) + (2 * width)
//Perimeter of a Circle = 2 * Math.PI * radius
if (isTriangle == true)
{
//Complete formula for triangle perimeter
perimeter = side1 + side2 + side3;
}
else if (isRectangle == true)
{
//Task 2a: Complete formula for rectangle perimeter
perimeter= (2 * length) + (2 * width);
}
else if (isCircle == true)
{
//Task 2b: Complete formula for circle perimeter
perimeter=2 * Math.PI * radius;
}
//Continue with the rest of the else if logic here.
//change return statement to match the perimeter of the shape
return perimeter;
}
public String toString()
{
if (isTriangle == true)
{
//Return "It's a Triangle: " and concatenate all the attributes of a triangle
return "It's a Triangle, with side1 = " + side1 + " side2 = " + side2 + " side3 = "+ side3;
}
else if (isRectangle == true)
{
//Task 3a: return "It's a Rectangle: " and concatenate all the attributes of a rectangle
return "It's a Rectangle, with Length = "+length+" Width = "+width;
}
else if (isCircle == true)
{
//Task 3b: return "It's a Circle: " and concatenate all the attributes of a circle
return "It's a Circle , with Radius = "+radius;
}
else
return "unknown shape";
}
}
___________________________________________
GeometryDriver.java
import java.util.Scanner;
public class GeometryDriver
{
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args)
{
int option;
do
{
//Display the following menu
displayMenu();
option = keyboard.nextInt();
processMenuSelection(option);
System.out.println("_________________________________");
}while(option!=4);
}
public static void displayMenu()
{
//Display the following menu
System.out.println("Welcome to the Geometry Calculator! "
+ "In this program we will use a menu to decide what kind of shape we will create. "
+ " 1.Create and Calculate Perimeter of a Circle"
+ " 2. Create and Calculate Perimeter of a Rectangle"
+ " 3. Create and Calculate Perimeter of a Triangle"
+ " 4. Exit");
}
public static void processMenuSelection(int option)
{
//Use a switch statement to determine the option that the user selected.
//Depending on the option that the user selected, ask the user for the appropriate information
needed to create the
//a specific geometric object. Then, call the getPerimeter() method to calculate the perimeter for
the geometric object created.
//Print the object created and its perimeter.
double userInputSide1, userInputSide2, userInputSide3; //These are the variables necessary to
calculat the perimeter of a triangle
double userInputRadius; //Radius is needed to calculate the perimeter of a circle
double userInputLength, userInputWidth;
switch (option)
{
case 1:
//ask user for the radius
System.out.print("Enter radius of circle: ");
userInputRadius = keyboard.nextDouble();
//create a GeometricShape with the radius
GeometricShape myCircle = new GeometricShape(userInputRadius);
//put logic here to call the perimeter method
System.out.println("Perimeter of the Circle :"+myCircle.getPerimeter());
System.out.println(myCircle);
break;
case 2:
//ask user for the length and width
System.out.print("Enter length of a rectangle: ");
userInputLength = keyboard.nextDouble();
System.out.print("Enter width of a rectangle: ");
userInputWidth = keyboard.nextDouble();
//create a GeometricShape with the length and width
GeometricShape myRectangle = new GeometricShape(userInputLength, userInputWidth);
//put logic here to call the perimeter method
System.out.println("Perimeter of the Rectangle :"+myRectangle.getPerimeter());
System.out.println(myRectangle);
break;
case 3:
//Using the constructors above as an example, complete the logic for a triangle:
//Task 4a: Ask user for side1, side2, and side3
System.out.print("Enter Trangle's Side 1 : ");
userInputSide1= keyboard.nextDouble();
System.out.print(" Enter Trangle's Side 2 : ");
userInputSide2= keyboard.nextDouble();
System.out.print(" Enter Trangle's Side 3 : ");
userInputSide3= keyboard.nextDouble();
//Task 4b: Create a GeometricShape with the the 3 sides
GeometricShape myTraingle=new GeometricShape(userInputSide1, userInputSide2,
userInputSide3);
//Task 4c: Put logic here to call the perimeter method
System.out.println("Perimeter of the Traingle :"+myTraingle.getPerimeter());
//Task 4d: Print the triangle object
System.out.println(myTraingle);
break;
case 4:
// Say goodbye to user.
System.out.println("Good bye!");
break;
default:
//Give message to user that option is not valid.
System.out.println("Invalid option selected. Only 1 - 4 are valid.");
}
}
}
__________________________________________________
Output:
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
1
Enter radius of circle: 5.5
Perimeter of the Circle :34.55751918948772
It's a Circle , with Radius = 5.5
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
2
Enter length of a rectangle: 5
Enter width of a rectangle: 6
Perimeter of the Rectangle :22.0
It's a Rectangle, with Length = 5.0 Width = 6.0
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
3
Enter Trangle's Side 1 : 4
Enter Trangle's Side 2 : 5
Enter Trangle's Side 3 : 6
Perimeter of the Traingle :15.0
It's a Triangle, with side1 = 4.0 side2 = 5.0 side3 = 6.0
_________________________________
Welcome to the Geometry Calculator!
In this program we will use a menu to decide what kind of shape we will create.
1.Create and Calculate Perimeter of a Circle
2. Create and Calculate Perimeter of a Rectangle
3. Create and Calculate Perimeter of a Triangle
4. Exit
4
Good bye!
_________________________________Thank You

More Related Content

Similar to I worte the code according to the requirement.And also I wrote the c.pdf

Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksJinTaek Seo
 
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.PunyaGowda8
 
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
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfanurag1231
 
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdfKrishnaKumar2309
 
Import java
Import javaImport java
Import javaheni2121
 
GeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdfGeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdfanokhilalmobile
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++Osama Al-Mohaia
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docxmayank272369
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 

Similar to I worte the code according to the requirement.And also I wrote the c.pdf (13)

Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
 
Pro.docx
Pro.docxPro.docx
Pro.docx
 
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
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf
19BCS2605_Krishna_Kumar_Computer_Graphics_exp_3.1.pdf
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
Import java
Import javaImport java
Import java
 
GeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdfGeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdf
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 

More from sudhinjv

1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf
1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf
1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdfsudhinjv
 
14 = disease ff24 = carriers Ff25 chances that they will pro.pdf
14 = disease ff24 = carriers Ff25  chances that they will pro.pdf14 = disease ff24 = carriers Ff25  chances that they will pro.pdf
14 = disease ff24 = carriers Ff25 chances that they will pro.pdfsudhinjv
 
Mosses, lichens are great indicators of radioactive pollution. They .pdf
  Mosses, lichens are great indicators of radioactive pollution. They .pdf  Mosses, lichens are great indicators of radioactive pollution. They .pdf
Mosses, lichens are great indicators of radioactive pollution. They .pdfsudhinjv
 
10 million.Sensory conflict theory argues , The brightest light at.pdf
10 million.Sensory conflict theory argues , The brightest light at.pdf10 million.Sensory conflict theory argues , The brightest light at.pdf
10 million.Sensory conflict theory argues , The brightest light at.pdfsudhinjv
 
We first find the slopes of the two lines 2M an.pdf
                     We first find the slopes of the two lines 2M an.pdf                     We first find the slopes of the two lines 2M an.pdf
We first find the slopes of the two lines 2M an.pdfsudhinjv
 
SO2 is a gas that mixes with water to form sulfur.pdf
                     SO2 is a gas that mixes with water to form sulfur.pdf                     SO2 is a gas that mixes with water to form sulfur.pdf
SO2 is a gas that mixes with water to form sulfur.pdfsudhinjv
 
1. Heterozygosity by migration calculated using the below formulaH.pdf
1. Heterozygosity by migration calculated using the below formulaH.pdf1. Heterozygosity by migration calculated using the below formulaH.pdf
1. Heterozygosity by migration calculated using the below formulaH.pdfsudhinjv
 
1).Monohybrid cross between true breeding parents. Assume that the.pdf
1).Monohybrid cross between true breeding parents. Assume that the.pdf1).Monohybrid cross between true breeding parents. Assume that the.pdf
1).Monohybrid cross between true breeding parents. Assume that the.pdfsudhinjv
 
1. Moving down a group, the electronegativity decreases due to the l.pdf
  1. Moving down a group, the electronegativity decreases due to the l.pdf  1. Moving down a group, the electronegativity decreases due to the l.pdf
1. Moving down a group, the electronegativity decreases due to the l.pdfsudhinjv
 
The mercury liquid and the mercury(II) oxide are .pdf
                     The mercury liquid and the mercury(II) oxide are .pdf                     The mercury liquid and the mercury(II) oxide are .pdf
The mercury liquid and the mercury(II) oxide are .pdfsudhinjv
 
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdfsudhinjv
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdfsudhinjv
 
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdf
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdfQues-6 answerThe clinical significance of beta-hemolytic (on blo.pdf
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdfsudhinjv
 
Valence electrons electrons at outer-most energy level.Effective.pdf
Valence electrons  electrons at outer-most energy level.Effective.pdfValence electrons  electrons at outer-most energy level.Effective.pdf
Valence electrons electrons at outer-most energy level.Effective.pdfsudhinjv
 
What is storage mediaAns-C. the physical material on which a co.pdf
What is storage mediaAns-C. the physical material on which a co.pdfWhat is storage mediaAns-C. the physical material on which a co.pdf
What is storage mediaAns-C. the physical material on which a co.pdfsudhinjv
 
Transactional model of communication states that if people are conne.pdf
Transactional model of communication states that if people are conne.pdfTransactional model of communication states that if people are conne.pdf
Transactional model of communication states that if people are conne.pdfsudhinjv
 
What is the measure of the strength of the relationship between inde.pdf
What is the measure of the strength of the relationship between inde.pdfWhat is the measure of the strength of the relationship between inde.pdf
What is the measure of the strength of the relationship between inde.pdfsudhinjv
 
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdf
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdfSome of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdf
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdfsudhinjv
 
Should begin with a letter and may contain additional letters and di.pdf
Should begin with a letter and may contain additional letters and di.pdfShould begin with a letter and may contain additional letters and di.pdf
Should begin with a letter and may contain additional letters and di.pdfsudhinjv
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdfsudhinjv
 

More from sudhinjv (20)

1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf
1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf
1.Rule based detection 2.Statical anomaly detection1.Rule based de.pdf
 
14 = disease ff24 = carriers Ff25 chances that they will pro.pdf
14 = disease ff24 = carriers Ff25  chances that they will pro.pdf14 = disease ff24 = carriers Ff25  chances that they will pro.pdf
14 = disease ff24 = carriers Ff25 chances that they will pro.pdf
 
Mosses, lichens are great indicators of radioactive pollution. They .pdf
  Mosses, lichens are great indicators of radioactive pollution. They .pdf  Mosses, lichens are great indicators of radioactive pollution. They .pdf
Mosses, lichens are great indicators of radioactive pollution. They .pdf
 
10 million.Sensory conflict theory argues , The brightest light at.pdf
10 million.Sensory conflict theory argues , The brightest light at.pdf10 million.Sensory conflict theory argues , The brightest light at.pdf
10 million.Sensory conflict theory argues , The brightest light at.pdf
 
We first find the slopes of the two lines 2M an.pdf
                     We first find the slopes of the two lines 2M an.pdf                     We first find the slopes of the two lines 2M an.pdf
We first find the slopes of the two lines 2M an.pdf
 
SO2 is a gas that mixes with water to form sulfur.pdf
                     SO2 is a gas that mixes with water to form sulfur.pdf                     SO2 is a gas that mixes with water to form sulfur.pdf
SO2 is a gas that mixes with water to form sulfur.pdf
 
1. Heterozygosity by migration calculated using the below formulaH.pdf
1. Heterozygosity by migration calculated using the below formulaH.pdf1. Heterozygosity by migration calculated using the below formulaH.pdf
1. Heterozygosity by migration calculated using the below formulaH.pdf
 
1).Monohybrid cross between true breeding parents. Assume that the.pdf
1).Monohybrid cross between true breeding parents. Assume that the.pdf1).Monohybrid cross between true breeding parents. Assume that the.pdf
1).Monohybrid cross between true breeding parents. Assume that the.pdf
 
1. Moving down a group, the electronegativity decreases due to the l.pdf
  1. Moving down a group, the electronegativity decreases due to the l.pdf  1. Moving down a group, the electronegativity decreases due to the l.pdf
1. Moving down a group, the electronegativity decreases due to the l.pdf
 
The mercury liquid and the mercury(II) oxide are .pdf
                     The mercury liquid and the mercury(II) oxide are .pdf                     The mercury liquid and the mercury(II) oxide are .pdf
The mercury liquid and the mercury(II) oxide are .pdf
 
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf
1 Ans Bacteria are unicellular organisms that reproduce by cell divi.pdf
 
1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf1#include stdio.h#include stdlib.h#include assert.h .pdf
1#include stdio.h#include stdlib.h#include assert.h .pdf
 
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdf
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdfQues-6 answerThe clinical significance of beta-hemolytic (on blo.pdf
Ques-6 answerThe clinical significance of beta-hemolytic (on blo.pdf
 
Valence electrons electrons at outer-most energy level.Effective.pdf
Valence electrons  electrons at outer-most energy level.Effective.pdfValence electrons  electrons at outer-most energy level.Effective.pdf
Valence electrons electrons at outer-most energy level.Effective.pdf
 
What is storage mediaAns-C. the physical material on which a co.pdf
What is storage mediaAns-C. the physical material on which a co.pdfWhat is storage mediaAns-C. the physical material on which a co.pdf
What is storage mediaAns-C. the physical material on which a co.pdf
 
Transactional model of communication states that if people are conne.pdf
Transactional model of communication states that if people are conne.pdfTransactional model of communication states that if people are conne.pdf
Transactional model of communication states that if people are conne.pdf
 
What is the measure of the strength of the relationship between inde.pdf
What is the measure of the strength of the relationship between inde.pdfWhat is the measure of the strength of the relationship between inde.pdf
What is the measure of the strength of the relationship between inde.pdf
 
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdf
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdfSome of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdf
Some of the SO32- is oxidized by atmospheric oxygen in air into SO42.pdf
 
Should begin with a letter and may contain additional letters and di.pdf
Should begin with a letter and may contain additional letters and di.pdfShould begin with a letter and may contain additional letters and di.pdf
Should begin with a letter and may contain additional letters and di.pdf
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 

I worte the code according to the requirement.And also I wrote the c.pdf

  • 1. I worte the code according to the requirement.And also I wrote the code to continue the program until user enters 4 to quit the program. If you want me to do any modifications other than these I will modify. ________________________________________ GeometricShape.java public class GeometricShape { private double side1, side2, side3; //These are the variables necessary to calculat the perimeter of a triangle private double radius; //Radius is needed to calculate the perimeter of a circle private double length, width; //Length and Width are needed to calculate the perimeter of a rectangle private boolean isTriangle = false; private boolean isRectangle = false; private boolean isCircle = false; //Constructor for a triangle public GeometricShape(double aSide1, double aSide2, double aSide3) { side1 = aSide1; side2 = aSide2; side3 = aSide3; isTriangle = true; } //Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don't forget to set isRectangle to true) public GeometricShape(double aLength, double aWidth) { this.length=aLength; this.width=aWidth; isRectangle=true; } //Task #1b - Write an Overloaded Constructor for a circle here: (don't forget to set isCircle to
  • 2. true) public GeometricShape(double radius) { this.radius=radius; isCircle=true; } public double getRadius() { return radius; } public double getSide1() { return side1; } public double getSide2() { return side2; } public double getSide3() { return side3; } public double getLength() { return length; } public double getWidth() { return width; }
  • 3. public void setRadius(double aRadius) { radius = aRadius; } public void setSide1(double aSide1) { side1 = aSide1; } public void setSide2(double aSide2) { side2 = aSide2; } public void setSide3(double aSide3) { side3 = aSide3; } public void setLength(double aLength) { length = aLength; } public void setWidth(double aWidth) { width = aWidth; } public double getPerimeter() { double perimeter =0; //Calculate the perimeter of the Geometric object depending on what the object is. //Remember the following formulas:
  • 4. //Perimeter of a Triangle = Side1 + Side2+ Side3 //Perimeter of a Rectangle = (2 * length) + (2 * width) //Perimeter of a Circle = 2 * Math.PI * radius if (isTriangle == true) { //Complete formula for triangle perimeter perimeter = side1 + side2 + side3; } else if (isRectangle == true) { //Task 2a: Complete formula for rectangle perimeter perimeter= (2 * length) + (2 * width); } else if (isCircle == true) { //Task 2b: Complete formula for circle perimeter perimeter=2 * Math.PI * radius; } //Continue with the rest of the else if logic here. //change return statement to match the perimeter of the shape return perimeter; } public String toString() { if (isTriangle == true) { //Return "It's a Triangle: " and concatenate all the attributes of a triangle return "It's a Triangle, with side1 = " + side1 + " side2 = " + side2 + " side3 = "+ side3;
  • 5. } else if (isRectangle == true) { //Task 3a: return "It's a Rectangle: " and concatenate all the attributes of a rectangle return "It's a Rectangle, with Length = "+length+" Width = "+width; } else if (isCircle == true) { //Task 3b: return "It's a Circle: " and concatenate all the attributes of a circle return "It's a Circle , with Radius = "+radius; } else return "unknown shape"; } } ___________________________________________ GeometryDriver.java import java.util.Scanner; public class GeometryDriver { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int option; do { //Display the following menu displayMenu(); option = keyboard.nextInt(); processMenuSelection(option); System.out.println("_________________________________"); }while(option!=4);
  • 6. } public static void displayMenu() { //Display the following menu System.out.println("Welcome to the Geometry Calculator! " + "In this program we will use a menu to decide what kind of shape we will create. " + " 1.Create and Calculate Perimeter of a Circle" + " 2. Create and Calculate Perimeter of a Rectangle" + " 3. Create and Calculate Perimeter of a Triangle" + " 4. Exit"); } public static void processMenuSelection(int option) { //Use a switch statement to determine the option that the user selected. //Depending on the option that the user selected, ask the user for the appropriate information needed to create the //a specific geometric object. Then, call the getPerimeter() method to calculate the perimeter for the geometric object created. //Print the object created and its perimeter. double userInputSide1, userInputSide2, userInputSide3; //These are the variables necessary to calculat the perimeter of a triangle double userInputRadius; //Radius is needed to calculate the perimeter of a circle double userInputLength, userInputWidth; switch (option) { case 1: //ask user for the radius System.out.print("Enter radius of circle: ");
  • 7. userInputRadius = keyboard.nextDouble(); //create a GeometricShape with the radius GeometricShape myCircle = new GeometricShape(userInputRadius); //put logic here to call the perimeter method System.out.println("Perimeter of the Circle :"+myCircle.getPerimeter()); System.out.println(myCircle); break; case 2: //ask user for the length and width System.out.print("Enter length of a rectangle: "); userInputLength = keyboard.nextDouble(); System.out.print("Enter width of a rectangle: "); userInputWidth = keyboard.nextDouble(); //create a GeometricShape with the length and width GeometricShape myRectangle = new GeometricShape(userInputLength, userInputWidth); //put logic here to call the perimeter method System.out.println("Perimeter of the Rectangle :"+myRectangle.getPerimeter()); System.out.println(myRectangle); break; case 3: //Using the constructors above as an example, complete the logic for a triangle: //Task 4a: Ask user for side1, side2, and side3 System.out.print("Enter Trangle's Side 1 : "); userInputSide1= keyboard.nextDouble(); System.out.print(" Enter Trangle's Side 2 : "); userInputSide2= keyboard.nextDouble(); System.out.print(" Enter Trangle's Side 3 : "); userInputSide3= keyboard.nextDouble(); //Task 4b: Create a GeometricShape with the the 3 sides GeometricShape myTraingle=new GeometricShape(userInputSide1, userInputSide2,
  • 8. userInputSide3); //Task 4c: Put logic here to call the perimeter method System.out.println("Perimeter of the Traingle :"+myTraingle.getPerimeter()); //Task 4d: Print the triangle object System.out.println(myTraingle); break; case 4: // Say goodbye to user. System.out.println("Good bye!"); break; default: //Give message to user that option is not valid. System.out.println("Invalid option selected. Only 1 - 4 are valid."); } } } __________________________________________________ Output: Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 1 Enter radius of circle: 5.5 Perimeter of the Circle :34.55751918948772 It's a Circle , with Radius = 5.5 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create.
  • 9. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 2 Enter length of a rectangle: 5 Enter width of a rectangle: 6 Perimeter of the Rectangle :22.0 It's a Rectangle, with Length = 5.0 Width = 6.0 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 3 Enter Trangle's Side 1 : 4 Enter Trangle's Side 2 : 5 Enter Trangle's Side 3 : 6 Perimeter of the Traingle :15.0 It's a Triangle, with side1 = 4.0 side2 = 5.0 side3 = 6.0 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 4 Good bye! _________________________________Thank You Solution I worte the code according to the requirement.And also I wrote the code to continue the program
  • 10. until user enters 4 to quit the program. If you want me to do any modifications other than these I will modify. ________________________________________ GeometricShape.java public class GeometricShape { private double side1, side2, side3; //These are the variables necessary to calculat the perimeter of a triangle private double radius; //Radius is needed to calculate the perimeter of a circle private double length, width; //Length and Width are needed to calculate the perimeter of a rectangle private boolean isTriangle = false; private boolean isRectangle = false; private boolean isCircle = false; //Constructor for a triangle public GeometricShape(double aSide1, double aSide2, double aSide3) { side1 = aSide1; side2 = aSide2; side3 = aSide3; isTriangle = true; } //Task #1a - Finish writing an Overloaded Constructor for a rectangle here: (don't forget to set isRectangle to true) public GeometricShape(double aLength, double aWidth) { this.length=aLength; this.width=aWidth; isRectangle=true; } //Task #1b - Write an Overloaded Constructor for a circle here: (don't forget to set isCircle to true) public GeometricShape(double radius)
  • 11. { this.radius=radius; isCircle=true; } public double getRadius() { return radius; } public double getSide1() { return side1; } public double getSide2() { return side2; } public double getSide3() { return side3; } public double getLength() { return length; } public double getWidth() { return width; } public void setRadius(double aRadius)
  • 12. { radius = aRadius; } public void setSide1(double aSide1) { side1 = aSide1; } public void setSide2(double aSide2) { side2 = aSide2; } public void setSide3(double aSide3) { side3 = aSide3; } public void setLength(double aLength) { length = aLength; } public void setWidth(double aWidth) { width = aWidth; } public double getPerimeter() { double perimeter =0; //Calculate the perimeter of the Geometric object depending on what the object is. //Remember the following formulas: //Perimeter of a Triangle = Side1 + Side2+ Side3 //Perimeter of a Rectangle = (2 * length) + (2 * width)
  • 13. //Perimeter of a Circle = 2 * Math.PI * radius if (isTriangle == true) { //Complete formula for triangle perimeter perimeter = side1 + side2 + side3; } else if (isRectangle == true) { //Task 2a: Complete formula for rectangle perimeter perimeter= (2 * length) + (2 * width); } else if (isCircle == true) { //Task 2b: Complete formula for circle perimeter perimeter=2 * Math.PI * radius; } //Continue with the rest of the else if logic here. //change return statement to match the perimeter of the shape return perimeter; } public String toString() { if (isTriangle == true) { //Return "It's a Triangle: " and concatenate all the attributes of a triangle return "It's a Triangle, with side1 = " + side1 + " side2 = " + side2 + " side3 = "+ side3; } else if (isRectangle == true)
  • 14. { //Task 3a: return "It's a Rectangle: " and concatenate all the attributes of a rectangle return "It's a Rectangle, with Length = "+length+" Width = "+width; } else if (isCircle == true) { //Task 3b: return "It's a Circle: " and concatenate all the attributes of a circle return "It's a Circle , with Radius = "+radius; } else return "unknown shape"; } } ___________________________________________ GeometryDriver.java import java.util.Scanner; public class GeometryDriver { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int option; do { //Display the following menu displayMenu(); option = keyboard.nextInt(); processMenuSelection(option); System.out.println("_________________________________"); }while(option!=4); }
  • 15. public static void displayMenu() { //Display the following menu System.out.println("Welcome to the Geometry Calculator! " + "In this program we will use a menu to decide what kind of shape we will create. " + " 1.Create and Calculate Perimeter of a Circle" + " 2. Create and Calculate Perimeter of a Rectangle" + " 3. Create and Calculate Perimeter of a Triangle" + " 4. Exit"); } public static void processMenuSelection(int option) { //Use a switch statement to determine the option that the user selected. //Depending on the option that the user selected, ask the user for the appropriate information needed to create the //a specific geometric object. Then, call the getPerimeter() method to calculate the perimeter for the geometric object created. //Print the object created and its perimeter. double userInputSide1, userInputSide2, userInputSide3; //These are the variables necessary to calculat the perimeter of a triangle double userInputRadius; //Radius is needed to calculate the perimeter of a circle double userInputLength, userInputWidth; switch (option) { case 1: //ask user for the radius System.out.print("Enter radius of circle: "); userInputRadius = keyboard.nextDouble();
  • 16. //create a GeometricShape with the radius GeometricShape myCircle = new GeometricShape(userInputRadius); //put logic here to call the perimeter method System.out.println("Perimeter of the Circle :"+myCircle.getPerimeter()); System.out.println(myCircle); break; case 2: //ask user for the length and width System.out.print("Enter length of a rectangle: "); userInputLength = keyboard.nextDouble(); System.out.print("Enter width of a rectangle: "); userInputWidth = keyboard.nextDouble(); //create a GeometricShape with the length and width GeometricShape myRectangle = new GeometricShape(userInputLength, userInputWidth); //put logic here to call the perimeter method System.out.println("Perimeter of the Rectangle :"+myRectangle.getPerimeter()); System.out.println(myRectangle); break; case 3: //Using the constructors above as an example, complete the logic for a triangle: //Task 4a: Ask user for side1, side2, and side3 System.out.print("Enter Trangle's Side 1 : "); userInputSide1= keyboard.nextDouble(); System.out.print(" Enter Trangle's Side 2 : "); userInputSide2= keyboard.nextDouble(); System.out.print(" Enter Trangle's Side 3 : "); userInputSide3= keyboard.nextDouble(); //Task 4b: Create a GeometricShape with the the 3 sides GeometricShape myTraingle=new GeometricShape(userInputSide1, userInputSide2, userInputSide3);
  • 17. //Task 4c: Put logic here to call the perimeter method System.out.println("Perimeter of the Traingle :"+myTraingle.getPerimeter()); //Task 4d: Print the triangle object System.out.println(myTraingle); break; case 4: // Say goodbye to user. System.out.println("Good bye!"); break; default: //Give message to user that option is not valid. System.out.println("Invalid option selected. Only 1 - 4 are valid."); } } } __________________________________________________ Output: Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 1 Enter radius of circle: 5.5 Perimeter of the Circle :34.55751918948772 It's a Circle , with Radius = 5.5 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle
  • 18. 3. Create and Calculate Perimeter of a Triangle 4. Exit 2 Enter length of a rectangle: 5 Enter width of a rectangle: 6 Perimeter of the Rectangle :22.0 It's a Rectangle, with Length = 5.0 Width = 6.0 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 3 Enter Trangle's Side 1 : 4 Enter Trangle's Side 2 : 5 Enter Trangle's Side 3 : 6 Perimeter of the Traingle :15.0 It's a Triangle, with side1 = 4.0 side2 = 5.0 side3 = 6.0 _________________________________ Welcome to the Geometry Calculator! In this program we will use a menu to decide what kind of shape we will create. 1.Create and Calculate Perimeter of a Circle 2. Create and Calculate Perimeter of a Rectangle 3. Create and Calculate Perimeter of a Triangle 4. Exit 4 Good bye! _________________________________Thank You