Advertisement
Stelios_Gakis

Exercise_2

Sep 7th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. package Introduction_to_programming;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class Exercise_2 {
  8.  
  9.     public static void main(String[] args) {
  10.         new Main();
  11.         new Exercise_2();
  12.         new Lecture_3();
  13.     }
  14.  
  15.     public Exercise_2() {
  16.         Scanner input = new Scanner(System.in);
  17.         double money1, money2, interest1, interest2 ,balance1, balance2, depositmoney, withdrawmoney;
  18.         String name1, name2, cn1, cn2;
  19.         boolean withdraw, deposit;
  20.  
  21.  
  22.         System.out.println("Welcome to our bank!");
  23.         System.out.println("\n<Account 1>");
  24.         System.out.print("Please enter your name: ");
  25.         name1 = input.nextLine();
  26.         System.out.print("Please enter your civic number (YYMMDD-XXXX): ");
  27.         cn1 = input.nextLine();
  28.         System.out.print("Please enter how much money you have (SEK): ");
  29.         money1 = input.nextDouble();
  30.         System.out.print("Please enter the interest rate in percent: ");
  31.         interest1 = input.nextDouble();
  32.         balance1 = money1 + money1 * interest1 / 100;
  33.         cn2 = input.nextLine();
  34.  
  35.         try {
  36.             Thread.sleep(1000);
  37.         } catch (InterruptedException e) {
  38.             e.printStackTrace();
  39.         }
  40.  
  41.         System.out.println("\n<Account 2>");
  42.         System.out.print("Please enter your name: ");
  43.         name2 = input.nextLine();
  44.         System.out.print("Please enter your civic number (YYMMDD-XXXX): ");
  45.         cn2 = input.nextLine();
  46.         System.out.print("Please enter how much money you have (SEK): ");
  47.         money2 = input.nextDouble();
  48.         System.out.print("Please enter the interest rate in percent: ");
  49.         interest2 = input.nextDouble();
  50.         balance2 = money2 + money2 * interest2 / 100;
  51.  
  52.         try {
  53.             Thread.sleep(1000);
  54.         } catch (InterruptedException e) {
  55.             e.printStackTrace();
  56.         }
  57.  
  58.         System.out.println("\nAccount 1 information: <" + name1 + ">");
  59.         System.out.println("Name: " + name1);
  60.         System.out.println("Civic number: " + cn1);
  61.         System.out.println("Balance: " + money1 + " SEK ");
  62.         System.out.println("Interest rate: " + interest1 + " % ");
  63.         System.out.println("\nAfter one year you will have " + balance1 + " SEK");
  64.  
  65.         try {
  66.             Thread.sleep(1000);
  67.         } catch (InterruptedException e) {
  68.             e.printStackTrace();
  69.         }
  70.  
  71.         System.out.println("\nAccount 2 information: <" + name2 + ">");
  72.         System.out.println("Name: " + name2);
  73.         System.out.println("Civic number: " + cn2);
  74.         System.out.println("Balance: " + money2 + " SEK ");
  75.         System.out.println("Interest rate: " + interest2 + " % ");
  76.         System.out.println("\nAfter one year you will have " + balance2 + " SEK");
  77.  
  78.         try {
  79.             Thread.sleep(1000);
  80.         } catch (InterruptedException e) {
  81.             e.printStackTrace();
  82.         }
  83.  
  84.         System.out.print("\n" + name1 + ", would you like to deposit money? (true/false) ");
  85.         deposit = input.nextBoolean();
  86.         if (deposit) {
  87.             System.out.print("\nHow much money would you like to deposit (SEK)? ");
  88.             depositmoney = input.nextDouble();
  89.             money1 = depositmoney + money1;
  90.             System.out.println("\n" + name1 + " thank you for your transaction, your new balance is " + money1 + "SEK");
  91.         }
  92.  
  93.         try {
  94.             Thread.sleep(1000);
  95.         } catch (InterruptedException e) {
  96.             e.printStackTrace();
  97.         }
  98.  
  99.         System.out.print("\n" + name1 + ", would you like to withdraw money? (true/false) ");
  100.         withdraw = input.nextBoolean();
  101.         if (withdraw) {
  102.             System.out.print("\nHow much money would you like to withdraw (SEK)? ");
  103.             withdrawmoney = input.nextDouble();
  104.             money1 = money1 - withdrawmoney;
  105.             System.out.println("\n" + name1 + " thank you for your transaction, your new balance is " + money1 + "SEK");
  106.         }
  107.  
  108.         try {
  109.             Thread.sleep(1000);
  110.         } catch (InterruptedException e) {
  111.             e.printStackTrace();
  112.         }
  113.  
  114.         System.out.print("\n" + name2 + ", would you like to deposit money? (true/false) ");
  115.         deposit = input.nextBoolean();
  116.         if (deposit) {
  117.             System.out.print("\nHow much money would you like to deposit (SEK)? ");
  118.             depositmoney = input.nextDouble();
  119.             money2 = depositmoney + money2;
  120.             System.out.println("\n" + name2 + " thank you for your transaction, your new balance is " + money2 + "SEK");
  121.         }
  122.  
  123.         try {
  124.             Thread.sleep(1000);
  125.         } catch (InterruptedException e) {
  126.             e.printStackTrace();
  127.         }
  128.  
  129.         System.out.print("\n" + name2 + ", would you like to withdraw money? (true/false) ");
  130.         withdraw = input.nextBoolean();
  131.         if (withdraw) {
  132.             System.out.print("\nHow much money would you like to withdraw (SEK)? ");
  133.             withdrawmoney = input.nextDouble();
  134.             money2 = money2 - withdrawmoney;
  135.             System.out.println("\n" + name2 + " thank you for your transaction, your new balance is " + money2 + "SEK ");
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement