Advertisement
yusufmukharom

Untitled

Oct 24th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package uts;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Ticket {
  7. public int tipe;
  8. private int id;
  9. private String setasiunBerangkat;
  10. private String tujuan;
  11. private int jumlah;
  12. private String tgl;
  13. private float harga;
  14.  
  15. Ticket (int tipe){
  16. this.tipe = tipe;
  17. Scanner scan = new Scanner(System.in);
  18. System.out.println("Masukkan Tempat Awal > ");
  19. setSetasiunBerangkat(scan.nextLine());
  20. System.out.println("Masukkan Tempat Ahir > ");
  21. setTujuan(scan.nextLine());
  22. System.out.println("Masukkan Jumlah Penumpang > ");
  23. setJumlah(scan.nextInt());
  24. scan.nextLine();
  25. System.out.println("Masukkan Tanggal Berangkat [hh/bb/tttt] > ");
  26. setTgl(scan.nextLine());
  27. int harga = this.tipe == 1 ? 10000 : 50000;
  28. hitung(jumlah, harga);
  29. }
  30.  
  31. public String getSetasiunBerangkat(){
  32. return this.setasiunBerangkat;
  33. }
  34. public void setSetasiunBerangkat(String stasiun){
  35. this.setasiunBerangkat = stasiun;
  36. }
  37. public String getTujuan(){
  38. return this.tujuan;
  39. }
  40. public void setTujuan(String tujuan){
  41. this.tujuan = tujuan;
  42. }
  43. public int getJumlah(){
  44. return this.jumlah;
  45. }
  46. public void setJumlah(int jumlah){
  47. this.jumlah = jumlah;
  48. }
  49. public String getTgl(){
  50. return this.tgl;
  51. }
  52. public void setTgl(String tanggal){
  53. this.tgl = tanggal;
  54. }
  55. public float getHarga(){
  56. return this.harga;
  57. }
  58. public void setHarga(float harga){
  59. this.harga = harga;
  60. }
  61.  
  62. public void hitung(int jumlah,int harga) {
  63. Random rand = new Random();
  64. int number = rand.nextInt(10) + 1;
  65. float total = (jumlah*harga*number);
  66. // System.out.println(number);
  67. setHarga(total);
  68. }
  69. public void getInfo() {
  70. if (this.tipe == 1 ) {
  71. System.out.println("<<<------------------------------------>>>");
  72. System.out.println("Stasiun Awal\t\t: " + this.setasiunBerangkat);
  73. System.out.println("Stasiun Ahir\t\t: " + this.tujuan);
  74. System.out.println("Tanggal Berangkat\t: " + this.tgl);
  75. System.out.println("Jumlah Penumpang\t: " + this.jumlah);
  76. System.out.println("Harga\t\t\t: " + this.harga);
  77. System.out.println("<<<------------------------------------>>>");
  78. } else {
  79. System.out.println("<<<------------------------------------>>>");
  80. System.out.println("Bandara Awal\t\t: " + this.setasiunBerangkat);
  81. System.out.println("Bandara Ahir\t\t: " + this.tujuan);
  82. System.out.println("Tanggal Berangkat\t: " + this.tgl);
  83. System.out.println("Jumlah Penumpang\t: " + this.jumlah);
  84. System.out.println("Harga\t\t\t: " + this.harga);
  85. System.out.println("<<<------------------------------------>>>");
  86. }
  87.  
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement