SlideShare a Scribd company logo
1 of 14
Download to read offline
Circle.java
import java.text.DecimalFormat;
public class Circle {
//declaring variable
private double radius;
//Parameterized constructor
public Circle(double radius) {
this.radius = radius;
}
//Setters and getters
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//calcArea() method is used to calculate the area of the circle
public double calcArea() {
double area=3.14*radius*radius;
return area;
}
//toString() method is used to display the contents of the Object inside it.
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Circle# Radius=" + radius + " Area=" +df.format(calcArea());
}
}
___________________________________________________
Rectangle.java
import java.text.DecimalFormat;
public class Rectangle {
//declaring variable
private double length;
private double width;
//Parameterized constructor
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
//Setters and getters
public double getlength() {
return length;
}
public void setlength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
//calcArea() method is used to calculate the area of the Rectangle
public double calcArea() {
double area=width* length;
return area;
}
//calcArea() method is used to calculate the area of the circle
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Rectangle# length=" + length + " Width=" + width + "
Area="+df.format(calcArea());
}
}
____________________________________________
Triangle.java
import java.text.DecimalFormat;
public class Triangle{
//declaring variable
private double base;
private double height;
//Parameterized constructor
public Triangle(double base,double height) {
this.base=base;
this.height=height;
}
//Setters and getters
public double getBase() {
return base;
}
public void setBase(double base) {
this.base = base;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
//calcArea() method is used to calculate the area of the Triangle
public double calcArea() {
double area=0.5*base*height;
return area;
}
//calcArea() method is used to calculate the area of the circle
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Triangle# Base=" + base + " Height=" + height + "
Area="+df.format(calcArea());
}
}
___________________________________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//Declaring variables
int choice;
char ch;
//Scanner Object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//This loop will continue to execute until user enters other than 'y' or 'Y'
do
{
//Displaying the menu
System.out.println(" ::Program Which Calculates the Area of the following Shapes::");
System.out.println("::Menu::");
System.out.println("1.Rectangle");
System.out.println("2.Circle");
System.out.println("3.Triangle");
//Getting the choice entered by the user
System.out.print("Enter Choice :");
choice=sc.nextInt();
//Based on the users choice corresponding case will be executed.
switch(choice)
{
case 1:
{
//Getting the length of the Rectangle
System.out.print("Enter the Length :");
double length=sc.nextDouble();
//Getting the width of the Rectangle
System.out.print(" Enter the Width :");
double width=sc.nextDouble();
//Creating the Rectangle Object by passing the length and width as parameters
Rectangle rect=new Rectangle(length, width);
//Displaying the contents of the Rectangle Object
System.out.println(rect.toString());
break;
}
case 2:
{
//Getting the Radius of the Circle
System.out.print("Enter the Radius:");
double radius=sc.nextDouble();
//Creating the Circle Object by passing the radius as parameter
Circle c=new Circle(radius);
//Displaying the contents of the Circle Object
System.out.println(c.toString());
break;
}
case 3:
{
//getting the base of the triangle
System.out.print("Enter the Base:");
double base=sc.nextDouble();
//getting the Height of the triangle
System.out.print(" Enter the Height:");
double height=sc.nextDouble();
//Creating the triangle Object by passing the area and height as parameters
Triangle t=new Triangle(base,height);
System.out.println(t.toString());
break;
}
default :
{
//If the user entered choice other than 1 or 2 or 3 then this error message will be displayed
System.out.println("Invalid Choice,Enter Valid choice");
break;
}
}
//Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Do you want to continue(Y/N) ::");
ch = sc.next(".").charAt(0);
}while(ch=='y'|| ch=='Y');
}
}
______________________________________________
Output:
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :1
Enter the Length :4
Enter the Width :5
Rectangle#
length=4.0
Width=5.0
Area=20
Do you want to continue(Y/N) ::y
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :2
Enter the Radius:5.5
Circle#
Radius=5.5
Area=94.98
Do you want to continue(Y/N) ::y
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :3
Enter the Base:6
Enter the Height:7
Triangle#
Base=6.0
Height=7.0
Area=21
Do you want to continue(Y/N) ::n
________________________________________________Thank You
Solution
Circle.java
import java.text.DecimalFormat;
public class Circle {
//declaring variable
private double radius;
//Parameterized constructor
public Circle(double radius) {
this.radius = radius;
}
//Setters and getters
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//calcArea() method is used to calculate the area of the circle
public double calcArea() {
double area=3.14*radius*radius;
return area;
}
//toString() method is used to display the contents of the Object inside it.
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Circle# Radius=" + radius + " Area=" +df.format(calcArea());
}
}
___________________________________________________
Rectangle.java
import java.text.DecimalFormat;
public class Rectangle {
//declaring variable
private double length;
private double width;
//Parameterized constructor
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
//Setters and getters
public double getlength() {
return length;
}
public void setlength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
//calcArea() method is used to calculate the area of the Rectangle
public double calcArea() {
double area=width* length;
return area;
}
//calcArea() method is used to calculate the area of the circle
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Rectangle# length=" + length + " Width=" + width + "
Area="+df.format(calcArea());
}
}
____________________________________________
Triangle.java
import java.text.DecimalFormat;
public class Triangle{
//declaring variable
private double base;
private double height;
//Parameterized constructor
public Triangle(double base,double height) {
this.base=base;
this.height=height;
}
//Setters and getters
public double getBase() {
return base;
}
public void setBase(double base) {
this.base = base;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
//calcArea() method is used to calculate the area of the Triangle
public double calcArea() {
double area=0.5*base*height;
return area;
}
//calcArea() method is used to calculate the area of the circle
@Override
public String toString() {
DecimalFormat df=new DecimalFormat("#.##");
return " Triangle# Base=" + base + " Height=" + height + "
Area="+df.format(calcArea());
}
}
___________________________________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//Declaring variables
int choice;
char ch;
//Scanner Object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//This loop will continue to execute until user enters other than 'y' or 'Y'
do
{
//Displaying the menu
System.out.println(" ::Program Which Calculates the Area of the following Shapes::");
System.out.println("::Menu::");
System.out.println("1.Rectangle");
System.out.println("2.Circle");
System.out.println("3.Triangle");
//Getting the choice entered by the user
System.out.print("Enter Choice :");
choice=sc.nextInt();
//Based on the users choice corresponding case will be executed.
switch(choice)
{
case 1:
{
//Getting the length of the Rectangle
System.out.print("Enter the Length :");
double length=sc.nextDouble();
//Getting the width of the Rectangle
System.out.print(" Enter the Width :");
double width=sc.nextDouble();
//Creating the Rectangle Object by passing the length and width as parameters
Rectangle rect=new Rectangle(length, width);
//Displaying the contents of the Rectangle Object
System.out.println(rect.toString());
break;
}
case 2:
{
//Getting the Radius of the Circle
System.out.print("Enter the Radius:");
double radius=sc.nextDouble();
//Creating the Circle Object by passing the radius as parameter
Circle c=new Circle(radius);
//Displaying the contents of the Circle Object
System.out.println(c.toString());
break;
}
case 3:
{
//getting the base of the triangle
System.out.print("Enter the Base:");
double base=sc.nextDouble();
//getting the Height of the triangle
System.out.print(" Enter the Height:");
double height=sc.nextDouble();
//Creating the triangle Object by passing the area and height as parameters
Triangle t=new Triangle(base,height);
System.out.println(t.toString());
break;
}
default :
{
//If the user entered choice other than 1 or 2 or 3 then this error message will be displayed
System.out.println("Invalid Choice,Enter Valid choice");
break;
}
}
//Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Do you want to continue(Y/N) ::");
ch = sc.next(".").charAt(0);
}while(ch=='y'|| ch=='Y');
}
}
______________________________________________
Output:
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :1
Enter the Length :4
Enter the Width :5
Rectangle#
length=4.0
Width=5.0
Area=20
Do you want to continue(Y/N) ::y
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :2
Enter the Radius:5.5
Circle#
Radius=5.5
Area=94.98
Do you want to continue(Y/N) ::y
::Program Which Calculates the Area of the following Shapes::
::Menu::
1.Rectangle
2.Circle
3.Triangle
Enter Choice :3
Enter the Base:6
Enter the Height:7
Triangle#
Base=6.0
Height=7.0
Area=21
Do you want to continue(Y/N) ::n
________________________________________________Thank You

More Related Content

Similar to Java program calculates shapes' areas

assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxssuser562afc1
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdfjeeteshmalani1
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10HUST
 
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
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxfaithxdunce63732
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaSyedShahroseSohail
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfarishmarketing21
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdfatozshoppe
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 

Similar to Java program calculates shapes' areas (13)

Ch3
Ch3Ch3
Ch3
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling Java
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 

More from ANJALIENTERPRISES1

H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdf
H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdfH2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdf
H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdfANJALIENTERPRISES1
 
Computer graphics are pictures and movies produced use computers fre.pdf
Computer graphics are pictures and movies produced use computers fre.pdfComputer graphics are pictures and movies produced use computers fre.pdf
Computer graphics are pictures and movies produced use computers fre.pdfANJALIENTERPRISES1
 
C is correct. Only the host that the unicast message is addressed to.pdf
C is correct. Only the host that the unicast message is addressed to.pdfC is correct. Only the host that the unicast message is addressed to.pdf
C is correct. Only the host that the unicast message is addressed to.pdfANJALIENTERPRISES1
 
According to the seriousness level, the following organs areThymu.pdf
According to the seriousness level, the following organs areThymu.pdfAccording to the seriousness level, the following organs areThymu.pdf
According to the seriousness level, the following organs areThymu.pdfANJALIENTERPRISES1
 
Among 40 subjects randomly choose 20 subjects and assign themSol.pdf
Among 40 subjects randomly choose 20 subjects and assign themSol.pdfAmong 40 subjects randomly choose 20 subjects and assign themSol.pdf
Among 40 subjects randomly choose 20 subjects and assign themSol.pdfANJALIENTERPRISES1
 
AdvantagesThe main objective of business combination is to elimina.pdf
AdvantagesThe main objective of business combination is to elimina.pdfAdvantagesThe main objective of business combination is to elimina.pdf
AdvantagesThe main objective of business combination is to elimina.pdfANJALIENTERPRISES1
 
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdf
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdfa. Germ cell speciication in Drosophila is primarily a maternlly con.pdf
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdfANJALIENTERPRISES1
 
A is correct. The packets to be filtered would be heading into the r.pdf
A is correct. The packets to be filtered would be heading into the r.pdfA is correct. The packets to be filtered would be heading into the r.pdf
A is correct. The packets to be filtered would be heading into the r.pdfANJALIENTERPRISES1
 
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdfANJALIENTERPRISES1
 
17-The Y-Chromosome DNA testing helps in the examination of the male.pdf
17-The Y-Chromosome DNA testing helps in the examination of the male.pdf17-The Y-Chromosome DNA testing helps in the examination of the male.pdf
17-The Y-Chromosome DNA testing helps in the examination of the male.pdfANJALIENTERPRISES1
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdfANJALIENTERPRISES1
 
The pH and pOH of a solution are defined as pH .pdf
                     The pH and pOH of a solution are defined as  pH .pdf                     The pH and pOH of a solution are defined as  pH .pdf
The pH and pOH of a solution are defined as pH .pdfANJALIENTERPRISES1
 
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdfANJALIENTERPRISES1
 
7 steps are required as 9 is the 7th element and the search is line.pdf
 7 steps are required as 9 is the 7th element and the search is line.pdf 7 steps are required as 9 is the 7th element and the search is line.pdf
7 steps are required as 9 is the 7th element and the search is line.pdfANJALIENTERPRISES1
 
(D) the number of moles of hydroxide ion added and the number of mol.pdf
  (D) the number of moles of hydroxide ion added and the number of mol.pdf  (D) the number of moles of hydroxide ion added and the number of mol.pdf
(D) the number of moles of hydroxide ion added and the number of mol.pdfANJALIENTERPRISES1
 
Look for changes in oxidation numbers. These occ.pdf
                     Look for changes in oxidation numbers.  These occ.pdf                     Look for changes in oxidation numbers.  These occ.pdf
Look for changes in oxidation numbers. These occ.pdfANJALIENTERPRISES1
 
Use Daltons Law of partial pressures. P(Total).pdf
                     Use Daltons Law of partial pressures.  P(Total).pdf                     Use Daltons Law of partial pressures.  P(Total).pdf
Use Daltons Law of partial pressures. P(Total).pdfANJALIENTERPRISES1
 
The Br was originally neutral, but picks up an ex.pdf
                     The Br was originally neutral, but picks up an ex.pdf                     The Br was originally neutral, but picks up an ex.pdf
The Br was originally neutral, but picks up an ex.pdfANJALIENTERPRISES1
 

More from ANJALIENTERPRISES1 (20)

