Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. package lat;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. class Account
  7. {
  8. public int id;
  9. public double balance;
  10.  
  11. public Account()
  12. {
  13. id=0;
  14. balance=0;
  15. }
  16.  
  17. public Account(int a, double b)
  18. {
  19. id=a;
  20. balance=b;
  21. }
  22.  
  23. public double getBalance()
  24. {
  25. return balance;
  26. }
  27.  
  28. public void deposit(double a)
  29. {
  30. balance=balance+a;
  31. }
  32. public void withdraw(double a)
  33. {
  34. if(a<=balance)
  35. {
  36. balance=balance-a;
  37. }
  38. else
  39. {
  40. System.out.println("Not enough money");
  41. }
  42. }
  43. }
  44.  
  45. public class lat
  46. {
  47. public static void main(String args[])
  48. {
  49. Account[] account=new Account[10];
  50. for(int i=0; i<10; i++)
  51. {
  52. account[i]=new Account(i,100);
  53. }
  54.  
  55. while(true)
  56. {
  57. Scanner s=new Scanner(System.in);
  58. System.out.print("Enter your account ID: ");
  59. int id=s.nextInt();
  60.  
  61. while(id > 10 || id < 0)
  62. {
  63. System.out.print("Please try again: ");
  64. id=s.nextInt();
  65. }
  66.  
  67. while(true)
  68. {
  69. System.out.println("\nWelcome!!!");
  70. System.out.println("1: Current balance");
  71. System.out.println("2: Withdraw");
  72. System.out.println("3: Deposit");
  73. System.out.println("4: Exit");
  74. int choice=s.nextInt();
  75.  
  76. if(choice==1)
  77. {
  78. System.out.println("Your current balance: $"+account[id].getBalance());
  79. }
  80. else if (choice==2)
  81. {
  82. System.out.print("Enter the amount to deposit: ");
  83. double deposit=s.nextDouble();
  84. account[id].deposit(deposit);
  85. }
  86. else if(choice==3)
  87. {
  88. System.out.print("Enter the amount to withdraw: ");
  89. double withdraw=s.nextDouble();
  90. account[id].withdraw(withdraw);
  91. }
  92. else if(choice==4)
  93. {
  94. System.out.println("Logging out...");
  95. System.out.print("Enter your ID: ");
  96. int fid=s.nextInt();
  97. while(fid!=id)
  98. {
  99. System.out.print("Please try again: ");
  100. id=s.nextInt();
  101. }
  102. System.out.println("Successfully logged out. Thank you for banking with Longitude Banking.");
  103. }
  104. }
  105. }
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement