Question
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
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started