Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Introduction_to_programming;
- import java.util.Scanner;
- public class Exercise_2 {
- public static void main(String[] args) {
- new Main();
- new Exercise_2();
- new Lecture_3();
- }
- public Exercise_2() {
- Scanner input = new Scanner(System.in);
- double money1, money2, interest1, interest2 ,balance1, balance2, depositmoney, withdrawmoney;
- String name1, name2, cn1, cn2;
- boolean withdraw, deposit;
- System.out.println("Welcome to our bank!");
- System.out.println("\n<Account 1>");
- System.out.print("Please enter your name: ");
- name1 = input.nextLine();
- System.out.print("Please enter your civic number (YYMMDD-XXXX): ");
- cn1 = input.nextLine();
- System.out.print("Please enter how much money you have (SEK): ");
- money1 = input.nextDouble();
- System.out.print("Please enter the interest rate in percent: ");
- interest1 = input.nextDouble();
- balance1 = money1 + money1 * interest1 / 100;
- cn2 = input.nextLine();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("\n<Account 2>");
- System.out.print("Please enter your name: ");
- name2 = input.nextLine();
- System.out.print("Please enter your civic number (YYMMDD-XXXX): ");
- cn2 = input.nextLine();
- System.out.print("Please enter how much money you have (SEK): ");
- money2 = input.nextDouble();
- System.out.print("Please enter the interest rate in percent: ");
- interest2 = input.nextDouble();
- balance2 = money2 + money2 * interest2 / 100;
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("\nAccount 1 information: <" + name1 + ">");
- System.out.println("Name: " + name1);
- System.out.println("Civic number: " + cn1);
- System.out.println("Balance: " + money1 + " SEK ");
- System.out.println("Interest rate: " + interest1 + " % ");
- System.out.println("\nAfter one year you will have " + balance1 + " SEK");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("\nAccount 2 information: <" + name2 + ">");
- System.out.println("Name: " + name2);
- System.out.println("Civic number: " + cn2);
- System.out.println("Balance: " + money2 + " SEK ");
- System.out.println("Interest rate: " + interest2 + " % ");
- System.out.println("\nAfter one year you will have " + balance2 + " SEK");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.print("\n" + name1 + ", would you like to deposit money? (true/false) ");
- deposit = input.nextBoolean();
- if (deposit) {
- System.out.print("\nHow much money would you like to deposit (SEK)? ");
- depositmoney = input.nextDouble();
- money1 = depositmoney + money1;
- System.out.println("\n" + name1 + " thank you for your transaction, your new balance is " + money1 + "SEK");
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.print("\n" + name1 + ", would you like to withdraw money? (true/false) ");
- withdraw = input.nextBoolean();
- if (withdraw) {
- System.out.print("\nHow much money would you like to withdraw (SEK)? ");
- withdrawmoney = input.nextDouble();
- money1 = money1 - withdrawmoney;
- System.out.println("\n" + name1 + " thank you for your transaction, your new balance is " + money1 + "SEK");
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.print("\n" + name2 + ", would you like to deposit money? (true/false) ");
- deposit = input.nextBoolean();
- if (deposit) {
- System.out.print("\nHow much money would you like to deposit (SEK)? ");
- depositmoney = input.nextDouble();
- money2 = depositmoney + money2;
- System.out.println("\n" + name2 + " thank you for your transaction, your new balance is " + money2 + "SEK");
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.print("\n" + name2 + ", would you like to withdraw money? (true/false) ");
- withdraw = input.nextBoolean();
- if (withdraw) {
- System.out.print("\nHow much money would you like to withdraw (SEK)? ");
- withdrawmoney = input.nextDouble();
- money2 = money2 - withdrawmoney;
- System.out.println("\n" + name2 + " thank you for your transaction, your new balance is " + money2 + "SEK ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement