Kubus
Balok
Tabung
Bola
Fungsi Main
Hasil screenshot
/**
* Write a description of class Kubus here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class kubus
{
public double s;
public double circumference()
{
return s*s*s;
}
public double area()
{
return 6*s*s;
}
}
Balok
/**
* Write a description of class Balok here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class balok
{
public double p,l,t;
public double circumference()
{
return p*l*t;
}
public double area()
{
return 2*(p*l)+2*(l*t)+2*(p*t);
}
}
Tabung
/**
* Write a description of class Tabung here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class tabung
{
public double s,t;
public double circumference()
{
return 3.14*s*s*t;
}
public double area()
{
return 2*3.14*s*t+2*3.14*s*s;
}
}
Bola
/**
* Write a description of class BOLA here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bola
{
public double s;
public double circumference()
{
return 1.33*3.14*s*s*s;
}
public double area()
{
return 4*3.14*s*s;
}
}
Fungsi Main
/**
* Write a description of class MyMain here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyMain
{
public static void main(/*String args[]*/)
{
kubus aKubus;
aKubus = new kubus();
aKubus.s = 45;
double area = aKubus.area();
double circumf = aKubus.circumference();
System.out.println("Kubus dengan sisi="+aKubus.s);
System.out.println("Luas="+area+"Volume="+circumf);
balok aBalok;
aBalok = new balok();
aBalok.p = 15;
aBalok.l = 5;
aBalok.t = 5;
area = aBalok.area();
circumf = aBalok.circumference();
System.out.println("Balok dengan panjang="+aBalok.p);
System.out.println("Balok dengan lebar="+aBalok.l);
System.out.println("Balok dengan tinggi="+aBalok.t);
System.out.println("Luas="+area+"Volume="+circumf);
tabung aTabung;
aTabung = new tabung();
aTabung.s = 7;
aTabung.t = 25;
area = aTabung.area();
circumf = aTabung.circumference();
System.out.println("Tabung dengan sisi="+aTabung.s);
System.out.println("Tabung dengan tinggi="+aTabung.t);
System.out.println("Luas="+area+"Volume="+circumf);
bola aBola;
aBola = new bola ();
aBola.s = 20;
area = aBola.area();
circumf = aBola.circumference();
System.out.println("Bola dedngan sisi="+aBola.s);
System.out.println("Luas="+area+"Volume="+circumf);
}
}
Hasil screenshot
Komentar
Posting Komentar