H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdf
H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdfH2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdf
H2SO4 may act as 1) an acidexample 2NaOH + H2SO4 - Na2SO4 +.pdf
 
Computer graphics are pictures and movies produced use computers fre.pdf
Computer graphics are pictures and movies produced use computers fre.pdfComputer graphics are pictures and movies produced use computers fre.pdf
Computer graphics are pictures and movies produced use computers fre.pdf
 
C is correct. Only the host that the unicast message is addressed to.pdf
C is correct. Only the host that the unicast message is addressed to.pdfC is correct. Only the host that the unicast message is addressed to.pdf
C is correct. Only the host that the unicast message is addressed to.pdf
 
According to the seriousness level, the following organs areThymu.pdf
According to the seriousness level, the following organs areThymu.pdfAccording to the seriousness level, the following organs areThymu.pdf
According to the seriousness level, the following organs areThymu.pdf
 
Among 40 subjects randomly choose 20 subjects and assign themSol.pdf
Among 40 subjects randomly choose 20 subjects and assign themSol.pdfAmong 40 subjects randomly choose 20 subjects and assign themSol.pdf
Among 40 subjects randomly choose 20 subjects and assign themSol.pdf
 
AdvantagesThe main objective of business combination is to elimina.pdf
AdvantagesThe main objective of business combination is to elimina.pdfAdvantagesThe main objective of business combination is to elimina.pdf
AdvantagesThe main objective of business combination is to elimina.pdf
 
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdf
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdfa. Germ cell speciication in Drosophila is primarily a maternlly con.pdf
a. Germ cell speciication in Drosophila is primarily a maternlly con.pdf
 
A is correct. The packets to be filtered would be heading into the r.pdf
A is correct. The packets to be filtered would be heading into the r.pdfA is correct. The packets to be filtered would be heading into the r.pdf
A is correct. The packets to be filtered would be heading into the r.pdf
 
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf
1). A) ipsilateralBelow the point of spinal cord, the nerve paths .pdf
 
-FSolution-F.pdf
-FSolution-F.pdf-FSolution-F.pdf
-FSolution-F.pdf
 
17-The Y-Chromosome DNA testing helps in the examination of the male.pdf
17-The Y-Chromosome DNA testing helps in the examination of the male.pdf17-The Y-Chromosome DNA testing helps in the examination of the male.pdf
17-The Y-Chromosome DNA testing helps in the examination of the male.pdf
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
 
The pH and pOH of a solution are defined as pH .pdf
                     The pH and pOH of a solution are defined as  pH .pdf                     The pH and pOH of a solution are defined as  pH .pdf
The pH and pOH of a solution are defined as pH .pdf
 
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf  goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
goal_state = [1, 8, 7, 2, 0, 6, 3, 4, 5] #goal_state = [1, 0, 7, 2, .pdf
 
7 steps are required as 9 is the 7th element and the search is line.pdf
 7 steps are required as 9 is the 7th element and the search is line.pdf 7 steps are required as 9 is the 7th element and the search is line.pdf
7 steps are required as 9 is the 7th element and the search is line.pdf
 
(D) the number of moles of hydroxide ion added and the number of mol.pdf
  (D) the number of moles of hydroxide ion added and the number of mol.pdf  (D) the number of moles of hydroxide ion added and the number of mol.pdf
(D) the number of moles of hydroxide ion added and the number of mol.pdf
 
Look for changes in oxidation numbers. These occ.pdf
                     Look for changes in oxidation numbers.  These occ.pdf                     Look for changes in oxidation numbers.  These occ.pdf
Look for changes in oxidation numbers. These occ.pdf
 
D) Insulin .pdf
                     D) Insulin                                       .pdf                     D) Insulin                                       .pdf
D) Insulin .pdf
 
Use Daltons Law of partial pressures. P(Total).pdf
                     Use Daltons Law of partial pressures.  P(Total).pdf                     Use Daltons Law of partial pressures.  P(Total).pdf
Use Daltons Law of partial pressures. P(Total).pdf
 
The Br was originally neutral, but picks up an ex.pdf
                     The Br was originally neutral, but picks up an ex.pdf                     The Br was originally neutral, but picks up an ex.pdf
The Br was originally neutral, but picks up an ex.pdf
 

Recently uploaded

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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 

Recently uploaded (20)

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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 

Java program calculates shapes' areas

  • 1. Circle.java import java.text.DecimalFormat; public class Circle { //declaring variable private double radius; //Parameterized constructor public Circle(double radius) { this.radius = radius; } //Setters and getters public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } //calcArea() method is used to calculate the area of the circle public double calcArea() { double area=3.14*radius*radius; return area; } //toString() method is used to display the contents of the Object inside it. @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); return " Circle# Radius=" + radius + " Area=" +df.format(calcArea()); } } ___________________________________________________ Rectangle.java
  • 2. import java.text.DecimalFormat; public class Rectangle { //declaring variable private double length; private double width; //Parameterized constructor public Rectangle(double length, double width) { this.length = length; this.width = width; } //Setters and getters public double getlength() { return length; } public void setlength(double length) { this.length = length; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } //calcArea() method is used to calculate the area of the Rectangle public double calcArea() { double area=width* length; return area; } //calcArea() method is used to calculate the area of the circle @Override public String toString() {
  • 3. DecimalFormat df=new DecimalFormat("#.##"); return " Rectangle# length=" + length + " Width=" + width + " Area="+df.format(calcArea()); } } ____________________________________________ Triangle.java import java.text.DecimalFormat; public class Triangle{ //declaring variable private double base; private double height; //Parameterized constructor public Triangle(double base,double height) { this.base=base; this.height=height; } //Setters and getters public double getBase() { return base; } public void setBase(double base) { this.base = base; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } //calcArea() method is used to calculate the area of the Triangle
  • 4. public double calcArea() { double area=0.5*base*height; return area; } //calcArea() method is used to calculate the area of the circle @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); return " Triangle# Base=" + base + " Height=" + height + " Area="+df.format(calcArea()); } } ___________________________________________ Test.java import java.util.Scanner; public class Test { public static void main(String[] args) { //Declaring variables int choice; char ch; //Scanner Object is used to get the inputs entered by the user Scanner sc=new Scanner(System.in); //This loop will continue to execute until user enters other than 'y' or 'Y' do { //Displaying the menu System.out.println(" ::Program Which Calculates the Area of the following Shapes::"); System.out.println("::Menu::"); System.out.println("1.Rectangle"); System.out.println("2.Circle"); System.out.println("3.Triangle"); //Getting the choice entered by the user System.out.print("Enter Choice :");
  • 5. choice=sc.nextInt(); //Based on the users choice corresponding case will be executed. switch(choice) { case 1: { //Getting the length of the Rectangle System.out.print("Enter the Length :"); double length=sc.nextDouble(); //Getting the width of the Rectangle System.out.print(" Enter the Width :"); double width=sc.nextDouble(); //Creating the Rectangle Object by passing the length and width as parameters Rectangle rect=new Rectangle(length, width); //Displaying the contents of the Rectangle Object System.out.println(rect.toString()); break; } case 2: { //Getting the Radius of the Circle System.out.print("Enter the Radius:"); double radius=sc.nextDouble(); //Creating the Circle Object by passing the radius as parameter Circle c=new Circle(radius); //Displaying the contents of the Circle Object System.out.println(c.toString()); break; } case 3:
  • 6. { //getting the base of the triangle System.out.print("Enter the Base:"); double base=sc.nextDouble(); //getting the Height of the triangle System.out.print(" Enter the Height:"); double height=sc.nextDouble(); //Creating the triangle Object by passing the area and height as parameters Triangle t=new Triangle(base,height); System.out.println(t.toString()); break; } default : { //If the user entered choice other than 1 or 2 or 3 then this error message will be displayed System.out.println("Invalid Choice,Enter Valid choice"); break; } } //Getting the character from the user 'Y' or 'y' or 'N' or 'n' System.out.print("Do you want to continue(Y/N) ::"); ch = sc.next(".").charAt(0); }while(ch=='y'|| ch=='Y'); } } ______________________________________________ Output: ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :1
  • 7. Enter the Length :4 Enter the Width :5 Rectangle# length=4.0 Width=5.0 Area=20 Do you want to continue(Y/N) ::y ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :2 Enter the Radius:5.5 Circle# Radius=5.5 Area=94.98 Do you want to continue(Y/N) ::y ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :3 Enter the Base:6 Enter the Height:7 Triangle# Base=6.0 Height=7.0 Area=21 Do you want to continue(Y/N) ::n ________________________________________________Thank You Solution Circle.java
  • 8. import java.text.DecimalFormat; public class Circle { //declaring variable private double radius; //Parameterized constructor public Circle(double radius) { this.radius = radius; } //Setters and getters public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } //calcArea() method is used to calculate the area of the circle public double calcArea() { double area=3.14*radius*radius; return area; } //toString() method is used to display the contents of the Object inside it. @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); return " Circle# Radius=" + radius + " Area=" +df.format(calcArea()); } } ___________________________________________________ Rectangle.java import java.text.DecimalFormat; public class Rectangle {
  • 9. //declaring variable private double length; private double width; //Parameterized constructor public Rectangle(double length, double width) { this.length = length; this.width = width; } //Setters and getters public double getlength() { return length; } public void setlength(double length) { this.length = length; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } //calcArea() method is used to calculate the area of the Rectangle public double calcArea() { double area=width* length; return area; } //calcArea() method is used to calculate the area of the circle @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); return " Rectangle# length=" + length + " Width=" + width + "
  • 10. Area="+df.format(calcArea()); } } ____________________________________________ Triangle.java import java.text.DecimalFormat; public class Triangle{ //declaring variable private double base; private double height; //Parameterized constructor public Triangle(double base,double height) { this.base=base; this.height=height; } //Setters and getters public double getBase() { return base; } public void setBase(double base) { this.base = base; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } //calcArea() method is used to calculate the area of the Triangle public double calcArea() { double area=0.5*base*height;
  • 11. return area; } //calcArea() method is used to calculate the area of the circle @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); return " Triangle# Base=" + base + " Height=" + height + " Area="+df.format(calcArea()); } } ___________________________________________ Test.java import java.util.Scanner; public class Test { public static void main(String[] args) { //Declaring variables int choice; char ch; //Scanner Object is used to get the inputs entered by the user Scanner sc=new Scanner(System.in); //This loop will continue to execute until user enters other than 'y' or 'Y' do { //Displaying the menu System.out.println(" ::Program Which Calculates the Area of the following Shapes::"); System.out.println("::Menu::"); System.out.println("1.Rectangle"); System.out.println("2.Circle"); System.out.println("3.Triangle"); //Getting the choice entered by the user System.out.print("Enter Choice :"); choice=sc.nextInt();
  • 12. //Based on the users choice corresponding case will be executed. switch(choice) { case 1: { //Getting the length of the Rectangle System.out.print("Enter the Length :"); double length=sc.nextDouble(); //Getting the width of the Rectangle System.out.print(" Enter the Width :"); double width=sc.nextDouble(); //Creating the Rectangle Object by passing the length and width as parameters Rectangle rect=new Rectangle(length, width); //Displaying the contents of the Rectangle Object System.out.println(rect.toString()); break; } case 2: { //Getting the Radius of the Circle System.out.print("Enter the Radius:"); double radius=sc.nextDouble(); //Creating the Circle Object by passing the radius as parameter Circle c=new Circle(radius); //Displaying the contents of the Circle Object System.out.println(c.toString()); break; } case 3: { //getting the base of the triangle
  • 13. System.out.print("Enter the Base:"); double base=sc.nextDouble(); //getting the Height of the triangle System.out.print(" Enter the Height:"); double height=sc.nextDouble(); //Creating the triangle Object by passing the area and height as parameters Triangle t=new Triangle(base,height); System.out.println(t.toString()); break; } default : { //If the user entered choice other than 1 or 2 or 3 then this error message will be displayed System.out.println("Invalid Choice,Enter Valid choice"); break; } } //Getting the character from the user 'Y' or 'y' or 'N' or 'n' System.out.print("Do you want to continue(Y/N) ::"); ch = sc.next(".").charAt(0); }while(ch=='y'|| ch=='Y'); } } ______________________________________________ Output: ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :1 Enter the Length :4 Enter the Width :5
  • 14. Rectangle# length=4.0 Width=5.0 Area=20 Do you want to continue(Y/N) ::y ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :2 Enter the Radius:5.5 Circle# Radius=5.5 Area=94.98 Do you want to continue(Y/N) ::y ::Program Which Calculates the Area of the following Shapes:: ::Menu:: 1.Rectangle 2.Circle 3.Triangle Enter Choice :3 Enter the Base:6 Enter the Height:7 Triangle# Base=6.0 Height=7.0 Area=21 Do you want to continue(Y/N) ::n ________________________________________________Thank You