Minggu, 30 September 2018

Membuat jam digital dan GUI

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PBO A

source code Clock Display
 
 /**  
  * Write a description of class ClockDisplay here.  
  * Program membuat jam digital  
  * @author (Hafidz Firman Asqalany)  
  * @version (4.1.3)  
  */  
 public class ClockDisplay  
 {  
   private NumberDisplay hours;  
   private NumberDisplay minutes;  
   private String displayString;// menstimulasi tampilan sebenarnya  
   /** perintah untuk objek clockDisplay   
    * perintah ini untuk membuat set jam baru pada pukul 00.00  
    */  
   public ClockDisplay()  
   {  
     hours = new NumberDisplay(24);  
     minutes = new NumberDisplay(60);  
     updateDisplay();  
   }  
   /**  
    * Perintah untuk objek ClockDisplay   
    * Perintah ini untuk membuat waktu baru   
    * pada spesifikasi oleh parameter  
   */  
   public ClockDisplay (int hour, int minute)  
   {  
     hours = new NumberDisplay(24);  
     minutes = new NumberDisplay(60);  
     setTime(hour, minute);  
   }  
   /**  
    * Perintah ini harus dipanggil setiap menit  
    * perintah ini untuk membuat tampilan jam   
    * menjadi satu menit kedepan  
   */  
   public void timeTick()  
   {  
     minutes.increment();  
     if(minutes.getValue() == 0) {  
       hours.increment();  
     }  
     updateDisplay();  
   }  
   /**  
    * untuk mengatur waktu pada tampilan  
    * pada jam dan menit secara spesifik  
   */  
   public void setTime(int hour, int minute)  
   {  
     hours.setValue(hour);  
     minutes.setValue(minute);  
     updateDisplay();  
   }  
   /**  
    * mengembalikan pada waktu saat ini pada format yaitu  
    * HH:MM  
   */  
   public String getTime()  
   {  
     return displayString;  
   }  
   /**  
    * mengupdate pada internal string yang direpresentasikan  
    * oleh display  
   */  
   private void updateDisplay ()  
   {  
     int hour = hours.getValue();  
     displayString = hours.getDisplayValue () + ":" +   
             minutes.getDisplayValue();  
   }  
 }  

source code NumberDisplay

 /**  
  * Write a description of class ClockDisplay here.  
  * Program membuat jam digital  
  * @author (Hafidz Firman Asqalany)  
  * @version (4.1.3)  
  */  
 public class NumberDisplay  
 {  
   private int limit;  
   private int value;  
   /**  
    * Constructor for objects of class NumberDisplay  
    */  
   public NumberDisplay(int rollOverlimit)  
   {  
     limit = rollOverlimit;  
     value = 0;  
   }  
   public int getValue()  
   {  
     return value;  
   }  
   /**  
    * Atur nilai tampilan ke nilai yang ditentukan yang baru.   
    * Jika nilai baru kurang dari nol atau melebihi batas  
    * Jangan melakukan apa-apa  
    */  
   public void setValue(int replacementValue)  
   {  
     if((replacementValue >= 0) &&   
       (replacementValue < limit))  
     {  
       value = replacementValue;  
     }  
   }  
   /**  
    * Kembalikan nilai tampilan (yaitu, nilai saat ini sebagai String dua digit.   
    * Jika nilainya kurang dari sepuluh, itu akan mudah dengan nol terkemuka)  
    */  
   public String getDisplayValue()  
   {  
     if(value < 10)  
     {  
       return "0" + value;  
     }  
     else  
     {  
       return "" + value;  
     }  
   }  
   /**    
   * Menaikkan nilai tampilan dengan satu dan dinaikkan menjadi nol  
   * jika batas tercapai  
   */  
   public void increment ()  
   {  
     value = (value +1) % limit;  
   }  
 }  

source code TestClockDisplay

 /**  
  * Write a description of class ClockDisplay here.  
  * Program membuat jam digital  
  * @author (Hafidz Firman Asqalany)  
  * @version (4.1.3)  
  */  
 public class TestClockDisplay  
  {  
   public void test()  
   {  
     ClockDisplay clock = new ClockDisplay();  
     clock.setTime(17,45);  
     System.out.println(clock.getTime());  
     clock.setTime(00,15);  
     System.out.println(clock.getTime());  
     clock.setTime(15,00);  
     System.out.println(clock.getTime());  
   }  
  }   

source code GUI

 /**  
  * Write a description of class ClockDisplay here.  
  * Program membuat jam digital  
  * @author (Hafidz Firman Asqalany)  
  * @version (4.1.3)  
  */   
 import java.awt.*;   
  import java.awt.event.*;   
  import javax.swing.*;   
  import javax.swing.border.*;   
  public class ClockGUI   
  {   
   private JFrame frame;   
   private JLabel label;   
   private ClockDisplay clock;   
   private boolean clockOn = false;   
   private TimerThread timerThread;   
   //fungsi untuk membuat sebuah objek dari class Clock   
   public void Clock()   
   {   
    makeFrame();   
    clock = new ClockDisplay();   
   }   
   //fungsi untuk memulai jam.   
   private void start()   
   {   
    clockOn = true;   
    timerThread = new TimerThread();   
    timerThread.start();   
   }   
   //fungsi untuk memberhentikan jam.   
   private void stop()   
   {   
    clockOn = false;   
   }   
   //fungsi untuk menjalankan jam secara perlahan (naik per menitnya).   
   private void step()   
   {   
    clock.timeTick();   
    label.setText(clock.getTime());   
   }   
   //fungsi untuk menampilkan program Clock ini.   
   private void showAbout()   
   {   
    JOptionPane.showMessageDialog (frame, "Clock Version 0.1\n" +    
    "Membuat jam digital simpel dengan Java.",   
    "About Clock",   
    JOptionPane.INFORMATION_MESSAGE);   
   }   
   //fungsi untuk keluar dari program.   
   private void quit()   
   {   
    System.exit(0);   
   }   
   //fungsi untuk membuat frame dan konten di dalamnya.   
   private void makeFrame()   
   {   
    frame = new JFrame("Clock");   
    JPanel contentPane = (JPanel)frame.getContentPane();   
    contentPane.setBorder(new EmptyBorder(1,60,1,60));   
    makeMenuBar(frame);   
    //secara spesifik mengatur tampilan dengan jarak.   
    contentPane.setLayout(new BorderLayout(12,12));   
    //membuat tampilan di tengah frame.   
    label = new JLabel("00:00", SwingConstants.CENTER);   
    Font displayFont = label.getFont().deriveFont(96.0f);   
    label.setFont(displayFont);   
    contentPane.add(label, BorderLayout.CENTER);   
    //membuat toolbar dengan tombol   
    JPanel toolbar = new JPanel();   
    toolbar.setLayout(new GridLayout(1,0));   
    //membuat tombol Start untuk memulai jam.   
    JButton startButton = new JButton("Start");   
    startButton.addActionListener(e->start());   
    toolbar.add(startButton);   
    //membuat tombol Stop untuk menghentikan jam.   
    JButton stopButton = new JButton("Stop");   
    stopButton.addActionListener(e->stop());   
    toolbar.add(stopButton);   
    //membuat tombol Step untuk menambah 1 menit pada jam.   
    JButton stepButton = new JButton("Step");   
    stepButton.addActionListener(e->step());   
    toolbar.add(stepButton);   
    //untuk memasukkan toolbar ke dalam panel disertai dengan jarak   
    JPanel flow = new JPanel();   
    flow.add(toolbar);   
    contentPane.add(flow, BorderLayout.SOUTH);   
    //menandakan bahwa frame sudah selesai - mengatur komponen di dalamnya   
    frame.pack();   
    //memposisikan frame di tengah layar serta menampilkannya   
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();   
    frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);   
    frame.setVisible(true);   
   }   
   //fungsi yang membuat menubar di frame utama   
   private void makeMenuBar(JFrame frame)   
   {   
    final int SHORTCUT_MASK =    
    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();   
    JMenuBar menubar = new JMenuBar();   
    frame.setJMenuBar(menubar);   
    JMenu menu;   
    JMenuItem item;   
    //membuat file menu   
    menu = new JMenu("File");   
    menubar.add(menu);   
    item = new JMenuItem("About Clock...");   
     item.addActionListener(e->showAbout());   
    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   
   {   
    //fungsi saat jam sedang dijalankan.   
    public void run()   
     {   
      //selama jam jalan, maka akan dilakukan Step(menambah nilai setiap menitnya).   
      //pause (berhenti selama beberapa saat sehingga nilai sekarang dapat terlihat.   
      while(clockOn)   
      {   
       step();   
       pause();   
      }   
     }   
     private void pause()   
     {   
      try    
      {   
       Thread.sleep(900);   
      }   
      catch(InterruptedException exc)   
      {   
      }   
    }   
   }   
  }   

dan ini merupakan hasil programnya



Selasa, 25 September 2018

Membuat Web Berita

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB C

Source Code html :

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Tugas berita Hafidz Firman Asqalany</title>  
   <link rel="stylesheet" href="index.css"/>  
 <style type="text/css">  
      .left  { text-align: left;}  
      .right  { text-align: right;}  
      .center { text-align: center;}  
      .justify { text-align: justify;}  
 </style>  
 </head>  
 <body>  
   <div class="header">  
     <div class="jarak">  
       <h2>Get Exclusive News In Here</h2>  
     </div>  
   </div>  
 <div class="menu">  
   <ul>  
     <Li><a href="#">Home</a></Li>  
     <Li><a href="#">Trending</a></Li>  
     <Li><a href="#">Contact</a></Li>  
   </ul>  
 </div>  
  <div class="content">  
  <div class="jarak">  
   <!-- kiri -->  
   <div class="kiri">  
   <!-- blog -->  
   <div class="border">  
   <div class="jarak">  
      <h3>Amazon Siap Ekspansi ke Indonesia, Janjikan Investasi hingga Rp14 Triliun</h3>  
   <p class="justify"> <img src="amazon-ilustrasi.jpg" alt="amazon-ilustrasi" height="125px" width="125px" align="left" border="3"/>  
   Pada 21 September 2018, Vice President Amazon Werner Vogels bersama Menteri Keuangan Indonesia Sri Mulyani Indrawati bertemu Presiden Indonesia Joko Widodo di Istana Kepresidenan.  
   Pihak Amazon mengungkapkan rencana mereka untuk melakukan investasi di Indonesia dengan besaran hingga Rp14 triliun dalam jangka waktu sepuluh tahun ke depan.  
  </p>  
   <button class="btn"><a href="https://id.techinasia.com/amazon-ekspansi-indonesia">Read More</a></button>  
   </div>  
  </div>  
  <!-- end blog-->  
  <!-- blog -->  
   <div class="border">  
   <div class="jarak">  
   <h3>Miliarder Teknologi Asal Jepang Jadi Turis Luar Angkasa Pertama Space X</h3>  
   <p class="justify"> <img src="pexels-photo-2.jpg" alt="pexels-photo-2" height="125px" width="125px" align="left" border="3"/>  
   Perusahan milik Elon Musk, Space X, resmi mengumumkan penumpang pertama yang telah “membeli tiket” terbang ke bulan.  
   Penumpang tersebut miliarder asal Jepang sekaligus bos bisnis pakaian online Zozotown, Yusaku Maezawa, yang saat ini berusia 42 tahun.  
   Perjalanan ke bulan ini rencananya akan berlangsung pada tahun 2023 dengan menggunakan roket Space X bernama Big Falcon Rocket (BFR).  
 </p>  
   <button class="btn"><a href="https://id.techinasia.com/penumpang-luar-angkasa-pertama-space-x?ref=related&pos=1">Read More</a></button>  
   </div>  
  </div>  
  <!-- end blog-->  
  <!-- blog -->  
   <div class="border">  
   <div class="jarak">  
   <h3>Facebook Luncurkan Platform Video Facebook Watch secara Global.</h3>  
   <p class="justify"> <img src="Facebook-Watch-Featured-Image.png" alt="Facebook-Watch-Featured-Image" height="125px" width="125px" align="left" border="3"/>  
   Pada 29 Agustus 2018, Facebook mengumumkan bahwa layanan streaming video mereka, Facebook Watch, telah diluncurkan secara global. Layanan ini merupakan desain baru tab Video yang sebelumnya telah tersedia di aplikasi Facebook.  
   Watch pertama kali diumumkan pada 9 Agustus 2017 dan diluncurkan secara berkala di Amerika Serikat selama beberapa minggu setelahnya.  
   Selain menyiarkan konten video dari halaman-halaman yang kamu ikuti, Watch juga akan menyiarkan konten orisinal buatan kreator dan penerbit yang bermitra dengan Facebook seperti Nas Daily dan Tastemade.  
 </p>  
   <button class="btn"><a href="https://id.techinasia.com/facebook-watch-global">Read More</a></button>  
   </div>  
  </div>  
  <!-- end blog-->  
  </div>  
 <!--kiri-->  
  <!-- kanan-->  
  <div class="kanan">  
  <div class="jarak">  
       <h3>Check some other newspage!</h3>  
   <hr/>  
   <p><a href="techinasia.com" class="undercor">TechInAsia</a></p>  
   <p><a href="cnn.com" class="undercor">CNN</a></p>  
   <p><a href="channelnewsasia.com" class="undercor">ChannelNewsAsia</a></p>  
   <p><a href="telegraph.co.uk" class="undercor">Telegraph</a></p>  
   <p><a href="bbc.com/news" class="undercor">BBC News</a></p>  
   </div>  
  </div>  
  <!--kanan-->  
  </div>  
  </div>  
   <div class="footer">  
   <div class="jarak">  
   <p>copyright 2018 HafidzAsqalany28 all reserved</p>  
  </div>  
  </div>  
 </body>  
 </html>  

Source Code CSS :

 body  
 {  
      background:#FFFAF0;  
   color:#333;  
   width:100%;  
   font-family:sans-serif;  
   margin:0 auto;  
 }  
 header  
 {  
      width:90%;  
   margin:auto;  
   height:auto;  
   height:12px;  
   line-height:120px;  
   background:##00CED1;  
   color:#fff;  
 }  
 .content  
 {  
      width:70%;  
      margin:auto;  
      height:1000px;  
      padding:0.1px;  
      background:#fff;  
      color:#333;  
 }  
 .kiri  
 {  
      width:70%;  
   float:left;  
   margin:auto;  
   background:#fff;  
   height:420px;  
 }  
 .kanan  
 {  
      width:30%;  
   float:left;  
   margin:auto;  
   background:#fff;  
   height:420px;  
 }  
 .border  
 {  
      border:2px solid #DCDCDC;  
   margin-top:1pc;  
   padding-bottom:1pc;  
   padding-left:2pc;  
   padding-right:2pc;  
 }  
 .undercor  
 {  
      text-decoration:none;  
 }  
  .footer  
  {   
       width:70%   
       margin:auto;   
       height:100px;   
       line-height:40px;   
       background:#00CED1;   
       color:#fff;   
  }   
  .menu  
  {   
       background-color : #00CED1;   
       height:50px;   
       line-height:50px;   
       position:relative;   
       width:90%;   
       margin:0 auto;   
       padding:0 auto;   
  }   
  .jarak  
  {   
       padding:0 3pc;   
  }  
  .menu ul  
 {   
       list-style:none;   
 }   
  .menu ul li a  
  {   
       float:left;   
       width:70px;   
       display:block;   
       text-align:center;   
       color:#FFF;   
       text-decoration:none;   
  }  
  .menu ul li a:hover   
  {   
       background-color:#0000CD;   
       display:block;   
  }   

Dan ini adalah hasil dari Source Code diatas :

Minggu, 23 September 2018

Membuat Program Remot AC

Nama  = Hafidz Firman Asqalany
Kelas  = PBO A
NRP   = 05111740000195

Kali ini saya disuruh membuat program remote tv menggunakan blue j. dan disini saya akan menunjukkan kodingan saya kepada anda kalian. tanpa basa-basi langsung saja saya tampilkan.

source code Remote AC:

 /**  
  * Program membuat Remote AC.  
  *  
  * @author (Hafidz Firman Asqalany)  
  * @version (1.0)  
  */  
 public class RemoteAC  
 {  
   public boolean power;  
   public int temp;  
   public int mode;  
   public int swing;  
   public RemoteAC(int tempnow)  
   {  
     power =true;  
     temp =tempnow;  
     mode =1;  
     swing =1;   
   }  
   public void modeAC(int modesekarang)  
   {  
     if(mode==1)  
     {  
       System.out.println("Mode sekarang : Otomatis");  
     }  
     else if(mode==2)  
     {  
       System.out.println("Mode sekarang : Cool");  
     }  
     else if(mode==3)  
     {  
       System.out.println("Mode sekarang : Dry");  
     }  
     else if(mode==4)  
     {  
       System.out.println("Mode sekarang : Fan");  
     }  
   }  
   public void Mode(int modesekarang)  
   {  
     modeAC(modesekarang);  
     System.out.println("Pilih mode yang anda inginkan :");  
     System.out.println("1. Otomatis");  
     System.out.println("2. Cool");  
     System.out.println("3. Dry ");  
     System.out.println("4. Fan");  
   }  
   public int ModeIngin(int modepilihan)  
   {  
     if(modepilihan ==1)  
     {  
       mode= modepilihan;  
       System.out.println("Mode yang anda inginkan berhasil! Mode sekarang : Otomatis ");  
     }  
     else if(modepilihan ==2)  
     {  
       mode= modepilihan;  
       System.out.println("Mode yang anda inginkan berhasil! Mode sekarang : Cool ");  
     }  
     else if(modepilihan ==3)  
     {  
       mode= modepilihan;  
       System.out.println("Mode yang anda inginkan berhasil! Mode sekarang : Dry ");  
     }  
     else if(modepilihan ==4)  
     {  
       mode= modepilihan;  
       System.out.println("Mode yang anda inginkan berhasil! Mode sekarang : Fan ");  
     }  
     return(mode);  
   }  
   public void tempratur(int tempsekarang)   
   {   
     System.out.println("Tempratur Sekarang :"+tempsekarang);   
     System.out.println("1. Naik");   
     System.out.println("2. Turun");   
   }   
   public int tempraturNaik(int naik)   
   {   
     if(naik>=30)    
     {  
     }   
     else   
     {   
       naik++;   
     }   
     return(naik);   
   }   
   public int tempraturTurun(int turun)   
   {   
     if(turun<=16)   
     {   
     }   
     else   
     {     
       turun--;   
     }   
     return(turun);   
   }   
 }  

Dan ini merupakan Source code main nya:

 /**  
  * program membuat remote AC.  
  *  
  * @author (Hafidz Firman Asqalany)  
  * @version (1.0)  
  */  
 import java.util.Scanner;  
 public class main  
 {  
   public static void main(String args[])  
   {  
     System.out.print('\u000C');  
     System.out.println("Atur tempratur yang anda inginkan:");  
     Scanner scan= new Scanner(System.in);  
     int tempawal;  
     int tempvalue;  
     int modevalue;  
     int menu;  
     boolean cek;  
     int sementara, smntr,modeAC,smntr1;  
     tempawal=scan.nextInt();  
     if(tempawal>=16 && tempawal<=30)  
     {  
       RemoteAC remAC= new RemoteAC(tempawal);  
       modeAC= remAC.mode;  
       while(true)  
       {  
         System.out.print('\u000C');   
         System.out.println("Haier AC");   
         System.out.println("Tempratur : "+tempawal);   
         remAC.modeAC(modeAC);    
         System.out.println("Menu");   
         System.out.println("1. Ubah Tempratur");    
         System.out.println("2. Ubah Mode");    
         System.out.println("3. Matikan AC");   
         System.out.println("------------------------------");   
         menu = scan.nextInt();   
         System.out.print('\u000C');   
         if(menu==1)   
         {   
           System.out.println("Haier AC");  
           System.out.println("Tempratur : "+tempawal);   
           remAC.modeAC(modeAC);  
           remAC.tempratur(tempawal);   
           System.out.println("------------------------------------");   
           tempvalue = scan.nextInt();   
           if(tempvalue==1)   
           {   
             sementara = remAC.tempraturNaik(tempawal);   
             tempawal = sementara;   
           }   
           else if(tempvalue==2)   
           {   
             sementara = remAC.tempraturTurun(tempawal);   
             tempawal = sementara;   
           }   
           System.out.print('\u000C');   
         }   
         else if(menu==2)   
         {  
           System.out.println("Haier AC");   
           System.out.println("Tempratur : "+tempawal);   
           remAC.modeAC(modeAC);   
           remAC.Mode(modeAC);   
           modevalue = scan.nextInt();   
           smntr=remAC.ModeIngin(modevalue);   
           modeAC = smntr;   
           System.out.print('\u000C');   
         }   
         else if(menu==4)   
         {    
           System.out.print('\u000C');   
           break;   
         }         
         }  
     }  
     else   
     {   
       System.out.println("Temperatur AC hanya bisa dari 16-30");   
     }   
   }    
 }  

jika kita compile program di atas maka akan seperti begini programnya :



seperti yang anda lihat saya ingin membuat temprature AC menjadi 24 maka program yang akan dihasilkan :


jika kalian ingin menaikkan suhu tempratur AC maka pilihlah menu 1 :




jika ingin mengganti mode AC maka pilihlah menu 2 :



Rabu, 19 September 2018

Belajar Mempercantik web dari HTML menggunakan CSS

Kali ini saya disuruh membuat WEB menggunakan HTML.



berikut source code HTML nya :

 <!DOCTYPE html>   
  <html>   
  <head>   
   <title>Belajar Membuat layout dengan HTML dan CSS</title>   
   <link rel="stylesheet" href="Tugas1.css"/>   
  </head>   
  <body>   
   <div class="header">   
    <div class="jarak">   
     <h2>Belajar Membuat Layout dengan HTML dan CSS</h2>   
    </div>   
   </div>   
   <div class="menu">   
    <ul>   
     <li><a href="#">Home</a></li>   
     <li><a href="#">About</a></li>   
     <li><a href="#">Blog</a></li>   
     <li><a href="#">Contact</a></li>   
    </ul>   
   </div>   
   <div class="content">   
    <div class="jarak">   
     <div class="kiri">   
      <div class="border">   
       <div class="jarak">   
        <h3>Lorem Ipsum</h3>   
        <p>Lorem Ipsum is simply dumy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> <button class="btn">Read More ..</button>   
       </div>   
      </div>   
      <div class="border">   
       <div class="jarak">   
        <h3>Lorem Ipsum</h3>   
        <p>Lorem Ipsum is simply dumy text of the printing and typesetting industry. Lorep Ipsum has been the industry's standard dummy text ever since the 1500s.</p> <button class="btn">Read More ..</button>   
       </div>   
      </div>   
     </div>   
     <div class="kanan">   
      <div class="jarak">   
       <h3>CATEGORY</h3>   
       <hr/>   
       <p><a href="#" class="undecor">HTML</a></p>   
       <p><a href="#" class="undecor">CSS</a></p>   
       <p><a href="#" class="undecor">BOOTSTRAP</a></p>   
       <p><a href="#" class="undecor">PHP</a></p>   
       <p><a href="#" class="undecor">MYSQL</a></p>   
       <p><a href="#" class="undecor">Jquery</a></p>   
       <p><a href="#" class="undecor">Ajax</a></p>   
      </div>   
     </div>   
    </div>   
   </div>   
   <div class="footer">   
    <div class="jarak">   
     <p>copyright 2017 codebareng all reserved</p>   
    </div>   
   </div>   
  </body>   
  </html>   

Dan ini Source code CSS nya :

 body {   
   background: #FFFFFF;   
   color:#333;   
   width:100%;   
   font-family:sans-serif;   
   margin:0 auto;   
  }   
  .header {   
   width: 90%   
   margin:auto;   
   height:120px;   
   line-height: 120px;   
   background: #40E0D0;   
   color: #FFFFFF;   
  }   
  .content {   
   width: 90%;   
   margin: auto;   
   height: 420px;   
   padding: 0.1px;   
   background: #fff;   
   color:#000000;   
  }   
  .kiri {   
   width:70%;   
   float: left;   
   margin:auto;   
   background: #fff;   
   height:420px;   
  }   
  .kanan {   
   width:30%;   
   float: left;   
   margin:auto;   
   background:#fff;   
   height:420px;   
  }   
  .border {   
   border:2px solid #74C599;   
   margin-top: 1pc;   
   padding-bottom: 1pc;   
   padding-left: 2pc;   
   padding-right: 2pc;   
  }   
  .undecor {   
   text-decoration: none;   
  }   
  .footer {   
   width: 90%;   
   margin: auto;   
   height:40px;   
   line-height: 40px;   
   background: #40E0D0;   
   color: #fff;   
  }   
  .menu {  
   background-color:#40E0D0;   
   height: 50px;   
   line-height: 50px;   
   position: relative;   
   width:90%;   
   margin: 0 auto;   
   padding: 0 auto;   
  }   
  .jarak {   
   padding: 0 2pc;   
  }   
  .menu ul {   
   list-style: none;   
  }   
  .menu ul li a {   
   float: left;   
   width:70px;   
   display:block;   
   text-align: center;   
   color:#FFF;   
   text-decoration: none;   
  }   
  .menu ul li a :hover {   
   background-color: #40E0D0;   
   display: block;   
  }   

Minggu, 16 September 2018

Membuat aplikasi mesin tiket kereta api

PBO-A

