Advertisement
hendroprwk08

Untitled

Sep 23rd, 2022 (edited)
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. public class Pesan {
  2. String nama, tipe, gula;
  3. Integer harga, qty;
  4.  
  5. public Pesan(String nama, String tipe, String gula, Integer harga, Integer qty) {
  6. this.nama = nama;
  7. this.tipe = tipe;
  8. this.gula = gula;
  9. this.harga = harga;
  10. this.qty = qty;
  11. }
  12.  
  13. public String getNama() {
  14. return nama;
  15. }
  16.  
  17. public String getTipe() {
  18. return tipe;
  19. }
  20.  
  21. public String getGula() {
  22. return gula;
  23. }
  24.  
  25. public Integer getHarga() {
  26. return harga;
  27. }
  28.  
  29. public Integer getQty() {
  30. return qty;
  31. }
  32. }
  33.  
  34.  
  35.  
  36. =================== bikin file baru
  37.  
  38. import java.util.ArrayList;
  39. import java.util.Scanner;
  40.  
  41. public class JavaApplication1 {
  42.  
  43. public static void main(String[] args) {
  44. ArrayList<Pesan> p = new ArrayList();
  45. Scanner sc = new Scanner(System.in);
  46. Integer pilihan = 0;
  47.  
  48. do{
  49. /*
  50. jika pilih 1, maka input data,
  51. jika 2, maka tampilkan data
  52. jika 3 maka keluar sistem
  53. */
  54.  
  55. System.out.println("----------------------------");
  56. System.out.println("--- BINTANG BUCK COFFEE ----");
  57. System.out.println("----------------------------");
  58. System.out.println(" 1. Pembelian");
  59. System.out.println(" 2. Bayar");
  60. System.out.println(" 3. Keluar sistem");
  61. System.out.println("----------------------------");
  62. System.out.print(" Pilihanmu: ");
  63. pilihan = sc.nextInt();
  64.  
  65. if(pilihan == 1 ){
  66. p = beli( p );
  67. }else if(pilihan == 2){
  68. p = bayar( p );
  69. }
  70. }while (pilihan != 3);
  71.  
  72. }
  73.  
  74. private static ArrayList<Pesan> beli( ArrayList<Pesan> p ){
  75. Scanner sc = new Scanner(System.in);
  76. String nama, tipe, gula;
  77. Integer harga, qty;
  78.  
  79. System.out.print("Nama: ");
  80. nama = sc.nextLine();
  81.  
  82. System.out.print("Tipe: ");
  83. tipe = sc.nextLine();
  84.  
  85. System.out.print("Gula: ");
  86. gula = sc.nextLine();
  87.  
  88. System.out.print("Harga: ");
  89. harga = sc.nextInt();
  90.  
  91. System.out.print("Qty: ");
  92. qty = sc.nextInt();
  93.  
  94. p.add( new Pesan( nama, tipe, gula, harga, qty ) );
  95.  
  96. return p;
  97. }
  98.  
  99. private static ArrayList<Pesan> bayar( ArrayList<Pesan> p ){
  100. Scanner sc = new Scanner(System.in);
  101.  
  102. //tampilkan data
  103. System.out.println("Jumlah data: "+ p.size()); //ini error
  104. System.out.println("--------------------------------------------------------------------");
  105. System.out.printf("| %-3s | %-10s | %-10s | %-5s | %-7s | %-3s | %-7s |",
  106. "No",
  107. "Nama",
  108. "Tipe",
  109. "Gula",
  110. "Harga",
  111. "Qty",
  112. "Jumlah");
  113. System.out.println();
  114. System.out.println("--------------------------------------------------------------------");
  115.  
  116. for(int i = 0; i < p.size(); i++ ){
  117. System.out.printf("| %-3s | %-10s | %-10s | %-5s | %-7s | %-3s | %-7s |",
  118. i + 1,
  119. p.get(i).getNama(),
  120. p.get(i).getTipe(),
  121. p.get(i).getGula(),
  122. p.get(i).getHarga(),
  123. p.get(i).getQty(),
  124. (p.get(i).getHarga() * p.get(i).getQty()));
  125. System.out.println();
  126. System.out.println("--------------------------------------------------------------------");
  127.  
  128. }
  129.  
  130. System.out.println("Tekan enter untuk lanjut...");
  131. sc.nextLine();
  132.  
  133. return p;
  134. }
  135. }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement