Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package encapsulation;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AccountProgram {
  6. Scanner userIn = new Scanner(System.in);
  7. Account acc = new Account();
  8. double balance;
  9. double interest;
  10. double deposit;
  11. double withdraw;
  12. public void SetValues() {
  13. System.out.print("Enter balance: ");
  14. balance = userIn.nextInt();
  15. System.out.println("");
  16. System.out.print("Enter interest: ");
  17. interest = userIn.nextInt();
  18. acc = new Account(balance, interest);
  19. }
  20.  
  21. public void choose(){
  22. System.out.print("Hva vil du gjøre? Se penger 'V', se rente 'I', sette inn 'D', ta ut 'W', endre rente 'C', 'E' for å avslutte");
  23. char answer = userIn.next().charAt(0);
  24. run(answer);
  25. }
  26.  
  27. public void run(char a){
  28. switch(a){
  29. case 'D': System.out.print("Skriv inn ønsket innskudd: ");
  30. double amount = userIn.nextDouble();
  31. acc.deposit(amount);
  32.  
  33. case 'W': System.out.print("Skriv inn ønsket uttak: ");
  34. double withdr = userIn.nextDouble();
  35. acc.withdraw(withdr);
  36.  
  37. case 'V': System.out.println("Balance: " + acc.getBalance());
  38.  
  39. case 'I': System.out.println("Interest rate: " + acc.getInterestRate());
  40.  
  41. case 'C': System.out.print("Skriv inn ny rente: ");
  42. double newInterest = userIn.nextDouble();
  43. acc.setInterestRate(newInterest);
  44.  
  45. case 'E': System.out.println("Avslutter");
  46. close();
  47.  
  48. default: System.out.println("Du skrev inn noe feil prøv igjen(Husk capslock)");
  49. choose();
  50.  
  51. }
  52. }
  53.  
  54. public void close(){
  55. userIn.close();
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement