Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the code in java from the following given code using JOPtionPane. Point.java public class Point { //Declaring instance variables private int x,y; //Zero Argumented

Write the code in java from the following given code using JOPtionPane.

Point.java

public class Point { //Declaring instance variables private int x,y;

//Zero Argumented constructor public Point() { super(); }

//Parameterized constructor public Point(int x, int y) { super(); this.x = x; this.y = y; }

//Getter and Setter methods public int getX() { return x; }

public void setX(int x) { this.x = x; }

public int getY() { return y; }

public void setY(int y) { this.y = y; }

/* toString() method which displays * the contents of an object inside it */ @Override public String toString() { return "Point ("+ x + "," + y +")"; }

}

___________________

Circle.java

import java.text.DecimalFormat;

public class Circle extends Point {

//Declaring instance variables private double radius; //Zero Argumented constructor public Circle() { this.radius=0.0; } //Parameterized constructor public Circle(int x, int y,double radius) { super(x, y); setRadius(radius); } //Getter and Setter methods public double getRadius() { return radius; } public void setRadius(double radius) { if(radius>=0) this.radius = radius; else { System.out.println("Invalid.Radius Must be Positive."); radius=0.0; } } public double calArea() { return Math.PI*getRadius()*getRadius(); } /* toString() method which displays * the contents of an object inside it */ @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); System.out.println(super.toString()); return "Circle# Radius=" + radius + " Area of Circle ="+df.format(calArea()); }

}

________________________

Cylinder.java

import java.text.DecimalFormat;

public class Cylinder extends Circle { //Declaring instance variables private double height;

//Zero Argumented constructor public Cylinder() { super(); }

//Parameterized constructor public Cylinder(int a,int b,double r,double height) { super(a,b,r); this.height = height; }

//Getter and Setter methods public double getHeight() { return height; }

public void setHeight(double height) { this.height = height; }

public double calVolume() { return Math.PI*getRadius()*getRadius()*getHeight(); }

/* toString() method which displays * the contents of an object inside it */ @Override public String toString() { DecimalFormat df=new DecimalFormat("#.##"); System.out.println(super.toString()); return "Cylinder# Height=" + height + " Volume Of the Cylinder ="+df.format(calVolume()); }

}

__________________________

Application.java

import java.util.ArrayList; import java.util.Scanner;

public class Application {

public static void main(String[] args) { //Declaring variables int x,y; double radius,height; //Creating an ArrayList Object ArrayList arl=new ArrayList(); /* Scanner class object is used to * read the inputs entered by the user */ Scanner sc=new Scanner(System.in); //Getting the point coordinates entered by the user System.out.print("Enter the X coordinate of Point :"); x=sc.nextInt(); System.out.print("Enter the Y coordinate of Point :"); y=sc.nextInt(); //Getting the radius of the circle enterd by the user System.out.print("Enter radius of the Circle :"); radius=sc.nextDouble(); //Getting the height of the circle entered by the user System.out.print("Enter Height of the Cylinder :"); height=sc.nextDouble(); /* Creating a Point class object by passing * the x,y coodinates as arguments */ Point p=new Point(x, y); //Adding the Point class object to the ArrayList arl.add(p); /* Creating a Circle class object by passing * the x,y coodinates and radius as arguments */ Circle c=new Circle(x, y, radius); //Adding the Circle class object to the ArrayList arl.add(c); /* Creating a Cylinder class object by passing * the x,y coodinates, radius,height as arguments */ Cylinder cyl=new Cylinder(x, y, radius, height); //Adding the Cylinder class object to the ArrayList arl.add(cyl); //Displaying Each object Information System.out.println("_____Displaying each Object Information_____"); for(Object o:arl) { System.out.println(o.toString()); System.out.println("_________________"); }

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago