Lab Assignment 1. WAP To Find The Volume of Any Cylinder Using Method 2. Wap To Find The Area of A Circle

You might also like

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

LAB ASSIGNMENT

1. WAP to find the volume of any cylinder using method


2. Wap to find the area of a circle
SOURCE CODE
import java.util.Scanner;
import java.lang.*;

class Cylinder{
Scanner input = new Scanner(System.in);
private double radius;
private double height;
private double PI = 3.14;
double volume;
public void getData(){
System.out.print("Enter radius for the cylinder: ");
radius = input.nextDouble();
System.out.print("\nEnter height for the cylinder: ");
height = input.nextDouble();
}

public void calculateVolume(){


volume = 2*PI*Math.pow(radius,2)*height;
}

public class main {

public static void main(String[] args) {

Cylinder object = new Cylinder();

object.getData();
object.calculateVolume();

System.out.println("The volume for the given measurements of the cylinder:


"+object.volume);
}

}
OUTPUT
SOURCE CODE

class Circle{
private double radius;
private double PI = 3.14;
private double area;

public void getRadius(double radius){


this.radius = radius;
}

private void calculateArea(){


area = PI*Math.pow(radius,2);
}

public void displayArea(){


calculateArea();
System.out.print("Area for the circle of radius "+radius+ " is: "+ area);
}
}

public class main {


public static void main(String[] args) {
Circle object = new Circle();

object.getRadius(5);
object.displayArea();

}
OUTPUT

You might also like