PEMROGRAMAN BERORIENTASI OBJEK
TUGAS PAPER WINDA HAPSARI . H 18110529 3KA30
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
DASAR - DASAR PEMROGRAMAN BERORIENTASI OBJEK
TUGAS Buat program dengan Java untuk menampilkan Biodata Pribadi Anda!
public class win { public static void main(String args[]) { System.out.print("Nama Saya Winda Hapsari"); System.out.print("\n\nNPM saya 18110529"); System.out.print("\n\nSaya kelas 3KA30"); System.exit(0); } }
Output Program :
3KA30 || JAVA
Page 2
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
DASAR BAHASA JAVA
1. Buat essay mengenai mengenai Unicod Unicodee berikut berikut tabel kodenya. kodenya.
2.
import javax.swing.JOptionPane; public class pbo {
3KA30 || JAVA
Page 3
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
public static void main(String args[]) { String input; int pembelian; int diskon; int harga; input = JOptionPane.showInputDialog("Input Pembelian :"); pembelian = Integer.parseInt(input); diskon = pembelian / 100*10; harga = pembelian - diskon; JOptionPane.showMessageDialog(null,"Pembelian : JOptionPane.showMessageDialog(null,"Pembelian Rp."+pembelian+"\nDiskon : "+diskon+"\nHarga "+diskon+"\nHarga Bayar : Rp."+harga); Rp."+harga); } }
Output Program :
3. public class pbo { 3KA30 || JAVA
Page 4
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
public static void main(String args[]) { System.out.println("\"Anda diundang rapat hari Jum\'at / pukul 14.00 WIB\""); } }
Output Program :
4. import javax.swing.JoptionPane public class win { public static void main(String args[]) { double c; double d; int a; int b; a=1; b=3; c=2.5; d=b*b-2*a*c; System.out.println("Hasil Determinan : "+d); } 3KA30 || JAVA
Page 5
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
}
Output Program :
OPERATOR DAN EKSPRESI
1.
import java.util.*; public class pbo { public static void main(String[] args) { Scanner input = new Scanner(System.in); double phi = 3.14; double r, luas,keliling,volume; System.out.print("Masukkan Jarijari Bola : "); r = input.nextDouble(); luas = 4 * phi * r * r * r / 3; keliling = 2 * phi * r; volume = 4 * phi * r * r; System.out.print("Luas Bola = " + (int)luas + " \nKeliling Bola = "+ (int)keliling + " \nVolume Bola = "+volume); } }
Output Program : 3KA30 || JAVA
Page 6
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
2. public class pbo { public static void main (String [] args) { int a = 25 + 25; String oktl = Integer.toOctalString(a); System.out.println("25(10)+25(10):: "+oktl+ "(8)"); System.out.println("25(10)+25(10) int b = 2 * 5; String hex1 = Integer.toHexString(b); System.out.println("2(10) x 5(10) :" +hex1+ "(16)"); int c = 81/9; String okt2 = Integer.toOctalString(c); System.out.println("81(10), 9(10) :" +okt2+ "(8)"); } }
Output Program :
3. public class pbo { public static void main (String [] args) { final String no = "001"; final String nama = "Aditya "Aditya Ramadhan"; 3KA30 || JAVA
Page 7
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
final String bulan = "April"; "April"; final float tarif = 250; final float biaya = 20000; 20000; final int pulsa = 110; float total = (pulsa*tarif) + biaya; System.out.println("Nomor Pelanggan : " +no); System.out.println("Nama Pelanggan : " +nama); System.out.println("Bulan Tagihan : " +bulan); System.out.println("Banyaknya Pulsa Pemakaian : " +pulsa); System.out.println("Jumlah Tagihan Bulan " +bulan+ " adalah sebesar Rp." +total); } }
Output Program :
OPERASI MASUKAN DAN KELUARAN 1. 3KA30 || JAVA
Page 8
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
import java.util.Scanner; import javax.swing.*; public class pbo { public static void main(String args[]) { int celcius = 0; double fahrenheit, reamur, fc = 1.8, cr = 0.8; Scanner input = new Scanner (System.in); System.out.println("Aplikasi Konventer Celcius ke Fahrenheit dan Reamur"); System.out.print("\nMasukkan suhu Celcius : "); celcius = input.nextInt(); fahrenheit = (celcius+32)*fc; System.out.println("\nSuhu dalam Fahrenheit : " + fahrenheit); reamur = celcius*cr; System.out.println("Suhu dalam Reamur
: " + reamur);
} }
Output Program :
2. import javax.swing.*; public class pbo 3KA30 || JAVA
Page 9
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
{ public static void main(String args[]) { String temp1 = JOptionPane.showInputDialog("Masukkan Nilai tugas : "); int tugas = Integer.parseInt(temp1); String temp2 = JOptionPane.showInputDialog("Masukkan Nilai mid : "); int mid = Integer.parseInt(temp2); String temp3 = JOptionPane.showInputDialog("Masukkan Nilai final : "); int fin = Integer.parseInt(temp3); int NA = (int) ((0.2*tugas)+(0.3*mid)+(0.5*fin)); JOptionPane.showMessageDialog(null,"Nilaii Akhir Anda = "+NA); JOptionPane.showMessageDialog(null,"Nila } }
Output Program :
3KA30 || JAVA
Page 10
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
3. import javax.swing.JOptionPane; public class win { public static void main(String args[]) { String input1,input2,input3; input1,input2,input3; int nilai1,nilai2,nilai3,volume,satu, nilai1,nilai2,nilai3,volume,satu,dua,tiga,luas; dua,tiga,luas; input1 = JOptionPane.showInpu J OptionPane.showInputDialog("Input tDialog("Input Panjang "); input2 = JOptionPane.showInputDialog("Input Lebar "); input3 = JOptionPane.showInputDialog("Input Tinggi "); nilai1 = Integer.parseInt(input1); nilai2 = Integer.parseInt(input2); nilai3 = Integer.parseInt(input3); volume = nilai1 * nilai2 * nilai3; satu= nilai1*nilai2; dua=nilai1*nilai3; tiga=nilai2*nilai3; luas=(2*satu) + (2*dua) + (2*tiga); JOptionPane.showMessageDialog(null,"Panjang : "+input1+"\nLebar JOptionPane.showMessageDialog(null,"Panjang "+input1+"\nLebar : "+input2+"\nTinggi : "+input3+"\nVolume = " +volume+ " \nLuas = " +luas); } }
Output Program :
3KA30 || JAVA
Page 11
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
EKSPRESI KONDISI DAN PERNYATAAN BERKONDISI
1. import javax.swing.JOptionPane; public class utsa { public static void main(String[] args) { int nilai; String bil = JOptionPane.showInputDialog("Masukkan sebuah bilangan bulat : "); nilai = Integer.parseInt(bil); if(nilai % 2 == 0) JOptionPane.showMessageDialog(null, "Nilai "Nilai " +nilai+ " habis dibagi 2 \nKarena itu termasuk bilangan GENAP"); else JOptionPane.showMessageDialog(null, "Nilai "Nilai " +nilai+ " tidak habis dibagi 2 \nKarena itu termasuk bilangan GANJIL"); } }
Output Program :
3KA30 || JAVA
Page 12
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
2.
import java.io.*; public class pbo { public static void main(String args[])throws Exception { DataInputStream nilai=new DataInputStream (System.in); System.out.println(" Menu Restaurant Mc'Cihuy"); System.out.println("================ System.out.println("======= =================== =================="); ========"); System.out.println("1. Nasi Goreng Informatika \tRp. 5.000,-"); System.out.println("2. Nasi Soto Ayam Internet \tRp. 7.000,-"); System.out.println("3. Gado-Gado Disket \t\tRp. 4.500,-"); System.out.println("4. Bubur Ayam LAN \t\tRp. 4.000,-"); System.out.println("================ System.out.println("======= =================== ================"); ======"); System.out.print("Masukkan Pilihan Anda : "); String Str ing snilai sni lai1=ni 1=nilai lai.re .readLi adLine ne (); int kode=Integer.valueOf(snilai1).intValue(); switch(kode) { case 1 :
3KA30 || JAVA
Page 13
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
System.out.println("Pilihan No. 1 Nasi Goreng Informatika Rp. 5.000,-"); break; case 2 : System.out.println("Pilihan No. 2 Nasi Soto Ayam Inter net Rp. 7.000,-"); break; case 3 : System.out.println("Pilihan No. 3 Gado-Gado Disket Rp. 4.500,-"); break; case 4 : System.out.println("Pilihan No. 4 Bubur Ayam LAN Rp. 4.000,-"); break; default : System.out.println("Pilihan Anda Salah, Ulangi Kembali!"); } } }
Output Program :
3KA30 || JAVA
Page 14
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
3. package winda; import java.util.*; public class winda { public static void main(String[] args) { Scanner input = new Scanner(System.in); int pilihan; int kode; int jumlah; String ukuran; System.out.print("Masukkan Kode Susu ( 1 - 3 ) : "); kode = input.nextInt(); System.out.print("Masukkan Jumlah Pembelian : "); jumlah = input.nextInt(); System.out.print("Masukkan Ukuran (B / S / K) : "); ukuran = input.next(); switch(kode){ case 1: System.out.println("\n Susu Dancow"); if (ukuran.equals ("B")) { System.out.println("Harga Susu Rp. 10000.00"); int jmlh=jumlah*10000; jmlh=jumlah*10000; System.out.print("Jumlah Pembelian Pembelian Rp. "+jmlh+ "+jmlh+ ".00"); } else if (ukuran.equals("S")) { System.out.println("Harga Susu Rp. 4250.00"); int jmlh=jumlah*4250; jmlh=jumlah*4250; System.out.print("Jumlah Pembelian Pembelian Rp. "+jmlh+ "+jmlh+ ".00"); } else if(ukuran.equals("K")) { System.out.println("Harga Susu Rp. 2100.00"); int jmlh=jumlah*2100; jmlh=jumlah*2100; System.out.print("Jumlah Pembelian Pembelian Rp. "+jmlh+ "+jmlh+ ".00"); } break; case 2: System.out.println("\n Susu Indomilk "); "); if(ukuran.equals("B")) { System.out.println("Harga Susu Rp. 8500.00"); int jmlh=jumlah*8500; jmlh=jumlah*8500; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } else if (ukuran.equals("S")) 3KA30 || JAVA
Page 15
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
{ System.out.println("Harga Susu Rp. 4000.00"); int jmlh=jumlah*4000; jmlh=jumlah*4000; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } else if (ukuran.equals("K")) { System.out.println("Harga Susu Rp. 2025.00"); int jmlh=jumlah*2025; jmlh=jumlah*2025; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } break; case 3: Sustacal "); System.out.println("\n Susu Sustacal "); if(ukuran.equals("B"))
{ System.out.println("Harga Susu Rp. 17000.00"); int jmlh=jumlah*17000; jmlh=jumlah*17000; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } else if(ukuran.equals("S")) { System.out.println("Harga Susu Rp. 14500.00"); int jmlh=jumlah*14500; jmlh=jumlah*14500; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } else if(ukuran.equals("K")) { System.out.println("Harga Susu Rp. 8300.00"); int jmlh=jumlah*8300; jmlh=jumlah*8300; System.out.print("Jumlah Pembelian Rp. "+jmlh+ ".00"); } break; default: System.out.print("Pilihan tidak ada, Ulangi Kembali!"); } } }
Output Program :
3KA30 || JAVA
Page 16
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
PENGULANGAN PROSES 1. package kondisi; public class cob { public static void main (String[] args) { System.out.print("Bilangan Ganjil : "); int x=1; for(int i=1; i<=25; i++) { System.out.print(x+" "); x+=2; } System.out.print("\n"); System.out.print("Bilangan Genap : "); int y=0; for(int i=1; i<=26; i++) { System.out.print(y+" "); y+=2; } } }
Output Program :
3KA30 || JAVA
Page 17
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
2. package winda; public class winda { public static void main(String[] args) { int celcius; double fahrenheit, reamur; System.out.println(" CELCIUS\tFAHRENHE CELCIUS\tFAHRENHEIT\tREAMUR\n"); IT\tREAMUR\n"); celcius = 100; do { fahrenheit = 1.8 * celcius + 32; reamur = 1.8 * celcius; System.out.printf( “ “ +celcius+"\t\t%.2f\t\t%.2f %n",fahrenheit,reamur); celcius--; } while(celcius >= 0); } }
Output Program :
3KA30 || JAVA
Page 18
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
3. package winda; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class winda; { public static void main(String[] args) throws IOException { BufferedReader a = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nMasukkan Bilangan = "); int angka = Integer.parseInt(a.readLine()); for(int i=1;i<=angka;i++) { 3KA30 || JAVA
Page 19
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
for(int j=1;j<=i;j++) { System.out.print("*"); } System.out.println(); } } }
Output Program :
AARAY DAN ARGUMEN BARIS PERINTAH 1.
package winda; public class winda 3KA30 || JAVA
{ Page 20
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
public static void main(String[] args) { int[] data={5,1,3,2,4}; cetakConsole("Data Asli : ",data); ascending(data); cetakConsole("\nPengurutan Ascending : ",data); descending(data); cetakConsole("\nPengurutan Descending : ",data); } static void ascending(int[] urut) { int tukar=0; for(int a=0;a
{
} static void descending(int[] urut) { int tukar=0; for(int a=0;a
urut[d]) { tukar=urut[a]; urut[a]=urut[d]; urut[d]=tukar; } }
{
} static void cetakConsole(String jdl,int[] arr) { System.out.println(jdl); for(int b=0;b
Output Program :
3KA30 || JAVA
Page 21
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
2.
package winda; import java.util.*; public class winda { public static void main(String args[]) { Scanner input = new Scanner(System.in); int i; int j; int[][]matrixA = new int[3][3]; int[][]matrixB = new int[3][23]; int[][]jumlah = new int[3][3]; for(i=1;i<3;i++) { for(j=1;j<3;j++) { System.out.print("Matrix System.out.print("Matrix A " + i + "." + j + "= "); ");
matrixA[i][j] =input.nextInt(); } } System.out.println(); for(i=1;i<3;i++)
3KA30 || JAVA
Page 22
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
{ for(j=1;j<3;j++) { System.out.print("Matrix System.out.print("Matrix B " + i + "." + j + "= "); ");
matrixB[i][j] =input.nextInt(); } } for(i=1;i<3;i++) { for(j=1;j<3;j++) { jumlah[i][j] = matrixA[i][j] + matrixB[i][j]; } } System.out.println("\nMatrix System.out.println("\nMatrix A");
for(i=1;i<3;i++) { for(j=1;j<3;j++) { System.out.print(" " + matrixA[i][j]); } System.out.println(); } System.out.println("\nMatrix System.out.println("\nMatrix B");
for(i=1;i<3;i++)
3KA30 || JAVA
Page 23
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
{ for(j=1;j<3;j++) { System.out.print(" " + matrixB[i][j]); } System.out.println(); } System.out.println("\nMatrix System.out.println("\nMatrix A + Matrix B");
for(i=1;i<3;i++) { for(j=1;j<3;j++) { System.out.print(" " + jumlah[i][j]); } System.out.println(); } } }
Output Program :
3KA30 || JAVA
Page 24
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
3. package kondisi; import java.io.*;; public class cob { public static void main(String args[]) throws IOException { int i,j; int tpenjualan = 0; BufferedReader a = new BufferedReader(newInputStreamReader(System.in)); BufferedReader(newInputStreamReader(System.in)); String nmbrg[] = new String[100]; int harga[] = new int[100]; int jml[] = new int[100]; int tbeli[] = new int[100]; int total[] = new int[100]; System.out.print("Masukkan Bulan Penjualan : "); String bln = a.readLine(); System.out.print("Masukkan Jumlah Data : "); int jmldata = Integer.parseInt(a.readLine()); for (i=1;i<=jmldata;i++) { System.out.print("Nama Barang ke - "+i+" : "); nmbrg[i] = a.readLine(); System.out.print("Jumlah : "); jml[i] = Integer.parseInt(a.readLine()); System.out.print("Harga Rp. : "); harga[i] = Integer.parseInt(a.readLine()); System.out.println(); } System.out.println(); System.out.println("LAPORAN PENJUALAN PT. YAI"); System.out.println("BULAN : "+bln); System.out.println("================ System.out.println("======= =================== ==================="); ========="); System.out.println("NO\tNAMA BARANG\tJUMLAH\t\tHARGA\t\tTOTAL BARANG\tJUMLAH\t\tHARGA\t\tTOTAL"); "); System.out.println("================ System.out.println("======= =================== ==================="); ========="); for(j=1;j<=jmldata;j++) { tbeli[j] = jml[j]*harga[j]; total[j] += tbeli[j]; System.out.println(j+"\t"+nmbrg[j]+"\t"+jml[j]+"\t\t"+harga[j]+"\t\t"+total[j]); 3KA30 || JAVA
Page 25
PEMROGRAMAN BERORIENTASI BERORIENTASI OBJEK || ERICK ORLANDO
tpenjualan += total[j]; } System.out.println("================ System.out.println("======= =================== ==================="); ========="); System.out.println("\nTOTAL BARANG : "+jmldata); System.out.println("TOTAL PENJUALAN : "+tpenjualan); } }
Output Program :
3KA30 || JAVA
Page 26