Advertisement
belamarsha

Untitled

Oct 24th, 2019
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. public class TiketKereta
  4. {
  5. private String[] noHP = new String[10];
  6. private String[] NIK = new String[10];
  7. private String stasiunAsal;
  8. private String stasiunTujuan;
  9. private int kode_stasiun1;
  10. private int kode_stasiun2;
  11. private int jumlahPenumpang;
  12. private int harga;
  13. private String tanggal;
  14. Scanner scan = new Scanner(System.in);
  15.  
  16. public void beliTiketKA()
  17. {
  18. System.out.println("Masukkan Jumlah Penumpang :");
  19. jumlahPenumpang = scan.nextInt();
  20. for(int i = 1; i <= jumlahPenumpang; i++)
  21. {
  22. System.out.println("Masukkan Nomor Identitas Penumpang " + i + " :");
  23. NIK[i] = scan.next();
  24. System.out.println("\n");
  25.  
  26. System.out.println("Masukkan Nomor HP Penumpang " + i + " :");
  27. noHP[i] = scan.next();
  28. System.out.println("\n");
  29. }
  30.  
  31. System.out.println("Masukkan Tanggal Keberangkatan :");
  32. tanggal = scan.next();
  33. System.out.println("\n");
  34.  
  35. System.out.println("Pilih Stasiun Keberangkatan");
  36. System.out.println("1. Gubeng");
  37. System.out.println("2. Malang");
  38. System.out.println("3. Jember");
  39. kode_stasiun1 = scan.nextInt();
  40.  
  41. System.out.println("Pilih Stasiun Tujuan");
  42. System.out.println("1. Gubeng");
  43. System.out.println("2. Malang");
  44. System.out.println("3. Jember");
  45. kode_stasiun2 = scan.nextInt();
  46.  
  47. switch(kode_stasiun1)
  48. {
  49. case 1:
  50. stasiunAsal = "Gubeng";
  51. break;
  52. case 2:
  53. stasiunAsal = "Jakarta";
  54. break;
  55. case 3:
  56. stasiunAsal = "Bandung";
  57. break;
  58. }
  59.  
  60. switch(kode_stasiun2)
  61. {
  62. case 1:
  63. stasiunTujuan = "Gubeng";
  64. break;
  65. case 2:
  66. stasiunTujuan = "Jakarta";
  67. break;
  68. case 3:
  69. stasiunTujuan = "Bandung";
  70. break;
  71. }
  72. hitungHarga();
  73. printNota();
  74. }
  75.  
  76. public void hitungHarga()
  77. {
  78. if((kode_stasiun1 == 1 && kode_stasiun2 == 2) || (kode_stasiun1 == 2 && kode_stasiun2 == 1))
  79. harga = 10000;
  80. if((kode_stasiun1 == 1 && kode_stasiun2 == 3) || (kode_stasiun1 == 3 && kode_stasiun2 == 1))
  81. harga = 150000;
  82. if((kode_stasiun1 == 2 && kode_stasiun2 == 3) || (kode_stasiun1 == 3 && kode_stasiun2 == 2))
  83. harga = 200000;
  84.  
  85. harga = harga * jumlahPenumpang;
  86. }
  87.  
  88. public void printNota()
  89. {
  90. System.out.println("\n");
  91. System.out.println("I-Kios");
  92. System.out.println("TiketKA");
  93. for(int i = 1; i <= jumlahPenumpang; i++)
  94. {
  95. System.out.println("Nomor Identitas Penumpang " + i + " : " + NIK[i]);
  96. System.out.println("Nomor HP Penumpang "+ i + " : " + noHP[i]);
  97. }
  98. System.out.println("Tanggal Keberangkatan : " + tanggal);
  99. System.out.println("Stasiun Keberangkatan : " + stasiunAsal);
  100. System.out.println("Stasiun tujuan : " + stasiunTujuan);
  101. System.out.println("Harga : " + harga);
  102. System.out.println("\n");
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement