Question

Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should d3) Class Transaction: has a transaction type (byte) (0= deposit, 1= withdraw, 2=addedInterest), amount (double) stores the amOther methods; getBalance (returns double), getCustomer (returns a customer), toString (returns a string with the account inf

Please help JAVA

Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer is created variable lastCustomerNumber is increased by one - Define the accessors and modifiers for the data fields as well as the methods equals and toString. Define as many constructors as needed. Add the following abstract methods: getSavingsInterest, getCheckInterest and getCheckCharge that all returna double. These methods will be implemented in the children classes 2) The classes Senior, Adult, Student extend the Customer class, they all have different values for the constants that are shown in the table below -The Senior class has an additional Boolean field that indicates whether the Senior is a VIP or not The following are the values for the constants in the classes: Senior, Adult and Student: CHECK INTEREST OVERDRAFT PENALTY SAVINGS INTEREST CHECK CHARGE only up to $500) 0.03 (38) 0.01 3 cents $25 Adult Student 0.07 0.03 2 cents cannot Senior 1 cent $10 0.08 0.04 No over draft up to $100 $5 up to Senior VIP 0.1 0.04 $500
3) Class Transaction: has a transaction type (byte) (0= deposit, 1= withdraw, 2=addedInterest), amount (double) stores the amount in the transaction, date of the transaction ( of type Date), fees, and a description (a string). It has one method: processTransaction that returns a string with the transaction information (similar to toString) 4) Class Account: An abstract class, each account has a customer (type Customer), balance (double), accountNumber (generated in a similar way to the customer number), transactions (an array of Transaction[]) When the Account is initialized you need to create an array with INITSIZE ( a class variable set to 25). - The account has a method reallocate that doubles the size of the transactions array when it is full
Other methods; getBalance (returns double), getCustomer (returns a customer), toString (returns a string with the account information except for the transactions), setCustomer (Customer c). 5) Classes SavingsAccount and CheckingAccount extend Account They implement the methods: deposit, withdraw and addInterest The method deposit adds a positive amount to the account balance and store the transaction information in the transactions array. The method with draw reduces the balance only if sufficient balance is available. Adults and Seniors can overdraft money up to $500 at an overdraft cost (see the above table). The withdraw information should be stored in a transaction along with the overdraft fee. If the customer withdraws money from a checking account and additional charge is incurred and added to the transaction fee. The method addInterest calculates the Interest for the balance and adds it to balance ( for example, if balance =$10 for a checking Interest 10*0.04) and adds it to the balance and saves the information in a transaction account of a senior, addInetrest calculate the 6) The class Bank has an accounts array (account []). When a bank is created, allocated a space 100 accounts and provide a reallocate method that can double the size of the accounts array whenever you cannot add a new account. The Bank class has the following methods: addAccount, makeDeposit, makeWithdrawal and geAccount 7) Some Notes: Please download and use the classes: BankGUI, BankApp, as well as the interface for the class Bank. You can modify the code as needed. For each class, add comments (documentation) describing the variables and methods used
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Customer.java
public abstract class Customer {
   private String firstName;
   private String lastName;
   private int age;
   private int customerNumber;
   public static int lastCustomerNumber = 9999;
   public Customer(){
       firstName = "";
       lastName = "";
       age = 0;
       customerNumber = lastCustomerNumber;
       lastCustomerNumber ++;
   }
   public Customer(String fname, String lname, int a){
       firstName = fname;
       lastName = lname;
       age = a;
       customerNumber = lastCustomerNumber;
       lastCustomerNumber ++;
   }
   public String getFirstName(){
       return firstName;
   }
   public String getLastName(){
       return lastName;
   }
   public int getAge(){
       return age;
   }
   public int getCustomerNumber(){
       return customerNumber;
   }
   public void setFirstName(String name){
       firstName = name;
   }
   public void setLastName(String name){
       lastName = name;
   }
   public void setAge(int a){
       age = a;
   }
   public boolean equals(Customer c){
       if(c.getCustomerNumber()==customerNumber){
           return true;
       }
       return false;
   }
   public String toString(){
       String str = "First Name : "+ firstName + " Last Name : "+ lastName + " Age : "+ age + " Customer Number : " + customerNumber;
       return str;
       }
   public abstract double getSavingsIntrest();
   public abstract double getCheckIntrest();
   public abstract double getCheckCharge();

   public double getOverDraftCharges(double amt) {
       return 0;
   }

}

Adult.java


public class Adult extends Customer {
   public Adult(){
       super();
   }
   public Adult(String fname, String lname, int a){
       super(fname,lname,a);
   }
  

   public double getSavingsIntrest() {
       return 0.03;
   }

   public double getCheckIntrest() {
       return 0.01;
   }

   public double getCheckCharge() {
       return 0.03;
   }

public double getOverDraftCharge(double amt){
       if(amt<500){
           return 25.0;
       }
       else {
           throw new IllegalArgumentException("OverDraft must be in limit $500");
       }
   }

}

Senior.java


public class Senior extends Customer {
  
   private boolean vip;
  
   public Senior(){
       super();
   }
   public Senior(String fname, String lname, int a){
       super(fname,lname,a);
   }
   public Senior(String fname, String lname, int a, boolean vip){
       super(fname,lname,a);
       this.vip = vip;
   }

   public double getSavingsIntrest() {
       if(vip){
           return 0.1;
       }
       return 0.08;
   }

   public double getCheckIntrest() {
       return 0.04;
   }

   public double getCheckCharge() {
       if(vip){
           return 0.00;
       }
       return 0.01;
   }

public double getOverDraftCharge(double amt){
       if(amt<500){
           if(vip){
               if(amt<=100){
                   return 0.0;
               }
               else{
                   return 5.0;
               }
           }
           else{
               return 10.0;
           }
       }
       else {
           throw new IllegalArgumentException("OverDraft must be in limit $500");
       }
   }

}

Student.java


public class Student extends Customer {
   public Student(){
       super();
   }
   public Student(String fname, String lname, int a){
       super(fname,lname,a);
   }
  

   public double getSavingsIntrest() {
       return 0.07;
   }

   public double getCheckIntrest() {
       return 0.03;
   }

   public double getCheckCharge() {
       return 0.02;
   }

public double getOverDraftCharge(double amt){
           throw new IllegalArgumentException("Student can not do OverDraft.");
   }

}

Transaction.java

import java.util.Date;


public class Transaction {

   private byte type;
   private double amount;
   private Date date;
   private double fees;
   private String discription;
   public String processTransaction(){
       String t = "";
       if(type==0){
           t = "deposited";
       }
       if(type == 1){
           t = "withdraw";
       }
       if(type == 2){
           t = "addedInterest";
       }
       return "Amount " + amount + " is " + t + "on Date :" + date + "with fees : " + fees + discription;
      
   }
   public Transaction(byte t,double amt,Date d,double f,String dis){
       type = t;
       amount = amt;
       date = d;
       fees = f;
       discription = dis;
   }
}

Account.java

import java.util.Date;


public abstract class Account {
  
   protected Customer customer;
   protected double balance;
   private int accountNumber;
   public static int AccountNumber = 0;
   private Transaction[] transactions;
   private int INITSIZE = 25;
   private int count = 0;
  
   public Account(Customer c,double balance){
       customer = c;
       this.balance = balance;
       accountNumber = AccountNumber + 1;
       AccountNumber++;
       transactions = new Transaction[INITSIZE];
   }
   public void reallocate(){
       int size = transactions.length;
       Transaction[] temp = new Transaction[size*2];
       transactions = temp;
   }
   public Customer getCustomer(){
       return customer;
   }
   public double getBalance(){
       return balance;
   }
   public int getAccountNumber(){
       return accountNumber;
   }
   public String toString(){
       return customer.toString()+" Account Number : " + accountNumber + " Balance : " + balance;  
   }
   public void setCustomer(Customer c){
       customer = c;
   }
   public void addTransaction(byte t,double amt,Date d,double f,String dis){
       if(count==transactions.length){
           reallocate();
           addTransaction(t, amt, d, f, dis);
       }
       else{
           transactions[count] = new Transaction(t, amt, d, f, dis);
       }
   }

public abstract void deposit(double amt, String dis);

public abstract void withdraw(double amt, String dis);

}

SavingsAccount.java

import java.util.Date;


public class SavingsAccount extends Account{

   public SavingsAccount(Customer c, double balance) {
       super(c, balance);
   }
  
   public void deposit(double amt,String dis){
       if(amt>0){
           this.balance = balance + amt;
           Date d = new Date();
           this.addTransaction((byte) 0, amt, d,0.0,dis);
       }
   }
   public void withdraw(double amt,String dis){
       if(amt<balance){
           this.balance = balance - amt;
           Date d = new Date();
           this.addTransaction((byte) 1, amt, d,0.0,dis);
       }
   }
   public void overDraft(double amt,String dis){
       if(amt<balance){
           this.balance = balance - amt;
           Date d = new Date();
           double charges = customer.getOverDraftCharges(amt);
           this.addTransaction((byte) 1, amt, d,charges,dis);
       }
   }
   public void addInterest(){
       Date d = new Date();
       double amt = customer.getSavingsIntrest()*balance;
       this.addTransaction((byte) 2, amt, d,0.0,"Interest have been added to the account.");  
   }

}

CheckingAccount.java

import java.util.Date;


public class CheckingAccount extends Account{

   public CheckingAccount(Customer c, double balance) {
       super(c, balance);
   }
  
   public void deposit(double amt,String dis){
       if(amt>0){
           this.balance = balance + amt;
           Date d = new Date();
           this.addTransaction((byte) 0, amt, d,0.0,dis);
       }
   }
   public void withdraw(double amt,String dis){
       if(amt<balance){
           this.balance = balance - amt;
           Date d = new Date();
           double charge = customer.getCheckCharge();
           this.addTransaction((byte) 1, amt, d,charge,dis);
       }
   }
   public void overDraft(double amt,String dis){
       if(amt<balance){
           this.balance = balance - amt;
           Date d = new Date();
           double charges = customer.getOverDraftCharges(amt);
           this.addTransaction((byte) 1, amt, d,charges,dis);
       }
   }
   public void addInterest(){
       Date d = new Date();
       double amt = customer.getCheckIntrest()*balance;
       this.addTransaction((byte) 2, amt, d,0.0,"Interest have been added to the account.");  
   }

}

Bank.java


public class Bank {
   private Account[] accounts;
   private int count;
   public Bank(){
       accounts = new Account[100];
       count = 0;
   }
   public void addAccount(Account ac){
       if(count == accounts.length){
           reallocate();
           addAccount(ac);
       }
       else{
           accounts[count] = ac;
           count++;
       }
   }
   private void reallocate() {
       Account[] temp = new Account[accounts.length*2];
       for(int i=0;i<accounts.length;i++){
           temp[i]=accounts[i];
       }
       accounts = temp;
   }
   public Account getAccount(int i){
       return accounts[i];
   }
   public void makeDeposit(double amt,String dis){
       accounts[count].deposit(amt,dis);
   }
   public void makeWithdraw(double amt,String dis){
       accounts[count].withdraw(amt,dis);
   }
}

Add a comment
Know the answer?
Add Answer to:
Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your l...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.

    Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • Bank Accounts Look at the Account class Account.java and write a main method in a different...

    Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...

  • Java coding help! Write a program to simulate a bank which includes the following. Include a...

    Java coding help! Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program. Create the following classes: Bank Customer Account At a minimum include the following data fields for each class: o Bank Routing number Customer First name Last name Account Account number Balance Minimum balance Overdraft fee At a minimum write the following...

  • [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver...

    [JAVA] < Instruction> You are given two classes, BankAccount and ManageAccounts ManageAccounts is called a Driver class that uses BankAccount. associate a member to BankAcount that shows the Date and Time that Accounts is created. You may use a class Date. To find API on class Date, search for Date.java. Make sure to include date information to the method toString(). you must follow the instruction and Upload two java files. BankAccount.java and ManageAccounts.java. -------------------------------------------------------------------------- A Bank Account Class File Account.java...

  • 1- Write a code for a banking program. a) In this question, first, you need to...

    1- Write a code for a banking program. a) In this question, first, you need to create a Customer class, this class should have: • 2 private attributes: name (String) and balance (double) • Parametrized constructor to initialize the attributes • Methods: i. public String toString() that gives back the name and balance ii. public void addPercentage; this method will take a percentage value and add it to the balance b) Second, you will create a driver class and ask...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT