Advertisement
iNoobAvicena

Laporan Praktikum 2

Feb 28th, 2020
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package sem2;
  2.  
  3. import java.util.*;
  4.  
  5. public class Solution {
  6.  
  7.     public static String[] judul = {"Konfigurasi Wireless Routerboard Mikrotik", "Instalasi & konfigurasi Jaringan Windows & Linux", "Cepat Kuasai PHP dan MySQL", "Pengantar Ilmu Sejarah", "Runtuhnya Kerajaan Hindu-Jawa", "Pemberontakan Indonesia Pada Masa Pendudukan Jepang", "Filsafat Manusia", "Pengantar Ilmu Filsafat", "Filsafat Islam", "Pemikiran dan Aktualisasi Pengembangan Pendidikan Islam ", "Fiqih Sunnah", "Ringkasan Shahih Muslim", "Dasar - Dasar Ilmu Politik", "Sistem Politik Indonesia", "Memahami Ilmu Politik"};
  8.     public static String[] penulis = {"Hardana", "Bunafit Nugroho", "Andreas", "Kuntowijoyo", "Slamet ", "Akira Nagazumi dan Nasution", "Abidin dan Zainal", "Achmadi Asmoro", "Al-Ghazali", "Prof. Dr. H. Muhaimin", "Imam Hasan Al-Banna", "Abu Ahmadi", "Miriam Budiarjo", "PT Gramedia Pustaka Utama", "Robert Michels"};
  9.     public static long[] hargaStat = {20000, 50000, 30000, 15000, 75000, 50000, 40000, 95000, 20000, 45000, 23000, 60000, 70000, 50000, 46000};
  10.     public static double[] diskon = {0.20, 0.05, 0.15, 0.03, 0.25, 0.04, 0.07, 0.06, 0.15, 0.07, 0.05, 0.09, 0.40, 0.45, 0.78};
  11.     public static String[] kategori = {"Teknologi", "Teknologi", "Teknologi", "Sejarah", "Sejarah", "Sejarah", "Filsafat", "Filsafat", "Filsafat", "Agama", "Agama", "Agama", "Politik", "Politik", "Politik"};
  12.     public static int[] stok = {4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 2, 12};
  13.  
  14.     public static void main(String[] args) throws Exception {
  15.         Scanner scan = new Scanner(System.in);
  16.         byte n;
  17.         do {
  18.             n = scan.nextByte();
  19.             if (n == 0) {
  20.                 System.exit(0);
  21.             }
  22.             String cari;
  23.             scan.nextLine();
  24.             cari = scan.nextLine();
  25.             Bukubaru a = new Bukubaru(cari);
  26.             a.printAll();
  27.         } while (n != 0);
  28.     }
  29. }
  30.  
  31. class Bukubaru {
  32.  
  33.     public String[] judul_b = new String[5];
  34.     public String[] penulis_b = new String[5];
  35.     public long[] hargaStat_b = new long[5];
  36.     public double[] diskon_b = new double[5];
  37.     public String[] discon_b = new String[5];
  38.     public String[] kategori_b = new String[5];
  39.     public long[] hargaAsli_b = new long[judul_b.length];
  40.     public int[] stok_b = new int[5];
  41.  
  42.     public void setAll(int n, int x) {
  43.         this.judul_b[x] = Solution.judul[n];
  44.         this.penulis_b[x] = Solution.penulis[n];
  45.         this.hargaStat_b[x] = Solution.hargaStat[n];
  46.         this.diskon_b[x] = Solution.diskon[n];
  47.         this.kategori_b[x] = Solution.kategori[n];
  48.         this.hargaAsli_b[x] = setHargaAsli(this.hargaStat_b[x], this.diskon_b[x]);
  49.         this.stok_b[x] = Solution.stok[n];
  50.     }
  51.  
  52.     public Bukubaru(String s) {
  53.         int j = 0;
  54.         for (int i = 0; i < 10; i++) {
  55.             if (Solution.penulis[i].equals(s)) {
  56.                 setAll(i, j);
  57.                 j++;
  58.             }
  59.         }
  60.         for (int i = 0; i < 10; i++) {
  61.             if (Solution.kategori[i].equals(s)) {
  62.                 setAll(i, j);
  63.                 j++;
  64.             }
  65.         }
  66.         for (int i = 0; i < 10; i++) {
  67.             if (Solution.judul[i].equals(s)) {
  68.                 setAll(i, j);
  69.                 j++;
  70.             }
  71.         }
  72.         for (int i = 0; i < 10; i++) {
  73.             if (String.valueOf(Solution.hargaStat[i]).equals(s)) {
  74.                 setAll(i, j);
  75.                 j++;
  76.             }
  77.         }
  78.     }
  79.  
  80.     public long setHargaAsli(long h, double d) {
  81.         double temp = h * d;
  82.         long temp1 = h - (long) temp;
  83.         return temp1;
  84.     }
  85.  
  86.     public void printAll() {
  87.         for (int i = 0; i <= 10; i++) {
  88.             if (this.stok_b[i] == 0) {
  89.                 break;
  90.             }
  91.             System.out.printf("%-12s :%s%n", "Judul Buku", this.judul_b[i]);
  92.             System.out.printf("%-12s :%s%d%n", "Harga Bersih", "Rp.", this.hargaAsli_b[i]);
  93.             System.out.printf("%-12s :%d%n%n", "Stok", this.stok_b[i]);
  94.         }
  95.     }
  96. }
Advertisement
RAW Paste Data Copied
Advertisement