Minggu, 30 September 2018

Jam Digital

Berikut hasil dan source code-nya.




Executor

 /**  
  * Write a description of class Executor here.  
  *  
  * @author (Ismail)  
  * @version (01102018)  
  */  
 public class Executor  
 {  
   public static void main(String[]args)  
   {  
     new Executor();  
   }  
   public Executor()  
   {  
     new waktu();  
   }  
 }  


Waktu

 /**  
  * Write a description of class waktu here.  
  *  
  * @author (Ismail)  
  * @version (01102018)  
  */  
 import javax.swing.*;  
 import java.awt.*;  
 import java.awt.event.*;  
 import java.util.Calendar;  
 public class waktu extends JFrame  
 {  
   private static final long serialVersionUID = 1L;  
   JTextField timeF;  
   JPanel panel;  
   public waktu()  
   {  
     super("Java Clock by Ismail Arifin");  
     setSize(500,200);  
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
     setVisible(true);  
     setResizable(true);  
     setLocationRelativeTo(null);  
     panel = new JPanel();  
     panel.setLayout(new FlowLayout());  
     timeF = new JTextField(10);  
     timeF.setEditable(false);  
     timeF.setFont(new Font("Arial",Font.PLAIN,50));  
     panel.add(timeF);  
     add(panel);  
     Timer t = new Timer(1000,new Listener());  
     t.start();  
   }  
   class Listener implements ActionListener  
   {  
     public void actionPerformed(ActionEvent e)  
     {  
       Calendar rightNow = Calendar.getInstance();  
       int hour = rightNow.get(Calendar.HOUR_OF_DAY);  
       int min = rightNow.get(Calendar.MINUTE);  
       int sec = rightNow.get(Calendar.SECOND);  
       timeF.setText(hour+":"+min+":"+sec);  
     }  
   }  
 }  

Minggu, 23 September 2018

Tugas 4 PBO

Pada perkuliahan minggu sebelumnya, kelas saya mendapatkan tugas untuk membuat projek remot tv menggunakan BlueJ. Berikut hasil beserta source code-nya.






Remote TV

 /**  
  * RemotTV  
  *  
  * @author (Ismail)  
  * @version (23/09/2018)  
  */  
 public class RemotTV  
 {  
   private int channel;  
   private int volume;  
   public RemotTV()  
   {  
     channel = 0;  
     volume = 50;  
   }  
   public void cekTV()  
   {  
     System.out.println("##########################");  
     System.out.println("# Anda sedang menonton #");  
     if(channel > 0 && channel <8)  
     {  
       switch(channel)  
       {  
         case 1:  
         System.out.println("#\tSCTV");  
         break;  
         case 2:  
         System.out.println("#\tINDOSIAR");  
         break;  
         case 3:  
         System.out.println("#\tRCTI");  
         break;  
         case 4:  
         System.out.println("#\tGLOBAL TV");  
         break;  
         case 5:  
         System.out.println("#\tTRANS TV");  
         break;  
         case 6:  
         System.out.println("#\tANTV");  
         break;  
         case 7:  
         System.out.println("#\tNET TV");  
         break;  
       }  
     }  
     else  
     {  
       System.out.println("# Channel tidak tersedia");  
     }  
     System.out.println("# Selamat Menyaksikan #");  
     System.out.println("##########################");  
   }  
   public int gantichannel(int nomor)  
   {  
     return channel=nomor;  
   }  
   public int cekvolume()  
   {  
     return volume;  
   }  
   public int tambahvolume()  
   {  
     return volume+=1;  
   }  
   public int kurangivolume()  
   {  
     return volume-=1;  
   }  
 }  


Main

 /**  
  * Main.  
  *  
  * @author (Ismail)  
  * @version (23/09/2018)  
  */  
 import java.util.Scanner;  
 public class Main  
 {  
   public static void main(String args[])  
   {  
     Scanner scan = new Scanner(System.in);  
     int menu, channel, volume;  
     RemotTV remot = new RemotTV();  
     System.out.println("1. Nonton TV");  
     System.out.println("2. Ganti Channel");  
     System.out.println("3. Cek Volume");  
     System.out.println("4. Tambah Volume");  
     System.out.println("5. Kurangi Volume");  
     System.out.println("6. Matikan TV");  
     int tipe=1;  
     while(tipe == 1)  
     {  
       menu = scan.nextInt();  
       switch(menu)  
       {  
         case 1:  
         remot.cekTV();  
         break;  
         case 2:  
         System.out.println("Pilih channel yang ingin ditonton");  
         System.out.println("1 - SCTV");  
         System.out.println("2 - INDOSIAR");                  
         System.out.println("3 - RCTI");          
         System.out.println("4 - GLOBAL TV");          
         System.out.println("5 - TRANS TV");          
         System.out.println("6 - ANTV");          
         System.out.println("7 - NET TV");  
         int angka = scan.nextInt();  
         remot.gantichannel(angka);  
         break;  
         case 3:  
         System.out.println("Volume : " +remot.cekvolume()+ "\n");  
         break;  
         case 4:  
         int nilai = remot.cekvolume();  
         if(nilai < 100)  
         System.out.println("Volume : " +remot.tambahvolume()+ "\n");  
         break;  
         case 5:  
         int nilai_ = remot.cekvolume();  
         if(nilai_ > 0)  
         System.out.println("Volume : " +remot.kurangivolume()+ "\n");  
         break;  
         case 6:  
         tipe = 0;  
         System.out.println("##############");  
         System.out.println("#TV Dimatikan#");  
         System.out.println("##############");  
         break;  
       }  
     }  
   }  
 }  

Senin, 17 September 2018

Tugas 3 PBO

Minggu ke-3 Perkuliahan, membuat class dan object studi kasus ticket machine menggunakan BlueJ. Berikut hasil dan source code-nya.




Ticket Machine

 /**  
  * Ticket Machine  
  *  
  * @author (Ismail)  
  * @version (16092018)  
  */  
 public class TicketMachine  
 {  
   private int price;  
   private int balance;  
   private int total;  
   public TicketMachine(int ticketCost)  
   {  
     price = ticketCost;  
     balance = 0;  
     total = 0;  
   }  
   public int getPrice()  
   {  
     return price;  
   }  
   public int getBalance()  
   {  
     return balance;  
   }  
   public void insertMoney(int amount)  
   {  
     balance += amount;  
   }  
   public void printTicket()  
   {  
     int bayar = balance;  
     balance = balance - price;  
     System.out.println("####################");  
     System.out.println("# Cinema XVIII");  
     System.out.println("# Tiket");  
     System.out.println("# " + price + " Rupiah");  
     System.out.println("Bayar "+bayar+" Rupiah");  
     System.out.println("Kembalian "+balance+" Rupiah");  
     System.out.println("####################");  
     System.out.println();  
     total = total + balance;  
     balance = 0;  
   }  
 }  


Main

 /**  
  * Main  
  *  
  * @author (Ismail)  
  * @version (16092018)  
  */  
 import java.util.Scanner;  
 public class IntMain  
 {  
   public static void main(String args[])  
   {  
     Scanner scan = new Scanner(System.in);  
     int cost, menu;  
     System.out.println("Masukkan harga tiket \n");  
     cost = scan.nextInt();  
     TicketMachine ticket = new TicketMachine(cost);  
     System.out.println("1. Get Price");  
     System.out.println("2. Get Balance");  
     System.out.println("3. Insert Money");  
     System.out.println("4. Print Ticket");  
     System.out.println("5. Exit");  
     int tipe=1;  
     while(tipe == 1)  
     {  
       menu = scan.nextInt();  
       switch(menu)  
       {  
         case 1:  
         cost = ticket.getPrice();  
         System.out.println(cost);  
         break;  
         case 2:  
         System.out.print(ticket.getBalance()+"\n");  
         break;  
         case 3:  
         int money = scan.nextInt();  
         ticket.insertMoney(money);  
         break;  
         case 4:  
         ticket.printTicket();  
         break;  
         case 5:  
         tipe=0;  
         break;  
       }  
     }  
   }  
 }  

Minggu, 16 September 2018

Tugas 2 PBO

Pada pertemuan Minggu ke-3 sebelumnya, kami medapatkan tugas untuk membuat sebuah pemandangan menggunakan BlueJ. Berikut hasil dan source code-nya.




Picture

 /**  
  * This class represents a simple picture. You can draw the picture using  
  * the draw method. But wait, there's more: being an electronic picture, it  
  * can be changed. You can set it to black-and-white display and back to  
  * colors (only after it's been drawn, of course).  
  *  
  * This class was written as an early example for teaching Java with BlueJ.  
  *   
  * @author Michael Kölling and David J. Barnes  
  * @version 1.1 (24 May 2001)  
  */  
 public class Picture  
 {  
   private Square kotak;  
   private Triangle gunung1;  
   private Triangle gunung2;  
   private Triangle jalan;  
   private Circle sun;  
   private Circle awan1;  
   private Circle awan2;  
   private Circle awan3;  
   private Circle awan4;  
   private Circle awan5;  
   private Square rumah1;  
   private Square rumah2;  
   private Triangle rumah3;  
   /**  
    * Constructor for objects of class Picture  
    */  
   public Picture()  
   {  
     // nothing to do... instance variables are automatically set to null  
   }  
   /**  
    * Draw this picture.  
    */  
   public void draw()  
   {  
     kotak = new Square();  
     kotak.changeColor("blue");  
     kotak.moveVertical(-150);  
     kotak.moveHorizontal(0);  
     kotak.changeSize(300);  
     kotak.makeVisible();  
     jalan = new Triangle();  
     jalan.changeColor("black");  
     jalan.moveVertical(140);  
     jalan.moveHorizontal(140);  
     jalan.changeSize(170, 70);  
     jalan.makeVisible();  
     sun = new Circle();  
     sun.changeColor("yellow");  
     sun.moveVertical(100);  
     sun.moveHorizontal(130);  
     sun.changeSize(50);  
     sun.makeVisible();  
     gunung1 = new Triangle();  
     gunung1.changeColor("green");  
     gunung1.moveVertical(100);  
     gunung1.moveHorizontal(80);  
     gunung1.changeSize(60, 200);  
     gunung1.makeVisible();  
     gunung2 = new Triangle();  
     gunung2.changeColor("green");  
     gunung2.moveVertical(100);  
     gunung2.moveHorizontal(220);  
     gunung2.changeSize(60, 200);  
     gunung2.makeVisible();  
     awan1 = new Circle();  
     awan1.changeColor("white");  
     awan1.moveVertical(40);  
     awan1.moveHorizontal(100);  
     awan1.changeSize(40);  
     awan1.makeVisible();  
     awan2 = new Circle();  
     awan2.changeColor("white");  
     awan2.moveVertical(40);  
     awan2.moveHorizontal(80);  
     awan2.changeSize(37);  
     awan2.makeVisible();  
     awan3 = new Circle();  
     awan3.changeColor("white");  
     awan3.moveVertical(40);  
     awan3.moveHorizontal(80);  
     awan3.changeSize(35);  
     awan3.makeVisible();  
     awan4 = new Circle();  
     awan4.changeColor("white");  
     awan4.moveVertical(40);  
     awan4.moveHorizontal(200);  
     awan4.changeSize(30);  
     awan4.makeVisible();  
     awan5 = new Circle();  
     awan5.changeColor("white");  
     awan5.moveVertical(40);  
     awan5.moveHorizontal(220);  
     awan5.changeSize(30);  
     awan5.makeVisible();  
     rumah1 = new Square();  
     rumah1.changeColor("red");  
     rumah1.moveVertical(240);  
     rumah1.moveHorizontal(20);  
     rumah1.changeSize(70);  
     rumah1.makeVisible();  
     rumah2 = new Square();  
     rumah2.changeColor("black");  
     rumah2.moveVertical(260);  
     rumah2.moveHorizontal(45);  
     rumah2.changeSize(20);  
     rumah2.makeVisible();  
     rumah3 = new Triangle();  
     rumah3.changeColor("brown");  
     rumah3.moveVertical(200);  
     rumah3.moveHorizontal(55);  
     rumah3.changeSize(50, 100);  
     rumah3.makeVisible();  
   }  
 }  


Canvas

 import javax.swing.*;  
 import java.awt.*;  
 import java.util.List;  
 import java.util.*;  
 /**  
  * Canvas is a class to allow for simple graphical drawing on a canvas.  
  * This is a modification of the general purpose Canvas, specially made for  
  * the BlueJ "shapes" example.   
  *  
  * @author: Bruce Quig  
  * @author: Michael Kölling (mik)  
  *  
  * @version: 1.6 (shapes)  
  */  
 public class Canvas  
 {  
   // Note: The implementation of this class (specifically the handling of  
   // shape identity and colors) is slightly more complex than necessary. This  
   // is done on purpose to keep the interface and instance fields of the  
   // shape objects in this project clean and simple for educational purposes.  
   private static Canvas canvasSingleton;  
   /**  
    * Factory method to get the canvas singleton object.  
    */  
   public static Canvas getCanvas()  
   {  
     if(canvasSingleton == null) {  
       canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300,   
           Color.white);  
     }  
     canvasSingleton.setVisible(true);  
     return canvasSingleton;  
   }  
   // ----- instance part -----  
   private JFrame frame;  
   private CanvasPane canvas;  
   private Graphics2D graphic;  
   private Color backgroundColour;  
   private Image canvasImage;  
   private List<Object> objects;  
   private HashMap<Object, ShapeDescription> shapes;  
   /**  
    * Create a Canvas.  
    * @param title title to appear in Canvas Frame  
    * @param width the desired width for the canvas  
    * @param height the desired height for the canvas  
    * @param bgClour the desired background colour of the canvas  
    */  
   private Canvas(String title, int width, int height, Color bgColour)  
   {  
     frame = new JFrame();  
     canvas = new CanvasPane();  
     frame.setContentPane(canvas);  
     frame.setTitle(title);  
     canvas.setPreferredSize(new Dimension(width, height));  
     backgroundColour = bgColour;  
     frame.pack();  
     objects = new ArrayList<Object>();  
     shapes = new HashMap<Object, ShapeDescription>();  
   }  
   /**  
    * Set the canvas visibility and brings canvas to the front of screen  
    * when made visible. This method can also be used to bring an already  
    * visible canvas to the front of other windows.  
    * @param visible boolean value representing the desired visibility of  
    * the canvas (true or false)   
    */  
   public void setVisible(boolean visible)  
   {  
     if(graphic == null) {  
       // first time: instantiate the offscreen image and fill it with  
       // the background colour  
       Dimension size = canvas.getSize();  
       canvasImage = canvas.createImage(size.width, size.height);  
       graphic = (Graphics2D)canvasImage.getGraphics();  
       graphic.setColor(backgroundColour);  
       graphic.fillRect(0, 0, size.width, size.height);  
       graphic.setColor(Color.black);  
     }  
     frame.setVisible(visible);  
   }  
   /**  
    * Draw a given shape onto the canvas.  
    * @param referenceObject an object to define identity for this shape  
    * @param color      the color of the shape  
    * @param shape      the shape object to be drawn on the canvas  
    */  
    // Note: this is a slightly backwards way of maintaining the shape  
    // objects. It is carefully designed to keep the visible shape interfaces  
    // in this project clean and simple for educational purposes.  
   public void draw(Object referenceObject, String color, Shape shape)  
   {  
     objects.remove(referenceObject);  // just in case it was already there  
     objects.add(referenceObject);   // add at the end  
     shapes.put(referenceObject, new ShapeDescription(shape, color));  
     redraw();  
   }  
   /**  
    * Erase a given shape's from the screen.  
    * @param referenceObject the shape object to be erased   
    */  
   public void erase(Object referenceObject)  
   {  
     objects.remove(referenceObject);  // just in case it was already there  
     shapes.remove(referenceObject);  
     redraw();  
   }  
   /**  
    * Set the foreground colour of the Canvas.  
    * @param newColour  the new colour for the foreground of the Canvas   
    */  
   public void setForegroundColor(String colorString)  
   {  
     if(colorString.equals("red"))  
       graphic.setColor(Color.red);  
     else if(colorString.equals("black"))  
       graphic.setColor(Color.black);  
     else if(colorString.equals("blue"))  
       graphic.setColor(Color.blue);  
     else if(colorString.equals("yellow"))  
       graphic.setColor(Color.yellow);  
     else if(colorString.equals("green"))  
       graphic.setColor(Color.green);  
     else if(colorString.equals("magenta"))  
       graphic.setColor(Color.magenta);  
     else if(colorString.equals("white"))  
       graphic.setColor(Color.white);  
     else  
       graphic.setColor(Color.black);  
   }  
   /**  
    * Wait for a specified number of milliseconds before finishing.  
    * This provides an easy way to specify a small delay which can be  
    * used when producing animations.  
    * @param milliseconds the number   
    */  
   public void wait(int milliseconds)  
   {  
     try  
     {  
       Thread.sleep(milliseconds);  
     }   
     catch (Exception e)  
     {  
       // ignoring exception at the moment  
     }  
   }  
   /**  
    * Redraw ell shapes currently on the Canvas.  
    */  
   private void redraw()  
   {  
     erase();  
     for(Iterator i=objects.iterator(); i.hasNext(); ) {  
       ((ShapeDescription)shapes.get(i.next())).draw(graphic);  
     }  
     canvas.repaint();  
   }  
   /**  
    * Erase the whole canvas. (Does not repaint.)  
    */  
   private void erase()  
   {  
     Color original = graphic.getColor();  
     graphic.setColor(backgroundColour);  
     Dimension size = canvas.getSize();  
     graphic.fill(new Rectangle(0, 0, size.width, size.height));  
     graphic.setColor(original);  
   }  
   /************************************************************************  
    * Inner class CanvasPane - the actual canvas component contained in the  
    * Canvas frame. This is essentially a JPanel with added capability to  
    * refresh the image drawn on it.  
    */  
   private class CanvasPane extends JPanel  
   {  
     public void paint(Graphics g)  
     {  
       g.drawImage(canvasImage, 0, 0, null);  
     }  
   }  
   /************************************************************************  
    * Inner class CanvasPane - the actual canvas component contained in the  
    * Canvas frame. This is essentially a JPanel with added capability to  
    * refresh the image drawn on it.  
    */  
   private class ShapeDescription  
   {  
     private Shape shape;  
     private String colorString;  
     public ShapeDescription(Shape shape, String color)  
     {  
       this.shape = shape;  
       colorString = color;  
     }  
     public void draw(Graphics2D graphic)  
     {  
       setForegroundColor(colorString);  
       graphic.fill(shape);  
     }  
   }  
 }  


Triangle

 import java.awt.*;  
 /**  
  * A triangle that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Michael Kölling and David J. Barnes  
  * @version 1.0 (15 July 2000)  
  */  
 public class Triangle  
 {  
   private int height;  
   private int width;  
   private int xPosition;  
   private int yPosition;  
   private String color;  
   private boolean isVisible;  
   /**  
    * Create a new triangle at default position with default color.  
    */  
   public Triangle()  
   {  
     height = 30;  
     width = 40;  
     xPosition = 0;  
     yPosition = 0;  
     color = "green";  
     isVisible = false;  
   }  
   /**  
    * Make this triangle visible. If it was already visible, do nothing.  
    */  
   public void makeVisible()  
   {  
     isVisible = true;  
     draw();  
   }  
   /**  
    * Make this triangle invisible. If it was already invisible, do nothing.  
    */  
   public void makeInvisible()  
   {  
     erase();  
     isVisible = false;  
   }  
   /**  
    * Move the triangle a few pixels to the right.  
    */  
   public void moveRight()  
   {  
     moveHorizontal(20);  
   }  
   /**  
    * Move the triangle a few pixels to the left.  
    */  
   public void moveLeft()  
   {  
     moveHorizontal(-20);  
   }  
   /**  
    * Move the triangle a few pixels up.  
    */  
   public void moveUp()  
   {  
     moveVertical(-20);  
   }  
   /**  
    * Move the triangle a few pixels down.  
    */  
   public void moveDown()  
   {  
     moveVertical(20);  
   }  
   /**  
    * Move the triangle horizontally by 'distance' pixels.  
    */  
   public void moveHorizontal(int distance)  
   {  
     erase();  
     xPosition += distance;  
     draw();  
   }  
   /**  
    * Move the triangle vertically by 'distance' pixels.  
    */  
   public void moveVertical(int distance)  
   {  
     erase();  
     yPosition += distance;  
     draw();  
   }  
   /**  
    * Slowly move the triangle horizontally by 'distance' pixels.  
    */  
   public void slowMoveHorizontal(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       xPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Slowly move the triangle vertically by 'distance' pixels.  
    */  
   public void slowMoveVertical(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       yPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Change the size to the new size (in pixels). Size must be >= 0.  
    */  
   public void changeSize(int newHeight, int newWidth)  
   {  
     erase();  
     height = newHeight;  
     width = newWidth;  
     draw();  
   }  
   /**  
    * Change the color. Valid colors are "red", "yellow", "blue", "green",  
    * "magenta" and "black".  
    */  
   public void changeColor(String newColor)  
   {  
     color = newColor;  
     draw();  
   }  
   /*  
    * Draw the triangle with current specifications on screen.  
    */  
   private void draw()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };  
       int[] ypoints = { yPosition, yPosition + height, yPosition + height };  
       canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));  
       canvas.wait(10);  
     }  
   }  
   /*  
    * Erase the triangle on screen.  
    */  
   private void erase()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.erase(this);  
     }  
   }  
 }  


Square

 import java.awt.*;  
 /**  
  * A square that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Michael Kölling and David J. Barnes  
  * @version 1.0 (15 July 2000)  
  */  
 public class Square  
 {  
   private int size;  
   private int xPosition;  
   private int yPosition;  
   private String color;  
   private boolean isVisible;  
   /**  
    * Create a new square at default position with default color.  
    */  
   public Square()  
   {  
     size = 30;  
     xPosition = 0;  
     yPosition = 0;  
     color = "red";  
     isVisible = false;  
   }  
   /**  
    * Make this square visible. If it was already visible, do nothing.  
    */  
   public void makeVisible()  
   {  
     isVisible = true;  
     draw();  
   }  
   /**  
    * Make this square invisible. If it was already invisible, do nothing.  
    */  
   public void makeInvisible()  
   {  
     erase();  
     isVisible = false;  
   }  
   /**  
    * Move the square a few pixels to the right.  
    */  
   public void moveRight()  
   {  
     moveHorizontal(20);  
   }  
   /**  
    * Move the square a few pixels to the left.  
    */  
   public void moveLeft()  
   {  
     moveHorizontal(-20);  
   }  
   /**  
    * Move the square a few pixels up.  
    */  
   public void moveUp()  
   {  
     moveVertical(-20);  
   }  
   /**  
    * Move the square a few pixels down.  
    */  
   public void moveDown()  
   {  
     moveVertical(20);  
   }  
   /**  
    * Move the square horizontally by 'distance' pixels.  
    */  
   public void moveHorizontal(int distance)  
   {  
     erase();  
     xPosition += distance;  
     draw();  
   }  
   /**  
    * Move the square vertically by 'distance' pixels.  
    */  
   public void moveVertical(int distance)  
   {  
     erase();  
     yPosition += distance;  
     draw();  
   }  
   /**  
    * Slowly move the square horizontally by 'distance' pixels.  
    */  
   public void slowMoveHorizontal(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       xPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Slowly move the square vertically by 'distance' pixels.  
    */  
   public void slowMoveVertical(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       yPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Change the size to the new size (in pixels). Size must be >= 0.  
    */  
   public void changeSize(int newSize)  
   {  
     erase();  
     size = newSize;  
     draw();  
   }  
   /**  
    * Change the color. Valid colors are "red", "yellow", "blue", "green",  
    * "magenta" and "black".  
    */  
   public void changeColor(String newColor)  
   {  
     color = newColor;  
     draw();  
   }  
   /*  
    * Draw the square with current specifications on screen.  
    */  
   private void draw()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.draw(this, color,  
           new Rectangle(xPosition, yPosition, size, size));  
       canvas.wait(10);  
     }  
   }  
   /*  
    * Erase the square on screen.  
    */  
   private void erase()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.erase(this);  
     }  
   }  
 }  


Circle

 import java.awt.*;  
 import java.awt.geom.*;  
 /**  
  * A circle that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Michael Kölling and David J. Barnes  
  * @version 1.0 (15 July 2000)  
  */  
 public class Circle  
 {  
   private int diameter;  
   private int xPosition;  
   private int yPosition;  
   private String color;  
   private boolean isVisible;  
   /**  
    * Create a new circle at default position with default color.  
    */  
   public Circle()  
   {  
     diameter = 30;  
     xPosition = 0;  
     yPosition = 0;  
     color = "blue";  
     isVisible = false;  
   }  
   /**  
    * Make this circle visible. If it was already visible, do nothing.  
    */  
   public void makeVisible()  
   {  
     isVisible = true;  
     draw();  
   }  
   /**  
    * Make this circle invisible. If it was already invisible, do nothing.  
    */  
   public void makeInvisible()  
   {  
     erase();  
     isVisible = false;  
   }  
   /**  
    * Move the circle a few pixels to the right.  
    */  
   public void moveRight()  
   {  
     moveHorizontal(20);  
   }  
   /**  
    * Move the circle a few pixels to the left.  
    */  
   public void moveLeft()  
   {  
     moveHorizontal(-20);  
   }  
   /**  
    * Move the circle a few pixels up.  
    */  
   public void moveUp()  
   {  
     moveVertical(-20);  
   }  
   /**  
    * Move the circle a few pixels down.  
    */  
   public void moveDown()  
   {  
     moveVertical(20);  
   }  
   /**  
    * Move the circle horizontally by 'distance' pixels.  
    */  
   public void moveHorizontal(int distance)  
   {  
     erase();  
     xPosition += distance;  
     draw();  
   }  
   /**  
    * Move the circle vertically by 'distance' pixels.  
    */  
   public void moveVertical(int distance)  
   {  
     erase();  
     yPosition += distance;  
     draw();  
   }  
   /**  
    * Slowly move the circle horizontally by 'distance' pixels.  
    */  
   public void slowMoveHorizontal(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       xPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Slowly move the circle vertically by 'distance' pixels.  
    */  
   public void slowMoveVertical(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       yPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Change the size to the new size (in pixels). Size must be >= 0.  
    */  
   public void changeSize(int newDiameter)  
   {  
     erase();  
     diameter = newDiameter;  
     draw();  
   }  
   /**  
    * Change the color. Valid colors are "red", "yellow", "blue", "green",  
    * "magenta" and "black".  
    */  
   public void changeColor(String newColor)  
   {  
     color = newColor;  
     draw();  
   }  
   /*  
    * Draw the circle with current specifications on screen.  
    */  
   private void draw()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,   
           diameter, diameter));  
       canvas.wait(10);  
     }  
   }  
   /*  
    * Erase the circle on screen.  
    */  
   private void erase()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.erase(this);  
     }  
   }  
 }  

Minggu, 09 September 2018

Tugas 2 PBO

Kuliah Minggu ke-3 PBO, Saya belajar membuat class untuk beberapa bangun ruang(3D) dengan method luas permukaan dan volume.
Berikut Hasil dan Source code-nya.



Class Main :

 /**  
  *   
  *  
  * @author (Ismail Arifin)  
  * @version (10/09/2018)  
  */  
 public class Main  
 {  
   public static void main(String args[])  
   {  
     kubus akubus;  
     akubus = new kubus();  
     akubus.s = 5;  
     double lpkubus = akubus.luasp();  
     double vkubus= akubus.volume();  
     System.out.println("Kubus");  
     System.out.println("Sisi = "+akubus.s);  
     System.out.println("Luas permukaan = "+lpkubus);  
     System.out.println("Volume = "+vkubus);  
     System.out.println();  
     balok abalok;  
     abalok = new balok();  
     abalok.p = 10;  
     abalok.l = 5;  
     abalok.t = 4;  
     double lpbalok = abalok.luasp();  
     double vbalok = abalok.volume();  
     System.out.println("Balok");  
     System.out.println("Panjang = "+abalok.p+" Lebar = "+abalok.l+" Tinggi = "+abalok.t);  
     System.out.println("Luas permukaan = "+lpbalok);  
     System.out.println("Volume = "+vbalok);  
     System.out.println();  
     Tabung aTabung;  
     aTabung = new Tabung();  
     aTabung.r = 5;  
     aTabung.t = 10;  
     double lptabung = aTabung.luasp();  
     double vtabung = aTabung.volume();  
     System.out.println("Tabung");  
     System.out.println("Jari-jari = "+aTabung.r+" Tinggi = "+aTabung.t);  
     System.out.println("Luas permukaan = "+lptabung);  
     System.out.println("Volume = "+vtabung);  
     System.out.println();  
     Bola aBola;  
     aBola = new Bola();  
     aBola.r = 7;  
     double lpbola = aBola.luasp();  
     double vbola = aBola.volume();  
     System.out.println("Bola");  
     System.out.println("Jari-jari = "+aBola.r);  
     System.out.println("Luas permukaan = "+lpbola);  
     System.out.println("Volume = "+vbola);  
     System.out.println();  
   }  
 }


Class Kubus :

 /**  
  * Program implementasi kubus   
  *  
  * @author (Ismail Arifin)  
  * @version (10/09/2018)  
  */  
 public class kubus  
 {  
   public double s;  
   public double luasp()  
   {  
     return 6*s*s;  
   }  
   public double volume()  
   {  
     return s*s*s;  
   }  
 }  


Class Balok :

 /**  
  * Program implementasi Balok  
  *  
  * @author (Ismail Arifin)  
  * @version (10/09/2018)  
  */  
 public class balok  
 {  
   public double p, l, t;  
   public double luasp()  
   {  
     return 2*(p*l+p*t+l*t);  
   }  
   public double volume()  
   {  
     return p*l*t;  
   }  
 }  


Class Tabung :

 /**  
  * Program implementasi tabung  
  *  
  * @author (Ismail Arifin)  
  * @version (10/09/2018)  
  */  
 public class Tabung  
 {  
   public double r, t;  
   public double luasp()  
   {  
     return 2*3.14*r*(r+t);  
   }  
   public double volume()  
   {  
     return 3.14*r*r*t;  
   }  
 }  


Class Bola :

 /**  
  * program implementasi bola  
  *  
  * @author (Ismail Arifin)  
  * @version (10/09/2018)  
  */  
 public class Bola  
 {  
   public double r;  
   public double luasp()  
   {  
     return 4*3.14*r*r;  
   }  
   public double volume()  
   {  
     return 4/3*3*r*r*r;  
   }  
 }  


Minggu, 02 September 2018

Tugas 1 PBO

Kuliah minggu ke-2 PBO, Saya belajar membuat program menggunakan bahasa java dan software yang digunakan yaitu BlueJ. Berikut hasil dan source code-nya.





 /**  


  * Write a description of class Perkenalan here.  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 public class Perkenalan  
 {  
   // instance variables - replace the example below with your own  
   private int x;  
   /**  
    * Constructor for objects of class Perkenalan  
    */  
   public Perkenalan()  
   {  
     // initialise instance variables  
     System.out.print("\t\tTugas #PBOA-Tugas1\n");  
     System.out.print("==============================================\n");  
     System.out.print("Nama\t\t: Ismail Arifin\n");  
     System.out.print("Kelas\t\t: PBO B\n");  
     System.out.print("Alamat Rumah\t: Keputih Gg IIC No.24\n");  
     System.out.print("Email\t\t: Ismail.a2803@gmail.com\n");  
     System.out.print("Blog\t\t: ismailarifin28.blogspot.com\n");  
     System.out.print("No HP/WA\t: 081241000939\n");  
     System.out.print("==============================================\n");  
     x = 0;  
   }  
   /**  
    * An example of a method - replace this comment with your own  
    *  
    * @param y a sample parameter for a method  
    * @return  the sum of x and y  
    */  
   public int sampleMethod(int y)  
   {  
     // put your code here  
     return x + y;  
   }  
 }  

EAS PBO B

1. Rancangan interface image editor. 2. Class diagram dari image editor yang akan dibuat terdiri atas 10 class seperti berikut. ...