You are on page 1of 3

Classes And Objects

Question1
public class Box
{
double h,w,d;
Box(double width,double height,double depth)
{
h=height;
w=width;
d=depth;
}
double volume()
{
double v;
v=h*w*d;
return v;
}
public static void main(String[] args)
{
Box bc = new Box(7.7,60.9,9.1);
System.out.println(bc.volume());
}
}
Output
4267.263

Question2

public class Calsi


{
public static void main(String[] args)
{
System.out.println(Calculator.powerDouble(31.2, 3));
System.out.println(Calculator.powerInt(3,4));
}
}
class Calculator
{
static double powerInt(int num1,int num2)
{
return Math.pow(num1,num2);
}
static double powerDouble(double num1,int num2)
{
return Math.pow(num1,num2);
}
}
Output
30371.327999999998
81.0

Question3
import java.util.Scanner;
public class BMICal {

public static void main(String[] args)


{
calculateBMI();
}

private static void calculateBMI()


{
System.out.print("Please enter your weight in kg: ");
Scanner s = new Scanner(System.in);
float weight = s.nextFloat();
System.out.print("Please enter your height in cm: ");
float height = s.nextFloat();
float bmi = (100*100*weight)/(height*height);

System.out.println("Your BMI is: "+bmi);


}
}
Output
Please enter your weight in kg: 55
Please enter your height in cm: 159
Your BMI is: 21.755468

You might also like