Langsung ke konten utama

Tugas 2 PBO A

Hi. On today's post, I'm going to show you my next project about Java Class implementation related to 2D solid shapes. In this project, I'm going to use 6 solid shapes, which is a circle, a square, a triangle, a diamond, a parallelogram, and a rectangle. Check it out! 

Class Structure






1. Main

   
 /**  
  * Fungsi main di sini.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 public class myMain  
 {  
   public static void main(String args[])  
   {  
     System.out.println("Lingkaran:");  
     Circle myCircle;  
     myCircle = new Circle();  
     double crcArea = myCircle.Area();  
     double crcCircum = myCircle.Circum();  
     System.out.print("Luas = " + crcArea + ", ");  
     System.out.println("Keliling = " + crcCircum + "\n");  
       
     System.out.println("Persegi:");  
     Square mySquare;  
     mySquare = new Square();  
     double sqrArea = mySquare.Area();  
     double sqrCircum = mySquare.Circum();  
     System.out.print("Luas = " + sqrArea + ", ");  
     System.out.println("Keliling = " + sqrCircum + "\n");  
       
     System.out.println("Segitiga (siku-siku):");  
     Triangle myTriangle;  
     myTriangle = new Triangle();  
     double triArea = myTriangle.Area();  
     double triCircum = myTriangle.Circum();  
     System.out.print("Luas = " + triArea + ", ");  
     System.out.println("Keliling = " + triCircum + "\n");  
       
     System.out.println("Belah Ketupat:");  
     Diamond myDiamond;  
     myDiamond = new Diamond();  
     double diaArea = myDiamond.Area();  
     double diaCircum = myDiamond.Circum();  
     System.out.print("Luas = " + diaArea + ", ");  
     System.out.println("Keliling = " + diaCircum + "\n");  
       
     System.out.println("Jajar Genjang:");  
     Parallel myParallel;  
     myParallel = new Parallel();  
     double parArea = myParallel.Area();  
     double parCircum = myParallel.Circum();  
     System.out.print("Luas = " + parArea + ", ");  
     System.out.println("Keliling = " + parCircum + "\n");  
       
     System.out.println("Persegi Panjang:");  
     Rectangle myRectangle;  
     myRectangle = new Rectangle();  
     double rectArea = myRectangle.Area();  
     double rectCircum = myRectangle.Circum();  
     System.out.print("Luas = " + rectArea + ", ");  
     System.out.println("Keliling = " + rectCircum + "\n");  
   }  
 }  


2. Circle

   
 /**  
  * Class untuk mencari luas dan keliling lingkaran.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Circle extends myMain  
 {  
   public double myRad;  
   public Circle()  
   {  
     System.out.print("Masukkan jari-jari: ");  
     Scanner rad = new Scanner (System.in);  
     myRad = rad.nextFloat();  
   }  
     
   public double Area()  
   {  
     return 3.14 * myRad * myRad;  
   }  
     
   public double Circum()  
   {  
     return 2 * 3.14 * myRad;  
   }  
 }  
   


3. Square

   
 /**  
  * Class untuk mencari luas dan keliling persegi.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Square extends myMain  
 {  
   public double mySide;  
   public Square()  
   {  
     System.out.print("Masukkan sisi: ");  
     Scanner side = new Scanner (System.in);  
     mySide = side.nextFloat();  
   }  
     
   public double Area()  
   {  
     return mySide * mySide;  
   }  
     
   public double Circum()  
   {  
     return 4 * mySide;  
   }  
 }  
   


4. Triangle

   
 /**  
  * Class untuk mencari luas dan keliling segitiga.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Triangle extends myMain  
 {  
   public double myBase, myHeight;  
   public Triangle()  
   {  
     System.out.print("Masukkan alas: ");  
     Scanner base = new Scanner (System.in);  
     myBase = base.nextFloat();  
     System.out.print("Masukkan tinggi: ");  
     Scanner height = new Scanner (System.in);  
     myHeight = height.nextFloat();  
   }  
     
   public double Area()  
   {  
     return myBase * myHeight / 2;  
   }  
     
   public double Circum()  
   {  
     return myBase + myHeight + Math.sqrt((myBase * myBase) + (myHeight * myHeight));  
   }  
 }  
   


5. Diamond

   
 /**  
  * Class untuk mencari luas dan keliling belah ketupat.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Diamond extends myMain  
 {  
   public double myDiag1, myDiag2;  
   public Diamond()  
   {  
     System.out.print("Masukkan diagonal 1: ");  
     Scanner diag1 = new Scanner (System.in);  
     myDiag1 = diag1.nextFloat();  
     System.out.print("Masukkan diagonal 2: ");  
     Scanner diag2 = new Scanner (System.in);  
     myDiag2 = diag2.nextFloat();  
   }  
     
   public double Area()  
   {  
     return myDiag1 * myDiag2 / 2;  
   }  
     
   public double Circum()  
   {  
     return 2 * Math.sqrt((myDiag1 * myDiag1) + (myDiag2 * myDiag2));  
   }  
 }  
   


6. Parallelogram

   
 /**  
  * Class untuk mencari luas dan keliling jajar genjang.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Parallel extends myMain  
 {  
   public double myBase, myHeight, mySide;  
   public Parallel()  
   {  
     System.out.print("Masukkan alas: ");  
     Scanner base = new Scanner (System.in);  
     myBase = base.nextFloat();  
     System.out.print("Masukkan tinggi: ");  
     Scanner height = new Scanner (System.in);  
     myHeight = height.nextFloat();  
     System.out.print("Masukkan sisi miring: ");  
     Scanner side = new Scanner (System.in);  
     mySide = side.nextFloat();  
   }  
     
   public double Area()  
   {  
     return myBase * myHeight;  
   }  
     
   public double Circum()  
   {  
     return 2 * (myBase + mySide);  
   }  
 }  
   


7. Rectangle

   
 /**  
  * Class untuk mencari luas dan keliling persegi panjang.  
  *  
  * @author (Elkana Hans Widersen)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Rectangle extends myMain  
 {  
   public double myLength, myWidth;  
   public Rectangle()  
   {  
     System.out.print("Masukkan panjang: ");  
     Scanner length = new Scanner (System.in);  
     myLength = length.nextFloat();  
     System.out.print("Masukkan lebar: ");  
     Scanner width = new Scanner (System.in);  
     myWidth = width.nextFloat();  
   }  
     
   public double Area()  
   {  
     return myLength * myWidth;  
   }  
     
   public double Circum()  
   {  
     return 2 * (myLength + myWidth);  
   }  
 }  
   

When it's done compiled, it will look like this:
Compile Result

Komentar

Postingan populer dari blog ini

Tugas PBO Remote AC

Hey guys! In this post I'm going to show you how to make an AC Remote using BlueJ. I'm going to use 2 classes, which are: Main ACRemote Main /* * Main function for the AC Remote * * Elkana Hans Widersen * 05111740000127 * 23 September 2018 */ import java.util.Scanner; public class Main{ public static void main(String args[]){ int menu; Scanner input = new Scanner(System.in); //Creates the remote ACRemote remote = new ACRemote(); while(true){ //displays the remote interface every loop remote.display(); //scans for menu number menu = input.nextInt(); switch(menu){ //changes the temperature case 1: remote.TempUp(); break; case 2: remote.TempDown(); break; //sets the AC swing mode case 3: remote.getSwing(); break; //terminates when the AC turned off ...

UAS GUI 3.1

Nama: Elkana Hans Widersen NRP: 05111740000127 Kelas: PBO-A 1. Inilah rancangan interface dari image editor yang saya buat: 2. Berikut diagram dari kelas-kelas penyusun image editor saya beserta relasinya: Image Viewer: Kelas utama yang mengatur fitur-fitur utama dari image editor. Image Panel: Kelas swing untuk menampilkan gambar dalam format OF. Image File Manager: Mengatur fungsi load dan save. OF Image: Mendefinisikan gambar dalam format OF. Filter: Abstraksi dari filter-filter yang tersedia. Darker Filter: Berisi settingan filter Darker. Lighter Filter: Berisi settingan filter Lighter . Threshold Filter:  Berisi settingan filter Threshold. Fish-eye Filter:  Berisi settingan filter Fish-eye. 3. Berikut implementasi dari kelas-kelas di atas: Image Viewer import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import java.io.File; import java.util...

Tugas 3 PBO A

Hey guys! This time I have been working on making my own Ticket Machine using BlueJ. I am using 2 classes, which is Main and TicketMachine . TicketMachine /* * This class contains the declaration of the Ticket Machine we are going to use.. * * @author (Elkana Hans Widersen) * @version (17/9/2018) */ import java.util.Scanner; public class TicketMachine{ Scanner scan = new Scanner(System.in); // The price of a ticket from this machine. private int price; // The amount of money entered by a customer so far. private int balance; // The amount of tickets about to be printed. private int ticket; // The total amount of money collected by this machine. private int total; /* * Create a machine that issues tickets of the given price. * Note that the price must be greater than zero, and there * are no checks to ensure this. */ public TicketMachine(int ticketCost){ ...