Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.String;
- public class Main
- {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String a = scan.next();
- while (!a.equals("End")) {
- if (a.equals("Create")) {
- BankAccount.accounts();
- }
- else if(a.equals("Deposit"))
- {
- int id = scan.nextInt();
- double amount = scan.nextDouble();
- BankAccount.deposit(id, amount);
- }
- else if(a. equals("SetInterest"))
- {
- double setInterest = scan.nextDouble();
- BankAccount.setInterestRate(setInterest);
- }
- else if(a. equals("GetInterest"))
- {
- int id = scan.nextInt();
- int year = scan.nextInt();
- if (BankAccount.getInterest(id,year) != -1)
- {
- System.out.println(BankAccount.getInterest(id, year));
- }
- }
- a = scan.next();
- }
- }
- }
- import java.util.ArrayList;
- public class BankAccount
- {
- private final static double DEFAULT_INTEREST_RATE = 0.02;
- private static int id;
- private double balance;
- private static double interestRate = DEFAULT_INTEREST_RATE;
- private static int bankAccount = 1;
- private static ArrayList BankAccounts = new ArrayList();
- BankAccount()
- {
- this.id = bankAccount++;
- this.balance = balance;
- }
- BankAccount(double amount)
- {
- this.id = id;
- this.balance += amount;
- }
- static void accounts()
- {
- BankAccounts.add(new BankAccount());
- System.out.println("ID"+id);
- }
- static void setInterestRate(double interestRate)
- {
- BankAccount.interestRate = interestRate;
- }
- static void deposit(int id, double amount)
- {
- if (id > BankAccounts.size())
- {
- System.out.println("Account does not exist");
- return;
- }
- id--;
- BankAccounts.set(id, new BankAccount(amount));
- System.out.println("Deposit "+ amount + " to ID" + ++id);
- }
- static double getInterest ( int id, int years)
- {
- if (id > BankAccounts.size())
- {
- System.out.println("Account does not exist");
- return -1;
- }
- id--;
- BankAccount temp = (BankAccount) BankAccounts.get(id);
- return BankAccount.interestRate * years * temp.balance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment