Advertisement
Stelios_Gakis

Seminar_1/Task_1

Sep 15th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package Seminar_1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_1 {
  6.     public static void main(String [] args){
  7.         int move, balance = 0, d = 0, w = 0;
  8.         Scanner input = new Scanner (System.in);
  9.  
  10.         System.out.println("Welcome to our bank!");
  11.  
  12.         for (int i = 0; i < 10; i++) {
  13.             System.out.println("--- --- ---");
  14.             System.out.println("Current balance:" + balance);
  15.             System.out.println("--- --- ---");
  16.             try {
  17.                 Thread.sleep(1000);
  18.             } catch (InterruptedException e) {
  19.                 e.printStackTrace();
  20.             }
  21.  
  22.             System.out.println("Enter a deposit or withdraw (>0 = deposit, <0 withdraw)");
  23.             move = input.nextInt();
  24.             if (move > 0) {
  25.                 balance += move;
  26.                 d += 1;
  27.             }
  28.             else if (move < 0) {
  29.                 balance += move;
  30.                 w += 1;
  31.             }
  32.             else {
  33.                 System.out.println("You can not deposit/withdraw 0 SEK");
  34.                 i -= 1;
  35.  
  36.                 try {
  37.                     Thread.sleep(1000);
  38.                 } catch (InterruptedException e) {
  39.                     e.printStackTrace();
  40.                 }
  41.  
  42.             }
  43.         }
  44.         System.out.printf("# of Deposits = %d%n# of Withdraws = %d%nFinal balance = %d", d, w, balance);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement