SlideShare a Scribd company logo
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_jintaeks
JinTaek 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
 
Pro.docx
Pro.docxPro.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
fathimafancy
 
Chapter 2
Chapter 2Chapter 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
anurag1231
 
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
KrishnaKumar2309
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
SanketAde1
 
Import java
Import javaImport java
Import java
heni2121
 
GeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdfGeometricObject.javapublic interface GeometricObject { Declari.pdf
GeometricObject.javapublic interface GeometricObject { Declari.pdf
anokhilalmobile
 
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.docx
mayank272369
 
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
contact41
 

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.pdf
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
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
sudhinjv
 
#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
sudhinjv
 

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

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

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