Question
design the following Java programs: BankAccount.java, Payable.java, SavingAccount.java, CheckingAccount.java and GiftCard.java. Requirements: Your Java class names must follow the names specified above. Note that they
design the following Java programs: BankAccount.java, Payable.java, SavingAccount.java, CheckingAccount.java and GiftCard.java.
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.
The constructor takes client's firstname, lastname and social security number.
The constructor should generate a number 6-digit number as the user account number.
The initial balance is 0 and the interest rate is fixed at 1.0%.
The withdraw method signature is:
public boolean withdraw(double amount).
It returns true if the amount is less or equal to the balance. Otherwise, the withdraw attempt fails and outputs a error message.The deposit method signature is:
public void deposit(double amount).
CheckingAccount: a concrete class that extends BankAccount, also implements Payable interface.
The constructor takes client's firstname, lastname, social security number and a 4-character pin.
Similary, the initial balance is 0 and its interest rate is fixed at 0.1%.
In addition, a 7-digit account number is randomly generated of a new client.
The withdraw method signature is:
public boolean withdraw(double amount).
It returns true if the amount is less or equal to the balance. Otherwise, the withdraw attempt fail s and outputs a error message.The deposit method signature is:
public void deposit(double amount).
The makePayment method signature is:
public boolean makePayment(double amount, String name, String pin).
It returns true if the amount is less or equal to the balance. And a message is printed for the payment.
It returns false if the pin check fails.
It returns false if the balance is not sufficient to make the payment.
GiftCard: a concrete class that implements Payable interface.
The constructor takes the amount and a 4-character pin number.
The makePayment method signature is:
public boolean makePayment(double amount, String name, String pin).
It returns true if the balance is sufficient and a confirmation messages is printed.
Otherwise, an error message should show the balance is not sufficient to make the payment.
Make sure your programs compile and submit your programs by following the submission instruction.
Program Template:
public abstract class BankAccount { protected String firstname; protected String lastname; protected int ssn; // implement your code } public interface Payable { public boolean makePayment(double amount, String name, String pin); } public class SavingAccount extends BankAccount { private double interest; private int acctNumber; private double balance; // implement your code } public class CheckingAccount extends BankAccount implements Payable { private double interest; private int acctNumber; private double balance; private String pin; // implement your code } public class GiftCard implements Payable { private String pin; private double balance; // implement your code }
Testing:
A test program is given below. Your programs should work with this test program. A sample result is allow provided.
public class Test { public static void main(String[] args) { BankAccount[] accts = { new SavingAccount("Cody", "Allen", 3428765), new CheckingAccount("Shane", "Bieber", 3284842, "1234"), new SavingAccount("Adam", "Cimber", 8097423)}; Payable[] items = { new CheckingAccount("Corey", "Kluber", 79872487, "4321"), new GiftCard(1000, "gift")}; accts[0].deposit(500); accts[1].deposit(1200); accts[2].deposit(1500); ((CheckingAccount)items[0]).deposit(2000); for (int i = 0; iSample Execution Results:
Withdraw Failed: balance too low... Successfully withdrew $800.0 Successfully withdrew $800.0 Paid Alonso with $2000.0 Payment Failed: wrong pin Payment Failed: balance too low Firstname: Cody Lastname: Allen Saving's Account Number: 395605 Balance: 500.0 Interest: 0.0 Firstname: Shane Lastname: Bieber Checking Account Number: 1797409 Balance: 400.0 Interest: 0.1 Pin: 1234 Firstname: Adam Lastname: Cimber Saving's Account Number: 684689 Balance: 700.0 Interest: 0.0 Firstname: Corey Lastname: Kluber Checking Account Number: 2877463 Balance: 0.0 Interest: 0.1 Pin: 4321 Gift Card Pin: gift Gift Card Balance: 1000.0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started