Jumat, 30 Desember 2011

program bangun ruang

import java.util.Scanner;
public class bangunR
{
public static void main(String args[])
{
Scanner masuk=new Scanner(System.in);
int pil;
balok b = new balok();
kubus s = new kubus();
System.out.println("....Menu.....");
System.out.println(".............");
System.out.println("1.Balok");
System.out.println("2.Kubus");
System.out.println(" ");
System.out.println("Volume bangun mana yang anda inginkan? ");
System.out.print("Masukkan pilihan : ");
pil=masuk.nextInt();
switch(pil)
{
case 1: b.tuing1();break;
case 2: s.tuing2();break;
}
}
}

class balok
{

public int setPanjang()
{
return 5;
}
public int setLebar()
{
return 10;
}
public int setTinggi()
{
return 10;
}

public int hitungVolume()
{
return setPanjang()*setLebar()*setTinggi();
}

public void tuing1()
{
System.out.println("Panjang = "+setPanjang());
System.out.println("Lebar = "+setLebar());
System.out.println("Tinggi = "+setTinggi());
System.out.println(" ");

System.out.println("Volume Balok = "+hitungVolume());
}
}


class kubus
{

public int setSisi()
{
return 4;
}
public float hitungVolume()
{
return setSisi()*setSisi()*setSisi();
}
public void tuing2()
{

System.out.println("Sisi Kubus = "+setSisi());
System.out.println(" ");
System.out.println("Volume Kubus = "+hitungVolume());
}
}

0 komentar:

Posting Komentar

Statistik

Translate

Blog Archive