Question

Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

BankAccount.java

package account;

/**
*
* @author Rand0mb0t
*/
abstract public class BankAccount {
double balance, AnnualInterestRate ;
int NumberDeposits, NumberWithdrawals, MonthlyServiceCharge;

public BankAccount(double balance, double AnnualInterestRate) {
this.balance = balance;
this.AnnualInterestRate = AnnualInterestRate;
}

public void setMonthlyServiceCharge(int MonthlyServiceCharge) {
this.MonthlyServiceCharge = MonthlyServiceCharge;
}

public double getBalance() {
return balance;
}

public double getAnnualInterestRate() {
return AnnualInterestRate;
}

public double getMonthlyServiceCharge() {
return MonthlyServiceCharge;
}

public int getNumberDeposits() {
return NumberDeposits;
}

public int getNumberWithdrawals() {
return NumberWithdrawals;
}
  
public void Deposit(double amount){
this.balance = this.balance + amount;
this.NumberDeposits += 1;
}
  
public void Withdrawal(double amount){
this.balance -= amount;
this.NumberWithdrawals += 1;
}
  
public void CalculateInterest(){
double monthlyInterest = this.balance * (this.AnnualInterestRate/12);
this.balance += monthlyInterest;
}
  
public void MonthlyProcess(){
this.balance -= this.MonthlyServiceCharge;
this.CalculateInterest();
this.NumberDeposits = 0;
this.NumberWithdrawals = 0;
this.MonthlyServiceCharge = 0;
}
}

SavingsAccount.java

package account;

/**
*
* @author Rand0mb0t
*/
public class SavingsAccount extends BankAccount {
  
  
  
private boolean status ;

public SavingsAccount(double balance, double AnnualInterestRate, int MonthlyServiceCharge) {
super(balance, AnnualInterestRate);
super.setMonthlyServiceCharge(MonthlyServiceCharge);
if (super.balance >= 25){
this.status = true;
}
else
this.status = false;
}
  
public void Deposit(double amount){
super.Deposit(amount);
if(this.balance > 25){
this.status = true;
}
}
  
public void Withdrawal(double amount){
if(this.status == true){
super.Withdrawal(amount);
if(this.balance < 25)
this.status = false;
}
}
  
public void MonthlyProcess(){
if(this.NumberWithdrawals <= 4){
super.MonthlyProcess();
}
else{
super.setMonthlyServiceCharge(this.NumberWithdrawals - 4);
super.MonthlyProcess();
}
}
  
  
  
}

Driver.java

package account;

/**
*
* @author Rand0mb0t
*/
public class Driver {
  
public static void main(String args[]){
SavingsAccount sa1 = new SavingsAccount(1200, 7, 2);
SavingsAccount sa2 = new SavingsAccount(40, 6, 1);
  
// For First object of SavingsAccount
System.out.println("Your account balance : "+sa1.getBalance());
System.out.println("Your number of deposits : "+sa1.getNumberDeposits());
System.out.println("Your number of withdrawals : "+sa1.getNumberWithdrawals());
System.out.println("Your annualInterest rate is : "+sa1.getAnnualInterestRate());
System.out.println("Your Monthly Service Charge is : "+sa1.getMonthlyServiceCharge());
  
sa1.Deposit(500);
sa1.Withdrawal(900);
sa1.CalculateInterest();
sa1.MonthlyProcess();
  
System.out.println("Now your balance is : "+sa1.getBalance());
System.out.println("\n\nACCOUNT INFORMATION FOR SAVINGSACCOUNT number 2 \n\n");
// For second object of SavingsAccount
System.out.println("Your account balance : "+sa2.getBalance());
System.out.println("Your number of deposits : "+sa2.getNumberDeposits());
System.out.println("Your number of withdrawals : "+sa2.getNumberWithdrawals());
System.out.println("Your annualInterest rate is : "+sa2.getAnnualInterestRate());
System.out.println("Your Monthly Service Charge is : "+sa2.getMonthlyServiceCharge());
  
sa2.Deposit(500);
sa2.Withdrawal(900);
sa2.CalculateInterest();
sa2.MonthlyProcess();
  
System.out.println("Now your balance is : "+sa2.getBalance());
}
  
}

BankAccount.java

package account;

/**
*
* @author Rand0mb0t
*/
abstract public class BankAccount {
double balance, AnnualInterestRate ;
int NumberDeposits, NumberWithdrawals, MonthlyServiceCharge;

public BankAccount(double balance, double AnnualInterestRate) {
this.balance = balance;
this.AnnualInterestRate = AnnualInterestRate;
}

public void setMonthlyServiceCharge(int MonthlyServiceCharge) {
this.MonthlyServiceCharge = MonthlyServiceCharge;
}

public double getBalance() {
return balance;
}

public double getAnnualInterestRate() {
return AnnualInterestRate;
}

public double getMonthlyServiceCharge() {
return MonthlyServiceCharge;
}

public int getNumberDeposits() {
return NumberDeposits;
}

public int getNumberWithdrawals() {
return NumberWithdrawals;
}
  
public void Deposit(double amount){
this.balance = this.balance + amount;
this.NumberDeposits += 1;
}
  
public void Withdrawal(double amount){
this.balance -= amount;
this.NumberWithdrawals += 1;
}
  
public void CalculateInterest(){
double monthlyInterest = this.balance * (this.AnnualInterestRate/12);
this.balance += monthlyInterest;
}
  
public void MonthlyProcess(){
this.balance -= this.MonthlyServiceCharge;
this.CalculateInterest();
this.NumberDeposits = 0;
this.NumberWithdrawals = 0;
this.MonthlyServiceCharge = 0;
}
}

SavingsAccount.java

package account;

/**
*
* @author Rand0mb0t
*/
public class SavingsAccount extends BankAccount {
  
  
  
private boolean status ;

public SavingsAccount(double balance, double AnnualInterestRate, int MonthlyServiceCharge) {
super(balance, AnnualInterestRate);
super.setMonthlyServiceCharge(MonthlyServiceCharge);
if (super.balance >= 25){
this.status = true;
}
else
this.status = false;
}
  
public void Deposit(double amount){
super.Deposit(amount);
if(this.balance > 25){
this.status = true;
}
}
  
public void Withdrawal(double amount){
if(this.status == true){
super.Withdrawal(amount);
if(this.balance < 25)
this.status = false;
}
}
  
public void MonthlyProcess(){
if(this.NumberWithdrawals <= 4){
super.MonthlyProcess();
}
else{
super.setMonthlyServiceCharge(this.NumberWithdrawals - 4);
super.MonthlyProcess();
}
}
  
  
  
}

Driver.java

package account;

/**
*
* @author Rand0mb0t
*/
public class Driver {
  
public static void main(String args[]){
SavingsAccount sa1 = new SavingsAccount(1200, 7, 2);
SavingsAccount sa2 = new SavingsAccount(40, 6, 1);
  
// For First object of SavingsAccount
System.out.println("Your account balance : "+sa1.getBalance());
System.out.println("Your number of deposits : "+sa1.getNumberDeposits());
System.out.println("Your number of withdrawals : "+sa1.getNumberWithdrawals());
System.out.println("Your annualInterest rate is : "+sa1.getAnnualInterestRate());
System.out.println("Your Monthly Service Charge is : "+sa1.getMonthlyServiceCharge());
  
sa1.Deposit(500);
sa1.Withdrawal(900);
sa1.CalculateInterest();
sa1.MonthlyProcess();
  
System.out.println("Now your balance is : "+sa1.getBalance());
System.out.println("\n\nACCOUNT INFORMATION FOR SAVINGSACCOUNT number 2 \n\n");
// For second object of SavingsAccount
System.out.println("Your account balance : "+sa2.getBalance());
System.out.println("Your number of deposits : "+sa2.getNumberDeposits());
System.out.println("Your number of withdrawals : "+sa2.getNumberWithdrawals());
System.out.println("Your annualInterest rate is : "+sa2.getAnnualInterestRate());
System.out.println("Your Monthly Service Charge is : "+sa2.getMonthlyServiceCharge());
  
sa2.Deposit(500);
sa2.Withdrawal(900);
sa2.CalculateInterest();
sa2.MonthlyProcess();
  
System.out.println("Now your balance is : "+sa2.getBalance());
}
  
}

HOPE IT HELPS YOU

RATE THUMBSUP PLEASE

THANKS

Add a comment
Know the answer?
Add Answer to:
Design and implement the following 3 classes with the exact fields and methods (these names and c...
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
  • BankAccount and SavingsAccount Classes (JAVA)

    Must be in GUI interfaceDesign an abstract class namedBankAccountto hold the following data for a bankaccount:* Balance* Number of deposits this month* Number of withdrawals (this month)* Annual interest rate* Monthly service chargesThe class should have the following methods:Constructor: The constructor should accept arguments for the balance and annual interest rate.deposit: A method that accepts an argument for the amount of the deposit. The methods should add the argument to the account balance. It should also increment thevariable holding the...

  • pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank...

    pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank account and 1 for savings accounts due in 12 hours Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all the concepts previously covered. Submit the java files electronically through Canvas by the above due date in 1 Zip file Lab4.Zip. (This is from the chapter on Inheritance.) 9. BankAccount and SavingsAccount Classes Design...

  • the programing language is C++ TIC PEO. Design a generic class to hold the following information...

    the programing language is C++ TIC PEO. Design a generic class to hold the following information about a bank account! Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following member functions: Constructor: Accepts arguments for the balance and annual interest rate. deposit: A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

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

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

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