Guest User

Untitled

a guest
Apr 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.util.Scanner;
  2. class SavingAccount {
  3. public String accountNumber;
  4. private String accountName;
  5. private double amount;
  6.  
  7. SavingAccount(String numb, String name) {
  8. accountNumber = numb;
  9. accountName = name;
  10. }
  11.  
  12. public void changeName(String name) {
  13. accountName = name;
  14. }
  15.  
  16. public void deposit(double amount) {
  17. if (amount >= 0)
  18. this.amount += amount;
  19. }
  20.  
  21. public void withdraw(double amount) {
  22. if (this.amount - amount >= 0) {
  23. this.amount -= amount;
  24. } else {
  25. System.out.println("AMOUNT IN ACCOUNT $" + String.format("%.2f", this.amount) + ". PLEASE TRY AGAIN.");
  26. }
  27. }
  28.  
  29. public void display() {
  30.  
  31. System.out.println("ACCOUNT NUMBER:" + accountNumber);
  32. System.out.println("ACCOUNT NAME:" + accountName);
  33. System.out.println("AMOUNT:$" + String.format("%.2f", amount));
  34. }
  35. }
  36.  
  37. public class RunSavingAccount {
  38. public static void main(String[] args){
  39. Scanner sc = new Scanner(System.in);
  40. final int n = sc.nextInt();
  41. SavingAccount saveAcc = new SavingAccount(null, null);
  42. String s;
  43. for(int i = 0;i<n;i++){
  44. s = sc.next();
  45. if(s.equals("A"))
  46. saveAcc = new SavingAccount(sc.next(), sc.next());
  47.  
  48.  
  49. else if(s.equals("D")){
  50. saveAcc.deposit(Double.parseDouble(sc.next()));
  51.  
  52. }
  53. else if(s.equals("C")){
  54. saveAcc.changeName(sc.next());
  55.  
  56. }
  57. else if(s.equals("W")){
  58. saveAcc.withdraw(Double.parseDouble(sc.next()));
  59.  
  60. }
  61. else if(s.equals("P") ){
  62. saveAcc.display();
  63. }
  64.  
  65.  
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment