Advertisement
yusufmukharom

Untitled

Oct 24th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package uts;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class payment {
  6. private int id;
  7. public int tipe;
  8. private int jumlah;
  9. private float harga;
  10.  
  11. payment (int tipe){
  12. this.tipe = tipe;
  13. Scanner scan = new Scanner(System.in);
  14. if (tipe == 1 ) {
  15. System.out.println("Masukkan nomer > ");
  16. setId(scan.nextInt());
  17. scan.nextLine();
  18. } else {
  19. System.out.println("Masukkan kode > ");
  20. setId(scan.nextInt());
  21. scan.nextLine();
  22. }
  23. System.out.println("Masukkan Nominal > ");
  24. setJumlah(scan.nextInt());
  25. scan.nextLine();
  26. float harga = tipe == 1 ? 1000 : 2500;
  27. hitung(harga);
  28. }
  29.  
  30. public int getJumlah(){
  31. return this.jumlah;
  32. }
  33. public void setJumlah(int jumlah){
  34. this.jumlah = jumlah;
  35. }
  36. public int getId(){
  37. return this.id;
  38. }
  39. public void setId(int id){
  40. this.id = id;
  41. }
  42. public float getHarga(){
  43. return this.harga;
  44. }
  45. public void setHarga(float harga){
  46. this.harga = harga;
  47. }
  48.  
  49. public void hitung(float harga) {
  50. setHarga(harga + this.jumlah);
  51. }
  52.  
  53. public void getInfo() {
  54. if (this.tipe == 1 ) {
  55. System.out.println("<<<------------------------------------>>>");
  56. System.out.println("Nomor Telepon\t\t: " + this.id);
  57. System.out.println("Nominal\t\t: " + this.jumlah);
  58. System.out.println("Harga\t\t\t: " + this.harga);
  59. System.out.println("<<<------------------------------------>>>");
  60. } else {
  61. System.out.println("<<<------------------------------------>>>");
  62. System.out.println("Nomor Telepon\t\t: " + this.id);
  63. System.out.println("Nominal\t\t: " + this.jumlah);
  64. System.out.println("Harga\t\t\t: " + this.harga);
  65. System.out.println("<<<------------------------------------>>>");
  66. }
  67.  
  68. }
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement