├── GridLayoutPane.java ├── Latihan_Inheritance1.java ├── Latihan_Inheritance2.java ├── Latihan_Inheritance3.java ├── Latihan_Inheritance_GUI.java ├── Motorcycle.java ├── Polimorfisme-ayam.java ├── Polimorfisme-hewan.java ├── Polimorfisme-kucing.java ├── Polimorfisme-main.java ├── README.md ├── agunglaksonop-BangunDatar.java ├── calculator.java ├── garlek123.java └── mbul48AngkaRibuan.java /GridLayoutPane.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | 4 | public class GridLayoutPane { 5 | public static void main(String[] args) { 6 | JFrame frame = new JFrame("GridLayoutPane"); 7 | JPanel panel = new JPanel(); 8 | panel.setLayout(new GridLayout(0,3,10,10)); 9 | panel.setPreferredSize(new Dimension(450,150)); 10 | frame.getContentPane().add(panel); 11 | 12 | //add button to desontrate the layout 13 | for (int i = 1; i<= 12; i++) 14 | panel.add(new JButton("Button #"+i)); 15 | 16 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 17 | frame.pack(); 18 | frame.setVisible(true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Latihan_Inheritance1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Bab4; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class Latihan_Inheritance1 { 12 | public String nama, biak, nafas; 13 | /*public void setnama (String nama) 14 | { 15 | this.nama=nama; 16 | } 17 | public String getnama() 18 | { 19 | return nama; 20 | } 21 | public void setbiak(String biak) 22 | { 23 | this.biak=biak; 24 | } 25 | public String getbiak() 26 | { 27 | return biak; 28 | } 29 | public void setnafas(String nafas) 30 | { 31 | this.nafas=nafas; 32 | } 33 | public String getnafas () 34 | { 35 | return nafas; 36 | }*/ 37 | } 38 | -------------------------------------------------------------------------------- /Latihan_Inheritance2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Bab4; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class Latihan_Inheritance2 extends Latihan_Inheritance1 { 12 | Latihan_Inheritance2 () 13 | { 14 | nama="Kelinci"; 15 | biak="Vivipar"; 16 | nafas="Paru-paru"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Latihan_Inheritance3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Bab4; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class Latihan_Inheritance3 extends Latihan_Inheritance1{ 12 | Latihan_Inheritance3 () 13 | { 14 | nama="Ikan Badut"; 15 | biak="Ovipar"; 16 | nafas="Insang"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Latihan_Inheritance_GUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Bab4; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class GUI extends javax.swing.JFrame { 12 | 13 | /** 14 | * Creates new form GUI 15 | */ 16 | public GUI() { 17 | initComponents(); 18 | } 19 | 20 | /** 21 | * This method is called from within the constructor to initialize the form. 22 | * WARNING: Do NOT modify this code. The content of this method is always 23 | * regenerated by the Form Editor. 24 | */ 25 | @SuppressWarnings("unchecked") 26 | // //GEN-BEGIN:initComponents 27 | private void initComponents() { 28 | 29 | jLabel1 = new javax.swing.JLabel(); 30 | jLabel2 = new javax.swing.JLabel(); 31 | jLabel3 = new javax.swing.JLabel(); 32 | jLabel4 = new javax.swing.JLabel(); 33 | itance2 = new javax.swing.JButton(); 34 | itance3 = new javax.swing.JButton(); 35 | biak = new javax.swing.JTextField(); 36 | nama = new javax.swing.JTextField(); 37 | nafas = new javax.swing.JTextField(); 38 | 39 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 40 | 41 | jLabel1.setText("LATIHAN INHERITANCE"); 42 | 43 | jLabel2.setText("NAMA"); 44 | 45 | jLabel3.setText("B. BIAK"); 46 | 47 | jLabel4.setText("BERNAFAS"); 48 | 49 | itance2.setText("INHERITANCE 2"); 50 | itance2.addActionListener(new java.awt.event.ActionListener() { 51 | public void actionPerformed(java.awt.event.ActionEvent evt) { 52 | itance2ActionPerformed(evt); 53 | } 54 | }); 55 | 56 | itance3.setText("INHERITANCE 3"); 57 | itance3.addActionListener(new java.awt.event.ActionListener() { 58 | public void actionPerformed(java.awt.event.ActionEvent evt) { 59 | itance3ActionPerformed(evt); 60 | } 61 | }); 62 | 63 | biak.addActionListener(new java.awt.event.ActionListener() { 64 | public void actionPerformed(java.awt.event.ActionEvent evt) { 65 | biakActionPerformed(evt); 66 | } 67 | }); 68 | 69 | nama.addActionListener(new java.awt.event.ActionListener() { 70 | public void actionPerformed(java.awt.event.ActionEvent evt) { 71 | namaActionPerformed(evt); 72 | } 73 | }); 74 | 75 | nafas.addActionListener(new java.awt.event.ActionListener() { 76 | public void actionPerformed(java.awt.event.ActionEvent evt) { 77 | nafasActionPerformed(evt); 78 | } 79 | }); 80 | 81 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 82 | getContentPane().setLayout(layout); 83 | layout.setHorizontalGroup( 84 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 85 | .addGroup(layout.createSequentialGroup() 86 | .addContainerGap() 87 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 88 | .addComponent(jLabel2) 89 | .addComponent(jLabel3) 90 | .addComponent(jLabel4)) 91 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 92 | .addGroup(layout.createSequentialGroup() 93 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE) 94 | .addComponent(jLabel1) 95 | .addGap(131, 131, 131)) 96 | .addGroup(layout.createSequentialGroup() 97 | .addGap(36, 36, 36) 98 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 99 | .addComponent(nama, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE) 100 | .addComponent(biak, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE) 101 | .addComponent(nafas, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)) 102 | .addGap(0, 0, Short.MAX_VALUE)))) 103 | .addGroup(layout.createSequentialGroup() 104 | .addGap(58, 58, 58) 105 | .addComponent(itance2) 106 | .addGap(28, 28, 28) 107 | .addComponent(itance3) 108 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 109 | ); 110 | layout.setVerticalGroup( 111 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 112 | .addGroup(layout.createSequentialGroup() 113 | .addGap(29, 29, 29) 114 | .addComponent(jLabel1) 115 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 116 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 117 | .addComponent(jLabel2) 118 | .addComponent(nama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 119 | .addGap(18, 18, 18) 120 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 121 | .addComponent(jLabel3) 122 | .addComponent(biak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 123 | .addGap(18, 18, 18) 124 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 125 | .addComponent(jLabel4) 126 | .addComponent(nafas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 127 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE) 128 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 129 | .addComponent(itance2) 130 | .addComponent(itance3)) 131 | .addGap(74, 74, 74)) 132 | ); 133 | 134 | pack(); 135 | }// //GEN-END:initComponents 136 | 137 | private void itance2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itance2ActionPerformed 138 | Latihan_Inheritance2 dua = new Latihan_Inheritance2(); 139 | nama.setText(dua.nama); 140 | biak.setText(dua.biak); 141 | nafas.setText(dua.nafas); 142 | }//GEN-LAST:event_itance2ActionPerformed 143 | 144 | private void itance3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itance3ActionPerformed 145 | Latihan_Inheritance3 tiga = new Latihan_Inheritance3(); 146 | nama.setText(tiga.nama); 147 | biak.setText(tiga.biak); 148 | nafas.setText(tiga.nafas); 149 | }//GEN-LAST:event_itance3ActionPerformed 150 | 151 | private void biakActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_biakActionPerformed 152 | // TODO add your handling code here: 153 | }//GEN-LAST:event_biakActionPerformed 154 | 155 | private void namaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_namaActionPerformed 156 | // TODO add your handling code here: 157 | }//GEN-LAST:event_namaActionPerformed 158 | 159 | private void nafasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nafasActionPerformed 160 | // TODO add your handling code here: 161 | }//GEN-LAST:event_nafasActionPerformed 162 | 163 | /** 164 | * @param args the command line arguments 165 | */ 166 | public static void main(String args[]) { 167 | /* Set the Nimbus look and feel */ 168 | // 169 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 170 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 171 | */ 172 | try { 173 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 174 | if ("Nimbus".equals(info.getName())) { 175 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 176 | break; 177 | } 178 | } 179 | } catch (ClassNotFoundException ex) { 180 | java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 181 | } catch (InstantiationException ex) { 182 | java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 183 | } catch (IllegalAccessException ex) { 184 | java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 185 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 186 | java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 187 | } 188 | // 189 | 190 | /* Create and display the form */ 191 | java.awt.EventQueue.invokeLater(new Runnable() { 192 | public void run() { 193 | new GUI().setVisible(true); 194 | } 195 | }); 196 | } 197 | // Variables declaration - do not modify//GEN-BEGIN:variables 198 | private javax.swing.JTextField biak; 199 | private javax.swing.JButton itance2; 200 | private javax.swing.JButton itance3; 201 | private javax.swing.JLabel jLabel1; 202 | private javax.swing.JLabel jLabel2; 203 | private javax.swing.JLabel jLabel3; 204 | private javax.swing.JLabel jLabel4; 205 | private javax.swing.JTextField nafas; 206 | private javax.swing.JTextField nama; 207 | // End of variables declaration//GEN-END:variables 208 | } 209 | -------------------------------------------------------------------------------- /Motorcycle.java: -------------------------------------------------------------------------------- 1 | public class Motorcycle { 2 | String make; 3 | String color; 4 | boolean engiceState; 5 | 6 | void startEngine(){ 7 | if (engiceState){ 8 | System.out.println("the engine is already on"); 9 | } 10 | else { 11 | System.out.println("the engine is now on"); 12 | } 13 | } 14 | 15 | void showAtts(){ 16 | System.out.println("this motorcycle is a"+color+" "+make+"."); 17 | if (engiceState){ 18 | System.out.println("the engine is on"); 19 | } 20 | else { 21 | System.out.println("the engine is off"); 22 | } 23 | } 24 | 25 | public static void main(String args[]) { 26 | Motorcycle m = new Motorcycle(); 27 | m.make = "Yamaha RZ350"; 28 | m.color = "yellow"; 29 | System.out.println("calling showAtts..."); 30 | m.showAtts(); 31 | System.out.println("Starting engine..."); 32 | m.startEngine(); 33 | System.out.println("calling showAtts..."); 34 | m.showAtts(); 35 | System.out.println("Starting engine..."); 36 | m.startEngine(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Polimorfisme-ayam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Polimorfisme; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class ayam extends hewan{ 12 | @Override 13 | void suara () 14 | { 15 | System.out.println("Kok Kok"); 16 | } 17 | @Override 18 | void makan () 19 | { 20 | System.out.println("Jagung"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Polimorfisme-hewan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Polimorfisme; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public abstract class hewan { 12 | abstract void suara(); 13 | abstract void makan(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Polimorfisme-kucing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Polimorfisme; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class kucing extends hewan{ 12 | @Override 13 | void suara () 14 | { 15 | System.out.println("Meong Miaw"); 16 | } 17 | @Override 18 | void makan () 19 | { 20 | System.out.println("Ikan"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Polimorfisme-main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package Polimorfisme; 6 | 7 | /** 8 | * 9 | * @author ScupidC0des 10 | */ 11 | public class main { 12 | public static void main (String [] args) 13 | { 14 | hewan oop; 15 | kucing k = new kucing (); 16 | oop = k; 17 | oop.suara(); 18 | oop.makan(); 19 | 20 | ayam a = new ayam (); 21 | oop = a; 22 | oop.suara(); 23 | oop.makan(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-Project 2 | 3 | Java Projects is a Python Projects library made by Open-Source Enthusiast. 4 | 5 | 6 | ## Contributing 7 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 8 | 9 | Please make sure to update tests as appropriate. 10 | 11 | ## License 12 | [MIT](https://choosealicense.com/licenses/mit/) 13 | 14 | hacktoberfest 2021 15 | -------------------------------------------------------------------------------- /agunglaksonop-BangunDatar.java: -------------------------------------------------------------------------------- 1 | package program; 2 | 3 | public interface BangunDatar { 4 | public void luas(); 5 | public void keliling(); 6 | 7 | 8 | } 9 | -------------------------------------------------------------------------------- /calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class kalkulatorCLI { 3 | 4 | public static void main(String args[]) 5 | { 6 | Scanner input = new Scanner(System.in); 7 | int bil1, bil2, pil ,hasil = 0; 8 | System.out.println("PROGRAM JAVA KALKULATOR SEDERHANA"); 9 | System.out.println("1. Perkalian"); 10 | System.out.println("2. Pembagian"); 11 | System.out.println("3. Penjumlahan"); 12 | System.out.println("4. Pengurangan"); 13 | System.out.println("----------------------------"); 14 | System.out.print("Bilangan 1 : "); 15 | bil1=input.nextInt(); 16 | System.out.print("Bilangan 2 : "); 17 | bil2=input.nextInt(); 18 | System.out.print("Pilihan Operasi: "); 19 | pil=input.nextInt(); 20 | 21 | switch (pil){ 22 | case 1 : hasil=bil1*bil2;break; 23 | case 2 : hasil=bil1/bil2;break; 24 | case 3 : hasil=bil1+bil2;break; 25 | case 4 : hasil=bil1-bil2;break; 26 | default : System.out.println("Salah memasukan pilihan"); 27 | } 28 | 29 | System.out.println("Hasil :"+hasil); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /garlek123.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TugasBesar { 4 | public static void main(String[] args) { 5 | int bil1, bil2, bil3, bil4, bil5; 6 | 7 | Scanner input = new Scanner(System.in); 8 | 9 | System.out.print("Masukkan Bilangan Pertama : "); 10 | bil1 = input.nextInt(); 11 | System.out.print("Masukkan Bilangan Kedua : "); 12 | bil2 = input.nextInt(); 13 | System.out.print("Masukkan Bilangan Ketiga : "); 14 | bil3 = input.nextInt(); 15 | System.out.print("Masukkan Bilangan Keempat : "); 16 | bil4 = input.nextInt(); 17 | System.out.print("Masukkan Bilangan Kelima : "); 18 | bil5 = input.nextInt(); 19 | 20 | input.close(); 21 | 22 | // Output 23 | int [] arr = new int [] {bil1, bil2, bil3, bil4, bil5}; 24 | int bilBesar = arr[0]; 25 | int bilKecil = arr[0]; 26 | for (int i = 0; i < arr.length; i++) { 27 | if(arr[i] > bilBesar) 28 | bilBesar = arr[i]; 29 | } 30 | for (int i = 0; i < arr.length; i++) { 31 | if(arr[i] < bilKecil) 32 | bilKecil = arr[i]; 33 | } 34 | System.out.println("===Bilangan Terbesar, Terkecil, dan Rata - Rata==="); 35 | System.out.println("Bilangan Terbesar adalah : " + bilBesar); 36 | System.out.println("Bilangan Terkecil adalah : " + bilKecil); 37 | System.out.println("Bilangan Rata - Rata adalah : " + ((bil1 + bil2 + bil3 + bil4 + bil5) / 5)); 38 | 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /mbul48AngkaRibuan.java: -------------------------------------------------------------------------------- 1 | import java.util.Locale; 2 | import java.util.Scanner; 3 | 4 | class mbul48AngkaRibuan { 5 | public static void main(String[] args) { 6 | Locale bahasa = new Locale("id"); 7 | Scanner inp = new Scanner(System.in); 8 | int harga = inp.nextInt(); 9 | 10 | System.out.printf(bahasa, "Rp%,d,-", harga); 11 | 12 | } 13 | } 14 | --------------------------------------------------------------------------------