Source Code :

 import java.util.Scanner;  
 /**  
  * Write a description of class TicketMachine here.  
  *  
  * @author (Hafidz Firman A.)  
  * @version (17092018)  
  */  
 public class TicketMachine  
 {  
   private int price;  
   private int balance;  
   private int total;  
   public TicketMachine(int cost)  
   {  
     price = cost;  
     balance = 0;  
     total = 0;  
   }  
   /**  
    * @Return The price of a ticket.  
    */  
   public int getPrice()  
   {  
     return price;  
   }  
   public int getBalance()  
   {  
     return balance;  
   }  
   public void insertMoney(int amount)  
   {  
     if(amount > 0) {  
       balance = balance + amount;  
     }  
     else {  
       System.out.println("Use a positive amount rather than: " +  
                 amount);  
     }  
   }  
   public void printTicket()  
   {  
     if(balance >= price) {  
       // Simulate the printing of a ticket.  
       System.out.println("##################");  
       System.out.println("# The BlueJ Line");  
       System.out.println("# Ticket");  
       System.out.println("# " + price + " cents.");  
       System.out.println("##################");  
       System.out.println();  
       // Update the total collected with the price.  
       total = total + price;  
       // Reduce the balance by the prince.  
       balance = balance - price;  
     }  
     else {  
       System.out.println("You must insert at least: " +  
                 (price - balance) + " more cents.");  
     }  
   }  
   public int refundBalance()  
   {  
     int amountToRefund;  
     amountToRefund = balance;  
     balance = 0;  
     return amountToRefund;  
   }  
   public static void main(String args[]){   
     Scanner scan= new Scanner(System.in);   
     int cost, menu;  
     boolean entry;  
     System.out.println("Masukkan harga tiket \n");   
     cost = scan.nextInt();  
     TicketMachine ticket = new TicketMachine(cost);  
     entry = true;  
     while(entry) {  
       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");  
       menu=scan.nextInt();   
       switch(menu){   
         case 1:   
           cost=ticket.getPrice();   
           System.out.println(cost);  
           break;  
         case 2:   
           ticket.getBalance();  
           break;  
         case 3:   
           int money=scan.nextInt();   
           ticket.insertMoney(money);  
           break;  
         case 4:   
           ticket.printTicket();  
           break;  
         case 5:  
           entry = false;  
           break;  
       }  
     }  
   }  
 }  

output :


Tugas Menggambar PBO-A

TUGAS PBO-A : Membuat Gambar/objek Menggunakan Bangun 2d dengan IDE BlueJ

Disini Saya akan menampilkan source code dan hasil output dari Tugas saya. Langsung saja saya Tampilkan.



Class:

    1. Picture :

 public class Picture   
  {   
   private Box wall;   
   private Box door;   
   private Box window;   
   private Box sky;  
   private Triangle street;   
   private Circle sun;    
   private Box ground;   
   private Box road;   
   private Circle cloud;   
   private Triangle mountain;   
   /**   
   * Constructor for objects of class Picture   
   */   
   public Picture()   
   {   
   // nothing to do... instance variables are automatically set to null   
   }   
   /**   
   * Draw this picture.   
   */   
   public void draw()   
   {   
   sky = new Box();   
   sky.changeColor("cyan");   
   sky.moveHorizontal(-200);   
   sky.moveVertical(-100);   
   sky.changeWidth(1600);   
   sky.changeHeight(1200);   
   sky.makeVisible();  
    sun = new Circle();   
   sun.changeColor("yellow");   
   sun.moveHorizontal(330);   
   sun.moveVertical(10);   
   sun.changeSize(300);   
   sun.makeVisible();  
   ground = new Box();   
   ground.changeColor("brown");   
   ground.moveHorizontal(-200);   
   ground.moveVertical(150);   
   ground.changeWidth(1600);   
   ground.changeHeight(1200);   
   ground.makeVisible();  
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(100);   
   cloud.moveVertical(0);   
   cloud.changeSize(45);   
   cloud.makeVisible();   
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(0);   
   cloud.moveVertical(0);   
   cloud.changeSize(45);   
   cloud.makeVisible();   
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(30);   
   cloud.moveVertical(-20);   
   cloud.changeSize(80);   
   cloud.makeVisible();    
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(720);   
   cloud.moveVertical(0);   
   cloud.changeSize(45);   
   cloud.makeVisible();   
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(815);   
   cloud.moveVertical(0);   
   cloud.changeSize(45);   
   cloud.makeVisible();   
   cloud = new Circle();   
   cloud.changeColor("light blue");   
   cloud.moveHorizontal(750);   
   cloud.moveVertical(-20);   
   cloud.changeSize(80);   
   cloud.makeVisible();  
   mountain = new Triangle();   
   mountain.changeColor("green");   
   mountain.moveHorizontal(220);   
   mountain.moveVertical(10);   
   mountain.changeSize(200, 675);    
   mountain.makeVisible();  
   mountain = new Triangle();   
   mountain.changeColor("green");   
   mountain.moveHorizontal(680);   
   mountain.moveVertical(10);   
   mountain.changeSize(200, 680);    
   mountain.makeVisible();   
   street = new Triangle();   
   street.changeColor("black");   
   street.moveHorizontal(450);   
   street.moveVertical(210);   
   street.changeSize(1000, 1500);    
   street.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(200);   
   ground.changeWidth(5);   
   ground.changeHeight(20);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(240);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(290);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(350);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(410);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(480);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(410);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(470);   
   ground.changeWidth(5);   
   ground.changeHeight(30);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(540);   
   ground.changeWidth(5);   
   ground.changeHeight(40);   
   ground.makeVisible();  
   ground = new Box();   
   ground.changeColor("white");   
   ground.moveHorizontal(440);   
   ground.moveVertical(610);   
   ground.changeWidth(5);   
   ground.changeHeight(40);   
   ground.makeVisible();  
   }   
  }  

     2. Box :

 import java.awt.*;   
  public class Box   
  {   
   private int width;   
   private int height;   
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   /**   
   * Create a new Box at default position with default color.   
   */   
   public Box()   
   {   
   width = 30;   
   height = 30;   
   xPosition = 60;   
   yPosition = 50;   
   color = "red";   
   isVisible = false;   
   }   
   /**   
   * Make this Box visible. If it was already visible, do nothing.   
   */   
   public void makeVisible()   
   {   
   isVisible = true;   
   draw();   
   }   
   /**   
   * Make this Box invisible. If it was already invisible, do nothing.   
   */   
   public void makeInvisible()   
   {   
   erase();   
   isVisible = false;   
   }   
   /**   
   * Move the Box a few pixels to the right.   
   */   
   public void moveRight()   
   {   
   moveHorizontal(20);   
   }   
   /**   
   * Move the Box a few pixels to the left.   
   */   
   public void moveLeft()   
   {   
   moveHorizontal(-20);   
   }   
   /**   
   * Move the Box a few pixels up.   
   */   
   public void moveUp()   
   {   
   moveVertical(-20);   
   }   
   /**   
   * Move the Box a few pixels down.   
   */   
   public void moveDown()   
   {   
   moveVertical(20);   
   }   
   /**   
   * Move the Box horizontally by 'distance' pixels.   
   */   
   public void moveHorizontal(int distance)   
   {   
   erase();   
   xPosition += distance;   
   draw();   
   }   
   /**   
   * Move the Box vertically by 'distance' pixels.   
   */   
   public void moveVertical(int distance)   
   {   
   erase();   
   yPosition += distance;   
   draw();   
   }   
   /**   
   * Slowly move the Box 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 Box 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 width to the new width (in pixels). Width must be >= 0.   
   */   
   public void changeWidth(int newWidth)   
   {   
   erase();   
   width = newWidth;   
   draw();   
   }   
   /**   
   * Change the height to the new height (in pixels). Height must be >= 0.   
   */   
   public void changeHeight(int newHeight)   
   {   
   erase();   
   height = newHeight;   
   draw();   
   }   
   /**   
   * Change the color. Valid colors are "red", "yellow", "blue", "green",   
   * "magenta" and "black".   
   */   
   public void changeColor(String newColor)   
   {   
   color = newColor;   
   draw();   
   }   
   /*   
   * Draw the Box 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 Box on screen.   
   */   
   private void erase()   
   {   
   if(isVisible) {   
      Canvas canvas = Canvas.getCanvas();   
      canvas.erase(this);   
     }   
   }   
  }  

      3. Circle :

 import java.awt.*;   
 import java.awt.geom.*;   
  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 = 20;   
     yPosition = 60;   
     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);   
     }   
   }   
  }  

    4. Triangle :

 import java.awt.*;   
  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 = 50;   
   yPosition = 15;   
   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);   
   }   
   }   
  }  

      5. Canvas :

 import javax.swing.*;   
 import java.awt.*;   
 import java.util.List;   
 import java.util.*;   
  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", 1000, 800, 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 objects;   
   private HashMap 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();   
   shapes = new HashMap();   
   }   
   /**   
   * 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("cyan"))   
    graphic.setColor(Color.cyan);  
   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 if(colorString.equals("light brown"))   
    graphic.setColor(new Color(153,102,0));   
   else if(colorString.equals("brown"))   
    graphic.setColor(new Color(102,51,0));   
   else if(colorString.equals("grey"))   
    graphic.setColor(new Color(190,190,190));   
   else if(colorString.equals("light blue"))   
    graphic.setColor(new Color(0,191,255));   
   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);   
   }   
   }   
  }  
Dan ini Merupakan Hasil Output Dari source code diatas :

Senin, 10 September 2018

PBO A-TUGAS CLASS


Syntax untuk class main nya :
 
 public class main   
  {   
   public static void main(String args[]){   
   triangle segitiga;  segitiga = new triangle();   
   bujursangkar kotak; kotak = new bujursangkar();   
   persegipanjang rectangle; rectangle = new persegipanjang();   
   jajargenjang jajar; jajar = new jajargenjang();   
   belahketupat ketupat;  ketupat = new belahketupat();   
   segitiga.tinggi = 8;   
   segitiga.alas = 5;   
   double luas= segitiga.luas();   
   double keliling = segitiga.keliling();    
   System.out.print("Luas segitiga = "+luas+" keliling = "+keliling);   
   kotak.sisi = 5;   
   int luasb = kotak.luas();   
   int kelilingb = kotak.keliling();   
   System.out.print("\nLuas bujur sangkar = "+luasb+" keliling = "+kelilingb);   
   rectangle.lebar = 10;   
   rectangle.panjang = 4;   
   int luaspp = rectangle.luas();   
   int kelilingpp = rectangle.keliling();   
   System.out.print("\nLuas persegi panjang = "+luaspp+" keliling = "+kelilingpp);   
   jajar.sisi = 10;   
   jajar.tinggi = 6;   
   jajar.sisimiring = 5;   
   int luasj = jajar.luas();   
   int kelilingj = jajar.keliling();   
   System.out.print("\nLuas jajar genjang = "+luasj+" keliling = "+kelilingj);   
   ketupat.diagonal1 = 4;   
   ketupat.diagonal2 = 8;   
   ketupat.sisi = 13;   
   double luasketupat = ketupat.luas();   
   int kelilingketupat = ketupat.keliling();   
   System.out.print("\nLuas belah ketupat = "+luasketupat+" keliling = "+kelilingketupat);   
   }   
  }   

Syntax untuk class triangle nya :

 public class triangle{  
   public int alas;  
   public int tinggi;  
   public double keliling(){  
     return 3*alas;  
   }  
   public double luas(){  
     return 0.5*alas*tinggi;  
   }  
 }  

Syntax untuk class bujursangkar nya :

 public class bujursangkar{  
   public int sisi;  
   public int keliling(){  
     return 4*sisi;  
   }  
   public int luas(){  
     return sisi*sisi;  
   }  
 }  

syntax untuk class persegipanjang nya :

 public class persegipanjang{  
   public int panjang;  
   public int lebar;  
   public int keliling(){  
     return 2*(panjang+lebar);  
   }  
   public int luas(){  
     return panjang*lebar;  
   }  
 }  

syntax untuk class jajargenjang nya :

 public class jajargenjang{  
   public int sisi;  
   public int tinggi;  
   public int sisimiring;  
   public int keliling(){  
     return 2*sisi+2*sisimiring;  
   }  
   public int luas(){  
     return tinggi*sisi;  
   }  
 }  

syntax untuk class belahketupat nya :

 public class belahketupat{  
   public int sisi;  
   public int diagonal1;  
   public int diagonal2;  
   public int keliling(){  
     return 4*sisi;  
   }  
   public double luas(){  
     return 0.5*diagonal1*diagonal2;  
   }  
 }  

Selasa, 04 September 2018

TUGAS 1 - Pemrograman Web
Membuat CV dengan HTML dan CSS
Nama  : Hafidz Firman Asqalany
NRP    : 05111740000195
Kelas   : Pemrograman Web C




berikut ini merupakan source code dari tampilan di atas :


<html>
  <head>
    <title>Curriculum Vitae</title> <!-- Judul pada suatu web-->
  </head>
  <body bgcolor="#E6E6FA" width="800px"> <!-- Membuat body memiliki warna dengan menggunakan bgcolor -->
  <div align="center">
 <!-- Membuat rata tengah-->
    <center>
<h1>
Curriculum Vitae</h1>
<!-- Membuat huruf menjadi besar (Ukuran H1) -->
</center>
<hr />
<h2>
Biodata Diri</h2>
<!-- Membuat huruf menjadi besar (Ukuran H2) -->
<table width="800px"> <!-- Membuat sebuah table -->
<tr>
          <td width="25%">Nama Lengkap</td>
          <td width="1%">:</td>
          <td>Hafidz Firman Asqalany</td>
          <td rowspan="5"><img src="foto_hafidz.jpg" alt="Foto Hafidz" title="Foto Hafidz" height="300px" width="300px"></td>
        </tr>
<tr>
          <td>Jenis Kelamin </td>
          <td>:</td>
          <td>Laki-Laki</td>
        </tr>
<tr>
          <td>Status </td>
          <td>:</td>
          <td>Mahasiswa</td>
        </tr>
<tr>
          <td>Tempat dan Tanggal Lahir </td>
          <td>:</td>
          <td>Merauke, 30 Mei 1999</td>
        </tr>
<tr>
          <td>Alamat</td>
          <td>:</td>
          <td>Jl. Bumi Marina Emas no 21 , Keputih , Surabaya</td>
        </tr>
<tr>
    <td>E-mail</td>
          <td>:</td>
          <td>oneokr33@gmail.com</td>
        </tr>

<tr>
          <td>No.Telp </td>
          <td>:</td>
          <td>085243131373</td>
        </tr>
</tbody>
    </table>
<h2>
Latar Belakang Pendidikan</h2>
<table width="800px">
      <tbody>
<tr>
          <td width="25%">2005-2011</td>
          <td width="1%">:</td>
          <td>SD Yapis 2 Merauke</td>
        </tr>
<tr>
          <td>2011-2014</td>
          <td>:</td>
          <td>SMP Negeri 1 Merauke</td>
        </tr>
<tr>
          <td>2014-2017</td>
          <td>:</td>
          <td>SMA Negeri 1 Merauke</td>
<tr>
          <td>2017-Sekarang</td>
          <td>:</td>
          <td>Institut Teknologi Sepuluh Nopember</td>
        </tr>
</tr>
</table>

<br /><br /> <!-- br untuk membuat baris baru -->
  <a href="penghargaan.html" title="penghargaan"><h2>
penghargaan >> </h2>
</a> <!-- Pergi ke file penghargaan.html  -->
  </div>
</body>
</html> 


 

Minggu, 02 September 2018

PBO A-TUGAS 1




 public class PBO1  
 {  
   public PBO1()  
   {  
     System.out.print(" ==========BIODATA======\n");  
     System.out.print("Nama          : Hafidz Firman Asqalany\n");  
     System.out.print("Kelas         : PBO A\n");  
     System.out.print("Alamat Rumah  : Jl. Bumi Marina Emas no 21, Surabaya\n");  
     System.out.print("Email         : hafidzasqalany28@gmail.com\n");  
     System.out.print("Blog          : HafidzAsqalany28.blogspot.com\n");  
     System.out.print("No HP/WA      : 085243131373\n");  
     System.out.print("Twitter       : @asqalany28\n");  
   }  
 }