Hardcopy Mod10

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Object Oriented Programming

CIRCLE

PARENT CLASS

public class Circle {


public double radius;

public void setRad (double Rad){


radius = Rad;
}
public double getRad(){
return radius;
}
public double getArea (double Rad){
return (Math.PI * radius * radius);
}
}

CHILD CLASS

public class Cylinder extends Circle{


private double height;

public void setHeight(double h){


height = h;
}
public double getHeight (){
return height;
}

public double getARea (){


return (2*Math.PI*radius*height+2*Math.PI*radius*radius);
}
public double getVolume (){
return (Math.PI*radius*radius*height);
}
}

TEST CLASS
import java.util.Scanner;
public class TestClass {
public static void main (String [] args){
Scanner input = new Scanner (System.in);
Circle myCircle = new Circle ();
Cylinder myCylinder = new Cylinder ();

System.out.println("Enter the radius: ");


double radius = input.nextDouble();

System.out.println("Enter the height: ");


double height = input.nextDouble();

myCircle.setRad(radius);
myCylinder.setRad (radius);
myCylinder.setHeight(height);

System.out.println("The radius is: " + myCircle.getRad() +


"\nThe height is: " + myCylinder.getHeight());
System.out.println("The area of the circle is: " + myCircle.getArea(radius)+
"\nThe area of the cylinder is: "+ myCylinder.getARea() +
"\nThe volume of the cylinder is: " + myCylinder.getVolume());

}
}

You might also like