Question

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 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 an error message.

o The deposit method signature is:public void deposit(double amount).

 CheckingAccount: a concrete class that extends BankAccount, also implements Payable interface.

o The constructor takes client's firstname, lastname, social security number and a 4-character pin (in String type).

o Similarily, the initial balance is 0 and its interest rate is fixed at 0.1% (0.001).

o In addition, a 7-digit account number is randomly generated for a new client.

o The withdraw method signature is:
public boolean withdraw(double amount).

It deducts the corresponding amount of money on the account balance and returns true if the amount is less or equal to the balance. Otherwise, the withdraw attempt fail s and outputs an error message.

o The deposit method signature is:public void deposit(double amount).

o 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.

  •  Itreturnsfalseifthebalanceisnotsufficienttomakethepayment.

 GiftCard: a concrete class that implements Payable interface.

o The constructor takes the amount and a 4-character pin number.o The makePayment method signature is:

public boolean makePayment(double amount, String name, String pin).

  •  It deducts the corresponding balance amount and 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.

 In each concrete class, you are required to override toString() method, which is orginally provided in Object class.

Program Template:

public abstract class BankAccount {
protected String firstname;
  protected String lastname;
  protected int ssn;
  // implement your code here
}

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 here
}

public class CheckingAccount extends BankAccount implements Payable { private double interest;
private int acctNumber;
private double balance;

  private String pin;
  // implement your code here
}
public class GiftCard implements Payable {
  private String pin;
  private double balance;
  // implement your code here
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

//abstract BankAccount class

public abstract class BankAccount {
protected String firstname;
protected String lastname;
protected int ssn;

abstract boolean withdraw(double amount);
abstract void deposit (double amount);

}


// SavingAccount class
public class SavingAccount extends BankAccount {
private double interest;
private int acctNumber;
private double balance;

SavingAccount(String firstname, String lastname, int ssn){
    this.firstname= firstname;
    this.lastname= lastname;
    this.ssn=ssn;
   
    // It will generate 6 digit random Number.
   
    Random rnd = new Random();
acctNumber= 100000 + rnd.nextInt(899999);
    balance=0;
    this.interest=0.01;
   
  
   
   
}

public boolean withdraw (double amount){
if(balance>=amount){
    balance=balance-amount;
    System.out.println(" Amount Withdrawn");
    return true;
}
else{
    System.out.println("insufficient balance");
    return false;
}
   
}

public void deposit(double amount){
    balance=balance+amount;
}

public String toString(){
    return firstname + " "+ lastname+ " " + ssn +" "+ acctNumber+ " " + balance;
   
}
}

//CheckingAccount class

public class CheckingAccount extends BankAccount implements Payable {
private double interest;
private int acctNumber;
private double balance;
private String pin;
   CheckingAccount(String firstname, String lastname, int ssn, String pin){
     this.firstname=firstname;
     this.lastname=lastname;
     this.ssn=ssn;
     this.pin=pin;
     this.balance=0;
     this.interest=0.001;
    
     // It will generate 7 digit random Number.
   
    Random rnd = new Random();
    int acctNumber= 1000000 + rnd.nextInt(8999999);
   }
  
   public boolean withdraw (double amount){
if(balance>=amount){
    balance=balance-amount;
    System.out.println(" Amount Withdrawn");
    return true;
}
else{
    System.out.println("insufficient balance");
    return false;
}
   
}

public void deposit(double amount){
    balance=balance+amount;
}

   public boolean makePayment(double amount, String name, String pin){
     if(amount<=balance && this.pin==pin){
       balance=balance-amount;
       System.out.println("Payment made");
       return true;
     }
     else(amount<=balance && this.pin !=pin){
       System.out.println("Pin match failed");
       return false;
     }
    
     else{
       System.out.println("Insufficient balance");
       return false;
     }
   }
  
   public String toString(){
    return firstname + " "+ lastname+ " " + ssn +" "+ acctNumber+ " " + balance;
   
}

}

//GiftCard class

public class GiftCard implements Payable {
private String pin;
private double balance;


GiftCard(String pin, double balance){
    this.pin=pin;
    this.balance=balance;
}

public boolean makePayment(double amount, String name, String pin){
     if(amount<=balance && this.pin==pin){
       balance=balance-amount;
       System.out.println("Payment made");
       return true;
     }
     else(amount<=balance && this.pin !=pin){
       System.out.println("Pin match failed");
       return false;
     }
    
     else{
       System.out.println("Insufficient balance");
       return false;
     }
   }
  
   public String toString(){
  
    return balance +" ";

}
}

Add a comment
Know the answer?
Add Answer to:
Requirements:  Your Java class names must follow the names specified above. Note that they are...
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
  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • 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...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a...

    java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...

  • java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a...

    java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...

  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields...

  • For this lab you must write a complete class in C++. This will be a class...

    For this lab you must write a complete class in C++. This will be a class named BankAccount. This class must have the following private variables: 1. accountHolderName : string 2. balance : double 3. interestRate: double This class must have the following public constructor: 1. BancAccount(name : string, balance : double, rate : double) This class must have the following public member functions: 1. getAccountHolderName() : string a. returns the account holders name 2. getBalance() : double a. returns...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

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