Senin, 10 September 2018

PBO B-TUGAS 2

Nama; Chrisnady Anggaiswara
NRP: 05111640000153
Kelas: PBO-B

Ini adalah tugas 2 PBO saya dengan mencari luas dan keliling dari bidang 3D(Kubus,Balok,Tabung,Bola) dengan membuat source code menggunakan bahasa Java. Dikelas telah belajar lingkaran dan mendapatkan tugas untuk bangun datar yang lain.

Berikut merupakan formatted source code saya:

  • Main

 /**  
  * Write a description of class myMain here.  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (1)  
  */  
 public class myMain  
 {  
   public static void main(String args[])   
   {   
     //kubus  
     Kubus aKubus;   
    aKubus = new Kubus();   
    aKubus.x = 5.0;   
    double LP = aKubus.LuasPermukaan();   
    double V = aKubus.Volume();   
    System.out.println("KUBUS");   
    System.out.println("Sisi = "+aKubus.x);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //balok  
    Balok aBalok;   
    aBalok = new Balok();   
    aBalok.x = 15.0;   
    aBalok.y = 5.0;   
    aBalok.z = 10.0;   
    LP = aBalok.LuasPermukaan();   
    V = aBalok.Volume();   
    System.out.println("BALOK");   
    System.out.println("Panjang = "+aBalok.x);   
    System.out.println("Lebar = "+aBalok.y);   
    System.out.println("Tinggi = "+aBalok.z);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //tabung  
    Tabung aTabung;   
    aTabung = new Tabung();   
    aTabung.r = 10.0;   
    aTabung.x = 20.0;   
    LP = aTabung.LuasPermukaan();   
    V = aTabung.Volume();   
    System.out.println("TABUNG");   
    System.out.println("Radius = "+aTabung.r);   
    System.out.println("Tinggi = "+aTabung.x);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //bola  
    Bola aBola;   
    aBola = new Bola();   
    aBola.r = 10.0;   
    LP = aBola.LuasPermukaan();   
    V = aBola.Volume();   
    System.out.println("BOLA");   
    System.out.println("Radius = "+aBola.r);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
   }   
 }  

  • Kubus

 /**  

  * Write a description of class Kubus here.  

  *  

  * @author (Chrisnady Anggaiswara)  

  * @version (1)  

  */  

 public class Kubus   

  {   

   public double x;   

   public double LuasPermukaan()   

   {   

    return 6*x*x;   

   }   

   public double Volume()   

   {   

    return x*x*x;   

   }   

  }   


  • Balok

 /**  

  * Write a description of class Balok here.  

  *  

  * @author (Chrisnady A)  

  * @version (1)  

  */  

 public class Balok   

  {   

   public double x,y,z;    

   public double LuasPermukaan()   

   {   

    return 2*(x*y)+2*(y*z)+2*(x*z);   

   }   

   public double Volume()   

   {   

    return x*y*z;   

   }   

  }   
  • Tabung
 /**  

  * Write a description of class Tabung here.  

  *  

  * @author (Chrisnady A)  

  * @version (1)  

  */  

 public class Tabung   

  {   

   public double r;   

   public double x;   

   public double LuasPermukaan()   

   {   

    return 2*3.14*r*(r+x);   

   }   

   public double Volume()   

   {   

    return 3.14*r*r*x;   

   }   

  }  


  • Bola

 /**  

  * Write a description of class Bola here.  

  *  

  * @author (Chrisnady Anggaiswara)  

  * @version (1)  

  */  

  public class Bola   

  {   

   public double r;   

   public double LuasPermukaan()   

   {   

    return 4*3.14*r*r;   

   }   

   public double Volume()   

   {   

    // put your code here   

    return (4*3.14*r*r*r)/3;   

   }   

  }   




Gambar Denah Class dan Hasil :






















Tidak ada komentar:

Posting Komentar