Stelios_Gakis

Exercise_3/Task_3+4

Sep 14th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package Exercise_3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_3_4 {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         int a;
  10.         int balance = 0, q = 1, w = 0;
  11.         String name = "";
  12.  
  13.         System.out.printf("- - - - Welcome to Bank of Hkr - - - - %n1) New account %n2) View account %n3) Deposit %n4) Withdraw %n5) Exit %n- - - - - - - - - - - - - - - - - - - -%n");
  14.  
  15.  
  16.         while (q == 1) {
  17.             if (w > 0) {
  18.                 try {
  19.                     Thread.sleep(1000);
  20.                 } catch (InterruptedException e) {
  21.                     e.printStackTrace();
  22.                 }
  23.                 System.out.printf("- - - - - - - - - - - - - - - - - - - -%n1) New account %n2) View account %n3) Deposit %n4) Withdraw %n5) Exit%n- - - - - - - - - - - - - - - - - - - -%n");
  24.             }
  25.             w++;
  26.  
  27.             System.out.println("Please input your choice ");
  28.             a = input.nextInt();
  29.             input.nextLine();
  30.             switch (a) {
  31.                 case 1:
  32.                     System.out.println("Please enter your name for your new account");
  33.                     name = input.nextLine();
  34.                     System.out.println("You account's name is: " + name);
  35.                     break;
  36.                 case 2:
  37.                     if (name.equals("")) {
  38.                         System.out.println("There are no registered accounts.");
  39.                     }
  40.                     else {
  41.                         System.out.println("Here's the information of your account\nName:");
  42.                         System.out.println(name);
  43.                         System.out.println("Your balance is = " + balance + " SEK");
  44.                     }
  45.                     break;
  46.                 case 3:
  47.                     if (name.equals("")) {
  48.                         System.out.println("There are no registered accounts.");
  49.                     }
  50.                     else {
  51.                         System.out.println("How much money would you like to deposit?");
  52.                         balance += input.nextInt();
  53.                         System.out.println("Your new balance is = " + balance + " SEK");
  54.                     }
  55.                     break;
  56.                 case 4:
  57.                     if (name.equals("")) {
  58.                         System.out.println("There are no registered accounts.");
  59.                     }
  60.                     else {
  61.                         System.out.println("How much money would you like to withdraw?");
  62.                         balance -= input.nextInt();
  63.                         System.out.println("Your new balance is = " + balance + " SEK");
  64.                     }
  65.                     break;
  66.                 case 5:
  67.                     System.out.println("Thank you for visiting our bank");
  68.                     q = 0;
  69.                     break;
  70.                 default:
  71.                     System.out.println("Error: Wrong number");
  72.                     break;
  73.             }
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment