BankAccountTester.java
unknown
java
3 years ago
1.5 kB
7
Indexable
import java.util.*; public class BankAccountTester { public static void main(String[] args) { BankAccount account = new BankAccount(); Scanner scan = new Scanner(System.in); String s = ""; String cmd = ""; float value = 0; do { System.out.println("Comando? (Q, B, D, W, A)"); try { s = scan.nextLine(); } catch (NoSuchElementException e) { System.out.println("NoSuchElementException"); } if (!s.equals("")) { if (s.trim().length() == 1) { cmd = s.trim(); } else { cmd = s.substring(0, 1); value = Integer.parseInt(s.substring(1).trim()); } } switch (cmd.toUpperCase()) { default: // empty break; case "Q": System.out.println("Chiusura programma..."); System.out.println("Arrivederci"); break; case "B": System.out.println("Saldo attuale: " + account.getBalance()); break; case "D": if (account.deposit(value)) { System.out.println("Deposito effettuato: " + value); } else { System.out.println("Deposito non effettuato"); } break; case "W": if (account.withdraw(value)) { System.out.println("Prelievo effettuato: " + value); } else { System.out.println("Prelievo non effettuato"); } break; case "A": if (account.addInterest(value)) { System.out.println("Interesse aggiunto: " + value); } else { System.out.println("Interesse non valido"); } break; } } while (!(cmd.equalsIgnoreCase("Q"))); scan.close(); } }
Editor is loading...