Minggu, 30 September 2018

Jam DIgital

Tugas PBO B - Jam Digital

Nama   : Yasinta Yusniawati
Kelas    : PBO-B
NRP     : 05111740000054


Untuk membuat jam digital di perlukan beberapa class yaitu :
  1. NumberDisplay
  2. ClockDisplay
  3. TestClockDisplay 
  4. Clock (GUI)

Source Code dari masing-masing class :


1. NumberDisplay

/**  
  * Write a description of class NumberDisplay here.  
  *  
  * @author Yasinta Yusniawati 
  * @version 1.0  
  */   
 public class NumberDisplay  
 {  
   private int limit;  
   private int value;  
   public NumberDisplay(int rollOverLimit)  
   {  
     limit = rollOverLimit;  
     value = 0;  
   }  
   public int getValue()  
   {  
     return value;  
   }  
   public void setValue(int replacementValue)  
   {  
     if((replacementValue >= 0) && (replacementValue < limit)) {  
           value = replacementValue;  
     }  
   }  
   public String getDisplayValue()  
   {  
     if(value < 10) {  
       return "0" +value ;  
     }  
     else {  
       return "" +value ;  
     }  
   }  
   public void increment()  
   {  
     value = (value + 1) % limit;  
   }  
 }  

2. ClockDisplay

/**  
  * Write a description of class ClockDisplay here.  
  *  
  * @author Yasinta Yusniawati  
  * @version 1.0  
  */   
 public class ClockDisplay  
 {  
   private NumberDisplay hours;  
   private NumberDisplay minutes;  
   private String displayString; //simulates the actual display  
   public ClockDisplay()  
   {  
     hours = new NumberDisplay(24);  
     minutes = new NumberDisplay(60);  
     updateDisplay();  
   }  
   public ClockDisplay(int hour, int minute)  
   {  
     hours = new NumberDisplay(12);  
     minutes = new NumberDisplay(60);  
     setTime(hour, minute);  
   }  
   public void timeTick()  
   {  
     minutes.increment();  
     if(minutes.getValue() == 0) { //it just rolled over  
       hours.increment();  
     }  
     updateDisplay();  
   }  
   public void setTime(int hour, int minute)  
   {  
     hours.setValue(hour);  
     minutes.setValue(minute);  
     updateDisplay();  
   }  
   public String getTime()  
   {  
     return displayString;  
   }  
   private void updateDisplay()  
   {  
     displayString = hours.getDisplayValue() + ":" +  
             minutes.getDisplayValue();  
   }  
 }  

3. TestClockDisplay

/**  
  * Write a description of class TestClockDisplay here.  
  *  
  * @author Yasinta Yusniawati  
  * @version 1.0  
  */   
 public class TestClockDisplay  
 {  
   public void test()  
   {  
     ClockDisplay clock = new ClockDisplay();  
     clock.setTime(0,0);  
     System.out.println(clock.getTime());  
     clock.setTime(12,00);  
     System.out.println(clock.getTime());  
     clock.setTime(18,45);  
     System.out.println(clock.getTime());  
     clock.setTime(21,16);  
     System.out.println(clock.getTime());  
   }  
 }  


4. ClockGUI

/**  
  * Write a description of class ClockGUI here  
  *  
  * @author Yasinta Yusniawati  
  * @version 1.0  
  */   
  import javax.swing.*;  
  import javax.swing.border.*;  
  import java.awt.*;  
  import java.awt.event.*;  
  public class ClockGUI   
  {   
   private JFrame frame;   
   private JLabel label;   
   private ClockDisplay clock;   
   private boolean clockOn = false;   
   private TimerThread timerThread;   
   public void Clock()   
   {   
    makeFrame();   
    clock = new ClockDisplay();   
   }   
   private void start()   
   {   
    clockOn = true;   
    timerThread = new TimerThread();   
    timerThread.start();   
   }   
   private void stop()   
   {   
    clockOn = false;   
   }   
   private void step()   
   {   
    clock.timeTick();   
    label.setText(clock.getTime());   
   }   
   private void showTentang()   
   {   
    JOptionPane.showMessageDialog (frame, "Jam Digital\n" +    
    "Jam digital dengan Bahasa Java.",   
    "Tentang",  
    JOptionPane.INFORMATION_MESSAGE);   
   }   
   private void quit()   
   {   
    System.exit(0);   
   }   
   private void makeFrame()   
   {   
    frame = new JFrame("Jam");   
    JPanel contentPane = (JPanel)frame.getContentPane();   
    contentPane.setBorder(new EmptyBorder(1,60,1,60));   
    makeMenuBar(frame);   
    contentPane.setLayout(new BorderLayout(12,12));   
    label = new JLabel("00:00", SwingConstants.CENTER);   
    Font displayFont = label.getFont().deriveFont(96.0f);   
    label.setFont(displayFont);   
    contentPane.add(label, BorderLayout.CENTER);   
    JPanel toolbar = new JPanel();   
    toolbar.setLayout(new GridLayout(1,0));   
    JButton startButton = new JButton("Start");   
    startButton.addActionListener(e->start());   
    toolbar.add(startButton);   
    JButton stopButton = new JButton("Stop");   
    stopButton.addActionListener(e->stop());   
    toolbar.add(stopButton);   
    JButton stepButton = new JButton("Step");   
    stepButton.addActionListener(e->step());   
    toolbar.add(stepButton);   
    JPanel flow = new JPanel();   
    flow.add(toolbar);   
    contentPane.add(flow, BorderLayout.SOUTH);   
    frame.pack();   
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();   
    frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);   
    frame.setVisible(true);   
   }   
   private void makeMenuBar(JFrame frame)   
   {   
    final int SHORTCUT_MASK =    
    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();   
    JMenuBar menubar = new JMenuBar();   
    frame.setJMenuBar(menubar);   
    JMenu menu;   
    JMenuItem item;   
    menu = new JMenu("File");   
    menubar.add(menu);   
    item = new JMenuItem("Tentang Jam...");   
     item.addActionListener(e->showTentang());   
    menu.add(item);   
    menu.addSeparator();   
    item = new JMenuItem("Quit");   
     item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,SHORTCUT_MASK));   
     item.addActionListener(e->quit());   
    menu.add(item);   
   }   
   class TimerThread extends Thread   
   {   
    public void run()   
     {   
      while(clockOn)   
      {   
       step();   
       tunda();   
      }   
     }   
     private void tunda()   
     {   
      try    
      {   
       Thread.sleep(900);   
      }   
      catch(InterruptedException exc)   
      {   
      }   
    }   
   }   
  }

Ketika TestClockDisplay dijalankan akan muncul seperti ini :


Saat class ClockGUI di run, ada bebeapa tombol. Tombol start untuk memulai jam dan stop untuk menghentikan jam tombol set digunakan untuk melakukan increment pada detik jam secara manual. Secara default jam menunjukkan pukul 00.00 ketika tombol start belum di klik. berikut gambarnya :


Ketika tombol start di klik, detik dalam jam akan berjalan dan ketika di klik tombol stop jam akan berhenti








Minggu, 23 September 2018

Tugas Remot TV

Tugas  PBO - B Remot TV

Fitur - fitur yang dimiliki remot tv :
1. Channel plus (+) = mengganti channel ke atas 
2. Channel min (-)  = menganti channel ke bawah
3. Vol plus (+)         = menambah volume TV
4. Vol min (-)          = mengurangi volume TV
5. Get channel        = menampilkan channel saat ini
0. Turn on/off         = menyalakan/mematikanTV

Hasil :
  •  Ketika TV dalam kondisi mati muncul tulisan NO SIGNAL

  • Saat di ketikkan 0 akan muncul layar TV yang berarti TV telah hidup

  • Untuk menambah channel caranya tuliskan no 1, setiap kali di ketikkan no 1 berkali-kali channel TV akan naik

  • Untuk menambahkan volume caranya tulis no 3 pada layar dan seterusnya sesuan dengan volume yang di inginkan

  • Untuk mengurangi volume caranya tulis no 4 pada layar dan seterusnya sesuan dengan volumeyang di inginkan


    • Untuk mengganti channel ketikkan no 2 yaitu tombol untuk menurunkan channel dari urutan sebelumnya

    • untuk menampilkan channel saat ini ketikkan no 5 pada layar

    Class yang digunakan dalam program :


    Source :
    Main:
    
    /**
     * main untuk remot tv
     *
     * @author Yasinta Yusniawati
     * @version 23 sep 2018
     */
        import java.util.Scanner;
        public class main
        {
            public static void main(String args[])
            {
                Scanner scan = new Scanner(System.in);
                int menu;
                remotv remot = new remotv();
                System.out.println("1.Channel plus (+)");
                System.out.println("2.Channel min (-)");
                System.out.println("3.Vol plus (+)");
                System.out.println("4.Vol min (-)");
                System.out.println("5.Get Channel");
                System.out.println("0. Turn on/off");
                remot.cetak();
                menu = scan.nextInt();
                while(menu!=6){
                switch(menu) 
                {
                    case 0:
                    remot.powerset();
                    break;
                    case 1:
                    if(remot.getch()<20)remot.plusch();
                    else if(remot.getch()==20) remot.setch(0);
                    //remot.cetak();
                    break;
                    case 2:
                    if(remot.getch()>0)remot.minch();
                    else if(remot.getch()==0) remot.setch(20);
                    //remot.cetak();
                    break;
                    case 3:
                    if(remot.getvol()<20)remot.plusvol();
                    //remot.cetak();
                    break;
                    case 4:
                    if(remot.getvol()>0)remot.minvol();
                    break;
                }
                remot.cetak();
                System.out.println("1.Channel plus (+)");
                System.out.println("2.Channel min (-)");
                System.out.println("3.Vol plus (+)");
                System.out.println("4.Vol min (-)");
                System.out.println("5.Get Channel");
                System.out.println("0. Turn on/off");
                menu = scan.nextInt();
                System.out.print('\u000C');
            }
              
            }
        }
    
    

    Remote:
    
    /**
     * Remot tv
     *
     * @author Yasinta Yusniawati
     * 23 sep 2018
     */
    public class remotv
    {
       // volume
       private int vol;
       // channel
       private int ch; 
       // on/off
       private boolean power;
       
       public remotv ()
       {
           vol = 0;
           power = false;
           ch = 0;
       }
       public void plusvol()
       {
           vol = vol + 1;
       }
       public void minvol()
       {
           vol = vol - 1;
       }
       public void plusch()
       {       
           ch = ch + 1;
       }
       public void minch()
       {
           ch = ch - 1;
       }
       public void inputchanel(int input)
       {
           ch = input;
       }
       public void powerset()
       {
           if(!power) power = true;
           else power = false;
       }
       public void setch(int chan)
       {
           ch=chan;
       }
       public int getch()
       {
           return ch;
       }
       public boolean getpower()
       {
           return power;
       }
       public int getvol()
       {
           return vol;
       }
      public void cetak()
      {
          if(power){
          System.out.println("========================");
          System.out.println("|       POLITRAN        ");
          System.out.println("========================");
          System.out.println("|                       ");
          System.out.println("|                       ");
          System.out.println("|   Channel:"+ch+"      ");
          System.out.println("|                       ");
          System.out.println("|   Vol:"+vol);       
          System.out.println("========================");
            }
          else System.out.println("\nNO SIGNAL");
      }
    }
    
    
    

    Minggu, 16 September 2018

    Tugas Minggu ke 4 PBO

    TUGAS P4 PBO
    Membuat Mesin Tiket

    Pada pertemuan kali ini kami belajar membuat mesin tiket dengan menggunakan Java.
    Tugas dalam pertemuan kali ini adalah :
    1. Mengetahui harga tiket satuan
    2. Mengetahui saldo yang dimiliki
    3. Memasukkan uang 
    4. Mencetak tiket sebanyak n-tiket
    5. Mengambil kembalian jika ada


    Berikut merupakan class yang saya buat :


    Hasilnya :



    Source code :

    
    /**
     * TicketMachine
     *
     * @author Yasinta Yusniawati
     * @version 17 Sep 2018
     */
    public class tiketmesin
    {
        // harga tiket
        private int harga;
        //jumlah uang yang dimasukkan
        private int uangmasuk;
        //jumlah total uang yang dikumpulkan oleh mesin
        private int total;
    
        /**
         * Membuat mesin mengeluarkan tiket dari harga yang diberikan.
         * Harga harus lebih besar dari 0
         */
        
        public tiketmesin(int hargatiket)
        {
            harga       = hargatiket;
            uangmasuk   = 0;
            total       = 0;
        }
        /**
         * Untuk mengembalikan harga tiket
         */
        public int price()
        {
            return harga;
        }
        /**
         * Kembalikan jumlah uang yang sudah dimasukkan untuk tiket selanjutnya.
         */
        public int balance()
        {
            return uangmasuk;
        }
        /**
         * Menerima sejumlah uang dalam sen dari pelanggan.
         */
        public void masukkanUang(int jumlah)
        {
            uangmasuk = uangmasuk + jumlah;
        }
        /**
         * Print tiket, update total, dan mengembalikan harga tiket ke 0
         */
        public void cetaktiket()
        { 
            if(uangmasuk>=harga){
            System.out.println("********************");
            System.out.println("* Bus Express      *");
            System.out.println("* YOGJAKARTA       *");
            System.out.println("* Rp." + harga +"          *");
            System.out.println("********************");
            System.out.println();
            uangmasuk=uangmasuk-harga;
        }
            
        }  
     }
        
    
    

    main :

    
    /**
     * TicketMachine
     *
     * @author Yasinta Yusniawati
     * @version 17 Sep 2018
    */
    import java.util.Scanner;
    public class main
    {
       public static void main(String args[])
       {
           Scanner scan = new Scanner(System.in);
           int cost, menu, money, saldo=0;
           System.out.println("Masukkan harga tiket \n");
           cost     = scan.nextInt();
           tiketmesin tiket = new tiketmesin(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");
           menu = scan.nextInt();
           while(menu!=6){
               switch(menu)
               {
               case 1:
               cost = tiket.price();
               System.out.println(cost);
               break;
               case 2:
               System.out.println(tiket.balance());
               break;
               case 3:
               money = scan.nextInt();
               tiket.masukkanUang (money);
               saldo = tiket.balance();
               break;
               case 4:
               if(saldo>=cost){
                tiket.cetaktiket();
                saldo = saldo - cost;
               }
               else System.out.println("Saldo Anda tidak mencukupi!");
               break;
            }
            menu = scan.nextInt();
           }
           
        }
    }
    
    

    Tugas PBO Visual Objek Pemandangan

    TUGAS Rumah PBO
    Kelas dan Objek Pemandangan

    Dari objek dan kelas yang didapat, kali ini akan dibuat sebuah gambar pemandangan dengan menggunakan fungsi canvas dan dengan bangun-bangun dua dimensi sederhana.

    Yakni menggunakan bangun-bangun dua dimensi berikut;
    1. Segitiga
    2. Kotak
    3. Lingkaran
    Berikut merupakan contoh output dari program yang saya buat :


    Berikut merupakan daftar kelas yang digunakan :


    • Kelas 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;
    
        public static final Color darkgreen = new Color(1,50,32);
        public static final Color brown = new Color(102,51,0);
        public static final Color lgreen = new Color(144,238,144);
        /**
         * Factory method to get the canvas singleton object.
         */
        public static Canvas getCanvas()
        {
            if(canvasSingleton == null) {
                canvasSingleton = new Canvas("BlueJ Shapes Demo", 600, 600, 
                        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("orange"))
                graphic.setColor(Color.orange);
            else if(colorString.equals("white"))
                graphic.setColor(Color.white);
            else if(colorString.equals("cyan"))
                graphic.setColor(Color.cyan);
            else if(colorString.equals("lgray"))
                graphic.setColor(Color.lightGray);
            else if(colorString.equals("gray"))
                graphic.setColor(Color.gray);
            else if(colorString.equals("dgreen"))
                graphic.setColor(darkgreen);
            else if(colorString.equals("lgreen"))
                graphic.setColor(lgreen);
            else if(colorString.equals("brown"))
                graphic.setColor(brown);
            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 all 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);
            }
        }
    
    }
    
    



    • Kelas 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(int x, int y, String cl, int h, int w)
        {
            height = h;
            width = w;
            xPosition = x;
            yPosition = y;
            color = cl;
            isVisible = true;
            draw();
        }
    
        /**
         * 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);
            }
        }
    }
    
    



    • Kelas 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(int x,int y, String cl, int di)
        {
            diameter = di;
            xPosition = x;
            yPosition = y;
            color = cl;
            isVisible = true;
            draw();
        }
    
        /**
         * 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);
            }
        }
    }
    
    



    • Kelas 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 height, width;
        private int xPosition;
        private int yPosition;
        private String color;
        private boolean isVisible;
    
        /**
         * Create a new square at default position with default color.
         */
        public Square(int x,int y, String cl,int h, int w)
        {
            height = h;
            width = w;
            xPosition = x;
            yPosition = y;
            color = cl;
            isVisible = true;
            draw();
        }
    
        /**
         * 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, width, height));
                canvas.wait(10);
            }
        }
    
        /*
         * Erase the square on screen.
         */
        private void erase()
        {
            if(isVisible) {
                Canvas canvas = Canvas.getCanvas();
                canvas.erase(this);
            }
        }
    }
    
    



    • Kelas Picture:

    
    /**
     * Picture
     *
     * Yasinta
     * 9/13/2018
     */
    public class Picture
    {
        private Circle bukit;
        private Circle matahari;
        private Square tanah;
        private Square langit;
        private Square pagar;
        private Triangle batang;
        private Square tembok;
        private Square jendela;
        private Square pintu;
        private Triangle atap;
        private Circle daun;
        private Circle awan1;
        private Circle awan2;
        private Circle awan3;
        
        public void draw()
        {
            langit = new Square(0,0,"cyan", 600,600);
            matahari = new Circle(300,120,"yellow",100);
            bukit = new Circle(60,280,"dgreen",500);
            bukit = new Circle(-100,270,"green",500);
            tanah = new Square(0,300,"green",300,600);
            for(int i=0;i<=600;i+=35) pagar = new Square(i,310,"brown", 40,15);
            pagar = new Square(0,330,"brown", 10,600);
            awan1 = new Circle(0,10,"white",80);
            awan2 = new Circle(40,0,"white",100);
            awan3 = new Circle(100,10,"white",80);
            awan1 = new Circle(100,10,"lgray",80);
            awan2 = new Circle(140,0,"lgray",100);
            awan3 = new Circle(200,10,"lgray",80);
            awan1 = new Circle(60,60,"white",80);
            awan2 = new Circle(100,70,"lgray",100);
            awan3 = new Circle(160,60,"lgray",80);
            awan1 = new Circle(400,10,"white",80);
            awan2 = new Circle(440,0,"white",100);
            awan3 = new Circle(500,10,"white",80);
            tembok = new Square(380,350,"orange",150,140);
            pintu = new Square(450,400,"brown",90,50);
            jendela = new Square(400,400,"white",30,30);
            atap = new Triangle(450,270,"red",100,200);
            daun = new Circle(130,320,"dgreen",80);
            daun = new Circle(100,280,"dgreen",100);
            daun = new Circle(150,350,"dgreen",80);
            daun = new Circle(100,320,"lgreen",100);
            daun = new Circle(60,330,"lgreen",120);
            batang = new Triangle(150,380,"brown",150,50);
        }
    }
    
    

    Minggu, 09 September 2018

    TUGAS 2 PBO
    Perkenalan Class dan Object

    Pada pertemuan kali ini kami belajar ,mengenai class dan object dalam sebuat pemrograman berorientasi objek. Secara sederhana class di misalkan sebuat toples dan oject dimisalkan banyak benda seperti pensil, pulpen, dan penggaris di dalamnya.

    Tugas dalam pertemuan kali ini adalah membuat metode, luas permukaan, dan volume dari;
    1. Kubus
    2. Balok
    3. Tabung
    4. Bola
    Berikut merupakan contoh output dari program yang saya buat :


    Class :


    Source Code dari tiap classnya 
    • Kubus
    
    /**
     * Program implementasi dengan field luas permukaan dan volume Kubus
     *
     * Yasinta Yusniawati
     * 10 Sepetember 2018
     */
    public class kubus
    {
        public double s; //sisi
        
        //cara return luas permukaan dan volume kubus
        public double lp(){
            return 6 * s * s;
        }
        public double vol(){
            return s * s * s;
        }
    }
        
    

    • Balok
    
    /**
     * Program implementasi dengan field luas permukaan dan volume Balok
     *
     * Yasinta Yusniawati
     * 10 Seb 2018
     */
    public class balok
    {
        public double p, l, t; //panjang lebar tinggi
        
        //cara return luas permukaan dan volume kubus
        public double lp(){ // luas permukaan
            return (2 * (p*l + p*t + l*t));
        }
        public double vol(){ //vo
            return p * l * t;
        }
    }
        
    

    • Tabung
    
    /**
     * Program implementasi dengan field luas permukaan dan volume Tabung
     *
     * Yasinta Yusniawati
     * 10 Seb 2018
     */
    public class tabung
    {
       public double r ; //jari-jari
       public double t; //tinggi
       
       //cara return luas permukaan dan volume kubus
        public double lp(){ // luas permukaan
            return (2 * 3.14 * r * r) + (2 * 3.14 * r * t);
       }
        public double vol(){ //volume
            return 3.14 * r * r * t;
        }
    }
    
    

    • Bola
    
    /**
     * Program implementasi dengan field luas permukaan dan volume Tabung
     *
     * Yasinta Yusniawati
     * 10 Seb 2018
     */
    public class bola
    {
       public double r ; //jari-jari
       
       //cara return luas permukaan dan volume kubus
        public double lp(){ // luas permukaan
            return 4 * 3.14 * r * r;
       }
        public double vol(){ //volume
            return (4/3) * 3.14 * r * r * r;
        }
    }
    


    Fungsi main :

    
    /**
     * Fungsi main dari luas permukaan dan volume dari Kubus, Balok, Tabung, dan Bola
     *
     * @author (Yasinta Yusniawati)
     * @version (10 Sep 2018)
     */
    public class main
    {
        public static void main(String arg[])
        {
         //KUBUS
         kubus cube; // membuat interface 
         cube   = new kubus();
         cube.s = 5;
         
         double Lp  = cube.lp();
         double V   = cube.vol();
         // output
         System.out.println("Program implementasi dengan field luas permukaan dan volume Kubus");
         System.out.println();
         System.out.println("Sisi           = " + cube.s);
         System.out.println("Luas permukaan = " + Lp);
         System.out.println("Volume         = " + V);
         System.out.println("=================================================================");
        
         //BALOK
         balok block; // membuat interface 
         block     = new balok();
         block.p   = 3;
         block.l   = 6;
         block.t   = 10;
         double lp = block.lp();
         double v  = block.vol();
         //output
         System.out.println("Program implementasi dengan field luas permukaan dan volume Balok");
         System.out.println();
         System.out.println("Panjang        = " + block.p);
         System.out.println("Lebar          = " + block.l);
         System.out.println("Tinggi         = " + block.t);
         System.out.println("Luas permukaan = " + lp);
         System.out.println("Volume         = " + v);
         System.out.println("=================================================================");
         
         //TABUNG
         tabung tube; // membuat interface
         tube       = new tabung();
         tube.r     = 7;
         tube.t     = 8;
         double LP  = tube.lp();
         double vol = tube.vol();
         //output
         System.out.println("Program implementasi dengan field luas permukaan dan volume Tabung");
         System.out.println();
         System.out.println("Jari-jari      = " + tube.r);
         System.out.println("Tinggi         = " + tube.t);
         System.out.println("Luas permukaan = " + LP);
         System.out.println("Volume         = " + vol);
         System.out.println("=================================================================");
         
         //BOLA
         bola ball;
         ball       = new bola();
         ball.r     = 14;
         double Lpr = ball.lp();
         double Vol = ball.vol();
         //output
         System.out.println("Program implementasi dengan field luas permukaan dan volume Bola");
         System.out.println();
         System.out.println("Jari-jari      = " + ball.r);
         System.out.println("Luas permukaan = " + Lpr);
         System.out.println("Volume         = " + Vol);
         System.out.println("=================================================================");
        }
    }
    
    

    Minggu, 02 September 2018

    PBOB-Tugas1

    PBO-Tugas 1

    Senin, 3 September 2018

    • Berikut adalah class di Bluej :





    • Source Code:

     /**  
      * Write a description of class PBOBTugas1 here.  
      *  
      * @author Yasinta Yusniawati  
      * @version 03 September 2018  
      */  
     public class PBOBTugas1  
     {  
       // instance variables - replace the example below with your own  
       private int x;  
       /**  
        * Constructor for objects of class PBOBTugas1  
        */  
       public PBOBTugas1()  
       {  
         // initialise instance variables  
         System.out.println("Tugas #PBOB-Tugas1");  
         System.out.println("---------------------------------------------------------");  
         System.out.println("Nama\t\t: Yasinta Yusniawati");  
         System.out.println("Kelas\t\t: PBO B");  
         System.out.println("Alamat Rumah\t: Jl. Purworejo-Jogja, Purwodadi, Purworejo");  
         System.out.println("Email\t\t: yasintayusniawati104@gmail.com");  
         System.out.println("Blog\t\t: yasintayusniawati.blogspot.com");  
         System.out.println("No HP/WA\t: 0852 8884 1109");  
         System.out.println("Twitter\t\t: @yasintayusnia");  
       }  
       /**  
        * 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;  
       }  
     }  
    


    • Hasil Akhir :


    Tugas APSI - C

    USE CASE Analisa Use Case adalah teknik yang digunakan untuk mengidentifikasi kebutuhan sistem perangkat lunak dengan menggambarkan akt...