BlueJ Lagi?! Tugas Kedua Kelas PBO!

Tugas kedua kelas Pemrograman Berbasis Objek atau PBO kali ini, tetap menggunakan BlueJ, tetapi kita membuat program untuk menghitung luas dan keliling bangun datar.

Source Code

Main

 public class Main  
 {  
   public static void Main(){  
     Circle aCircle;  
     aCircle= new Circle();  
     aCircle.r=11;  
     double area = aCircle.area();  
     double circumf = aCircle.circumference();  
     System.out.println("Jari-jari="+aCircle.r+" Luas="+area);  
     System.out.println("Jari-jari="+aCircle.r+" Keliling="+circumf+"\n");  
     Triangle aTriangle;  
     aTriangle= new Triangle();  
     aTriangle.a=8;  
     aTriangle.t=4;  
     double areaT = aTriangle.area();  
     double circumfT = aTriangle.circumference();  
     System.out.println("Alas="+aTriangle.a+" Tinggi="+aTriangle.t+" Luas="+areaT);  
     System.out.println("Alas="+aTriangle.a+" Tinggi="+aTriangle.t+" Keliling="+circumfT+"\n");      
     Square aSquare;  
     aSquare= new Square();  
     aSquare.s=3;  
     double areaS = aSquare.area();  
     double circumfS = aSquare.circumference();  
     System.out.println("Sisi="+aSquare.s+" Luas="+areaS);  
     System.out.println("Sisi="+aSquare.s+" Keliling="+circumfS+"\n");  
     Diamond aDiamond;  
     aDiamond= new Diamond();  
     aDiamond.s=5;  
     aDiamond.d1=3;  
     aDiamond.d2=4;  
     double areaD = aDiamond.area();  
     double circumfD = aDiamond.circumference();  
     System.out.println("Sisi="+aDiamond.s+" Diagonal 1="+aDiamond.d1+" Diagonal 2="+aDiamond.d2+" Luas="+areaD);  
     System.out.println("Sisi="+aDiamond.s+" Diagonal 1="+aDiamond.d1+" Diagonal 2="+aDiamond.d2+" Keliling="+circumfD+"\n");  
     Parallelogram aParallelogram;  
     aParallelogram= new Parallelogram();  
     aParallelogram.a=10;  
     aParallelogram.b=5;  
     aParallelogram.t=8;  
     double areaP = aParallelogram.area();  
     double circumfP = aParallelogram.circumference();  
     System.out.println("Sisi Datar="+aParallelogram.a+" Sisi Miring="+aParallelogram.b+" Tinggi="+aParallelogram.t+" Luas="+areaP);  
     System.out.println("Sisi Datar="+aParallelogram.a+" Sisi Miring="+aParallelogram.b+" Tinggi="+aParallelogram.t+" Keliling="+circumfD+"\n");  
   }  
 }  

Lingkaran

 public class Circle  
 {  
   public double r;  
   public double circumference(){  
     return 2*3.14*r;  
   }  
   public double area(){  
     return 3.14*r*r;  
   }  
 }  

Segitiga

 public class Triangle  
 {  
   public double a, t;  
   public double circumference(){  
     return a*3;  
   }  
   public double area(){  
     return (a*t)/2;  
   }  
 }  

Bujursangkar

 public class Square  
 {  
   public double s;  
   public double circumference(){  
     return 4*s;  
   }  
   public double area(){  
     return s*s;  
   }  
 }  

Belah Ketupat

 public class Diamond  
 {  
   public double d1,d2,s;  
   public double circumference(){  
     return 4*s;  
   }  
   public double area(){  
     return (d1*d2)/2;  
   }  
 }  

Jajar Genjang

 public class Parallelogram  
 {  
   public double a,b,t;  
   public double circumference(){  
     return 2*(a+b);  
   }  
   public double area(){  
     return a*t;  
   }  
 }  

Tampilan

 

Komentar

Postingan populer dari blog ini

Halaman Berita? HTML & CSS!

Menggunakan CodeIgniter!!

Sistem Informasi Cinema 21 - APSI