x-y plane and you designed the class to capture the properties of a point in Part a), you must derive the class “circleType” from the class “pointType”. You should be able to perform the usual operations on the circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center. Also, write a program to test various operations on a circle.
Note: Since the coding language is not specified I am using Java.
import java.util.Scanner;
import java.lang.Math;
class pointType{
private int x;
private int y;
public pointType(int x,int y){
this.x=x;
this.y=y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
class circleType extends pointType{
private double radius;
public circleType(int x,int y,double radius){
super(x,y);
this.radius=radius;
}
public double getRadius(){
return radius;
}
public double area(double radius){
return 3.14*radius*radius;
}
public double circumference(double radius){
return 2*3.14*radius;
}
}
class cylinderType extends circleType{
private double baseRadius;
private double height;
public cylinderType(int x,int y,double baseRadius,double height){
super(x,y,baseRadius);
this.height=height;
}
public double getHeight(){
return height;
}
public double volume(double baseRadius,double height){
return 3.14*baseRadius*baseRadius*height;
}
}
public class PrintMessage{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
//a.) POINT TYPE
System.out.println("a.)POINT TYPE");
System.out.print("Enter the X & Y coordinates of a point, by space separation(ex: 3 5): ");
String str=sc.nextLine();
String s[]=str.split(" ");
int x=Integer.parseInt(s[0]);
int y=Integer.parseInt(s[1]);
pointType obj=new pointType(x,y);
System.out.println("Point: "+obj.getX()+" "+obj.getY());
double d=Math.sqrt(x*x+y*y);
System.out.println("Distance of the point from origin is: "+String.format("%.2f",d));
//b.) CIRCLE TYPE
System.out.println("\n------------------------------------");
System.out.println("b.)CIRCLE TYPE");
System.out.print("Enter the X and Y coordinates of the center of circle by space separation(ex: 4,5): ");
String str1=sc.nextLine();
String s1[]=str1.split(" ");
x=Integer.parseInt(s1[0]);
y=Integer.parseInt(s1[1]);
System.out.print("Enter the radius of the circle:");
double r=sc.nextDouble();
circleType circle=new circleType(x,y,r);
System.out.println("Center of the circle: "+x+" "+y);
System.out.println("Radius of the circle: "+circle.getRadius());
System.out.println("Area of the circle: "+String.format("%.2f",circle.area(r)));
System.out.println("Circumference of the circle: "+String.format("%.2f",circle.circumference(r)));
//c.)CYLINDER TYPE
System.out.println("\n------------------------------------");
System.out.println("b.)CYLINDER TYPE");
System.out.print("Enter the X and Y coordinates of the center of cylinder by space separation(ex: 4,5): ");
sc.next();
String str2=sc.nextLine();
String s2[]=str.split(" ");
x=Integer.parseInt(s2[0]);
y=Integer.parseInt(s2[1]);
System.out.print("Enter the base radius of the cylinder:");
double br=sc.nextDouble();
System.out.print("Enter the height of the cylinder:");
double ch=sc.nextDouble();
cylinderType cylinder=new cylinderType(x,y,br,ch);
System.out.println("Center of the cylinder: "+x+" "+y);
System.out.println("Base Radius of the cylinder: "+cylinder.getRadius());
System.out.println("Volume of the cylinder: "+String.format("%.2f",cylinder.volume(br,ch)));
//d.) CIRCLE TYPE IS SAME AS THE a.)
}
}
Thank you! If you have any queries post it below in the comment section i will try my best to resolve your queries and if required i will add it to my answer.Give a upvote if you like it.
Get Answers For Free
Most questions answered within 1 hours.