Senin, 10 September 2018

TUGAS 2 PBO A - CLASS AND OBJECT

Nama : Timothyus Tanner
NRP   : 05111740000103

Tugas 2 PBO A tentang membuat rumus bangun 2D dengan Class and Object

Source Code
1. Main

 public class Main  
 {  
   public static void kotak()  
   {  
     Persegi kotaks;  
     kotaks = new Persegi();  
     kotaks.s = 5;  
     int luas = kotaks.luas();  
     int keliling = kotaks.kel();  
     System.out.println("Persegi");  
     System.out.println("Sisi\t\t= " + kotaks.s);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + keliling);  
   }  
   public static void segitiga()  
   {  
     Segitiga segitigas;  
     segitigas = new Segitiga();  
     segitigas.a = 10;  
     segitigas.t = 4;  
     double l = segitigas.luas();  
     double k = segitigas.keliling();  
     System.out.println("Segitiga Sama Sisi");  
     System.out.println("Alas\t\t= " + segitigas.a);  
     System.out.println("Tinggi\t\t= " + segitigas.t);  
     System.out.println("Luas\t\t= " + l);  
     System.out.println("Keliling\t= " + k);  
   }  
   public static void pp()  
   {  
     Persegi_Panjang PP;  
     PP = new Persegi_Panjang();  
     PP.p = 5;  
     PP.l = 2;  
     int luas = PP.luas();  
     int keliling = PP.kel();  
     System.out.println("Persegi Panjang");  
     System.out.println("Panjang\t\t= " + PP.p);  
     System.out.println("Lebar\t\t= " + PP.l);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + keliling);  
   }  
   public static void jg()  
   {  
     Jajar_Genjang jgs;  
     jgs = new Jajar_Genjang();  
     jgs.a = 10;  
     jgs.t = 2;  
     jgs.b = 4;  
     double luas = jgs.luas();  
     double kel = jgs.keliling();  
     System.out.println("Jajar Genjang");  
     System.out.println("Alas\t\t= " + jgs.a);  
     System.out.println("Tinggi\t\t= " + jgs.t);  
     System.out.println("Sisi Miring\t= " + jgs.b);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + kel);  
   }  
   public static void bk()  
   {  
     Belah_Ketupat bks;  
     bks = new Belah_Ketupat();  
     bks.d1 = 6;  
     bks.d2 = 8;  
     bks.s = 5;  
     double luas = bks.luas();  
     double kel = bks.kel();  
     System.out.println("Belah Ketupat");  
     System.out.println("Diagonal 1\t= " +bks.d1);  
     System.out.println("Diagonal 2\t= " +bks.d2);  
     System.out.println("Sisi\t\t= " +bks.s);  
     System.out.println("Luas\t\t= " +luas);  
     System.out.println("Keliling\t= " +kel);  
   }  
   public static void lingk()  
   {  
     Lingkaran bunder;  
     bunder = new Lingkaran();  
     bunder.r = 10;  
     double luas = bunder.luas();  
     double kel = bunder.kel();  
     System.out.println("Lingkaran");  
     System.out.println("Jari-jari\t= " +bunder.r);  
     System.out.println("Luas\t\t= " +luas);  
     System.out.println("Keliling\t= " +kel);  
   }  
 }  

2. Segitiga

 public class Segitiga  
 {  
   public double a, t;  
   public double luas()  
   {  
     return a * t / 2.0;  
   }  
   public double keliling()  
   {  
     return 3 * a;  
   }  
 }  

3. Persegi

 public class Persegi  
 {  
   public int s;  
   public int luas()  
   {  
     return s * s;  
   }  
   public int kel()  
   {  
     return 4 * s;  
   }  
 }  

4. Jajar Genjang

 public class Jajar_Genjang  
 {  
   public double a,t,b;  
   public double luas()  
   {  
     return a * t;  
   }  
   public double keliling()  
   {  
     return 2 * (a + b);  
   }  
 }  

5. Belah Ketupat

 public class Belah_Ketupat  
 {  
   public double d1, d2, s;  
   public double luas()  
   {  
     return (d1 * d2) / 2.0;  
   }  
   public double kel()  
   {  
     return 4 * s;  
   }  
 }  

6. Persegi Panjang

 public class Persegi_Panjang  
 {  
   public int p,l;  
   public int luas()  
   {  
     return p * l;  
   }  
   public int kel()  
   {  
     return 2 * (p + l);  
   }  
 }  

7. Lingkaran

 public class Lingkaran  
 {  
   public double r;  
   public double luas()  
   {  
     return 3.14159 * r * r;  
   }  
   public double kel()  
   {  
     return 2 * 3.14159 * r;  
   }  
 }  


Output :



Tidak ada komentar:

Posting Komentar