Question

Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all

Next, design a savingsAccount class that extends the BankAccount class. The savingsAccount class should have a status field t

pls write psuedocode
write UML CODE
ALSO

Aggregation in UML Diagrams Course ourseName : String ructor Instructor - textBook: TextBook Course(name: String, instr: Inst

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 an abstract class named BankAccount to hold the following data for a bank account: Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following methods: Constructor The constructor should accept arguments for the balance and annual interest rate. A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits. deposit: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals. withdraw A method that updates the balance by calculating the monthly inter- est earned by the account, and adding this interest to the balance. This is performed by the following formulas: calcInterest: Monthly Interest Rate (Annual Interest Rate / 12) Monthly Interest Balance Monthly Interest Rate Balance Balance+ Monthly Interest A method that subtracts the monthly service charges from the bal- ance, calls the calcInterest method, and then sets the variables that hold the number of withdrawals, number of deposits, and monthly service charges to zero. monthlyProcess:
Next, design a savingsAccount class that extends the BankAccount class. The savingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals may be made until the balance is raised above $25, at which time the account becomes active again. The savings account class should have the following methods: A method that determines whether the account is inactive before withdraw: a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method. A method that determines whether the account is inactive before a deposit: deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. A deposit is then made by calling the superelass version of the method. Before the superclass method is called, this method checks the num- ber of withdrawals. If the number of withdrawals for the month is monthlyProcess: more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges. (Don't forget to check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)
Aggregation in UML Diagrams Course ourseName : String ructor Instructor - textBook: TextBook Course(name: String, instr: Instructor, text: TextBook) getName): String +getT tor): Instructor Book): TextBook +to String) Sking Instructor TextBook lastName : String firstName : String officeNumber String title : String - author: String - publisher: String +TextBook(title : String, author : String, publisher + Instructor(Iname : String, fname: String, String) office : String) TextBook(object2 TextBook) + set(title : String, author String, publisher: String) +Instructor(object2 Instructor) +set(Iname String, fname : String, office String): void +toString) String void + toString(): String 8-3 ©2013 Pearson Education, Inc. Upper Saddle River, NJ All Rights Reserved. O Type here to search
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.awt.HeadlessException; 
import java.text.DecimalFormat; 
import javax.swing.JOptionPane; 
public class Main {  
public static class SavingsAccount extends BankAccount { 
protected boolean isActive = (super.balance > 25); 
// Constructors 
public SavingsAccount() { 
super(); 
} 
public SavingsAccount(double balance, double annualInterest) { 
super(balance, annualInterest); 
} 
public double getMonthlyCharge() { 
this.monthlyProcess(); 
return monthlyCharge; 
} 
// Monthly charge process. 
public void monthlyProcess() { 
if (super.numberOfWithdrawals > 4) { 
super.monthlyCharge += super.numberOfWithdrawals - 4; 
if (super.balance < 25) { 
this.isActive = false; 
} 
} 
} 


// Withdraw. 
public boolean withdraw(double amount) { 
if (isActive) { 
return super.withdraw(amount); 
} else { 
return false; 
} 
} 

// Deposit 
public boolean deposit(double amount) { 
super.deposit(amount); 
if ((!this.isActive) && super.balance > 25) { 
this.isActive = true; 
return true; 
} else { 
return false; 
} 

} 
public boolean getIsActive() { 
return isActive; 
} 
public void setActive(boolean isActive) { 
this.isActive = isActive; 
} 
} 
//Abstract class BankAccount
public static abstract class BankAccount { 
protected double balance; 
protected int numberOfDeposits; 
protected int numberOfWithdrawals; 
protected double annualInterest; 
protected double monthlyCharge; 

// Constructor accepts annual interest and 
// the balance. 
public BankAccount(double balance, double annualInterest) { 
this.setAnnualInterest(annualInterest);
this.setBalance(balance); 
} 
// Default constructor. 
public BankAccount() {} 

// Monthly charge process. 
public void monthlyProcess() { 
this.balance -= this.monthlyCharge; 
this.calcInterest(); 
this.monthlyCharge = 0; 
this.numberOfDeposits = 0; 
this.numberOfWithdrawals = 0; 
} 

// Calculate the interest. 
protected void calcInterest() { 
double monthlyInterestRate; 
double monthlyInterest; 

monthlyInterestRate = this.annualInterest / 12; 
monthlyInterest = this.balance * monthlyInterestRate; 
this.balance = this.balance + monthlyInterest; 
} 

// Withdraw. 
public boolean withdraw(double amount) { 
if ((this.balance > amount) && (amount > 0)) { 
this.balance -= amount; 
this.numberOfWithdrawals++; 
return true; 
} else { 
return false; 
} 
} 

// Deposit 
public boolean deposit(double amount) { 
if (amount > 0) { 
this.balance += amount; 
this.numberOfDeposits++; 
return true; 
} else { 
return false; 
} 
} 

// Accessors and mutators. 
public double getBalance() { 
return balance; 
} 

public void setBalance(double balance) { 
this.balance = balance; 
} 

public int getNumDepositsThisMonth() { 
return numberOfDeposits; 
} 

public void setNumDepositsThisMonth(int numDepositsThisMonth) { 
this.numberOfDeposits = numDepositsThisMonth; 
} 

public double getAnnualInterest() { 
return annualInterest; 
} 

public void setAnnualInterest(double annualInterest) { 
this.annualInterest = annualInterest; 
} 

public double getMonthlyCharge() { 
return monthlyCharge; 
} 

public void setMonthlyCharge(double monthlyCharge) { 
this.monthlyCharge = monthlyCharge; 
} 
public boolean getIsActive() { 
// TODO Auto-generated method stub 
return (Boolean) null; 
} 
} 

public static void main(String[] args) { 
double balance = 0; 
double annualInterest = 0; 
String output; 
String input; 
DecimalFormat df = new DecimalFormat("#0.00"); 

do { 
try { 
output = "Enter your account balance $:"; 
input = JOptionPane.showInputDialog(output); 

balance = Double.parseDouble(input); 
if (balance < 0) { 
throw new NumberFormatException(); 
} 
break; 
} catch (HeadlessException e) { 
errorMsg(); 
} catch (NumberFormatException e) { 
errorMsg(); 
} 
} while (true); 

do { 
try { 
output = "Please enter your annual interest rate: \n" 
+ "EXAMPLE: A 4% interst rate is 0.04"; 
input = JOptionPane.showInputDialog(output); 

annualInterest = Double.parseDouble(input); 
if (annualInterest < 0) { 
throw new NumberFormatException(); 
} 
break; 
} catch (HeadlessException e) { 
errorMsg(); 
} catch (NumberFormatException e) { 
errorMsg(); 
} 
} while (true); 

// Instantiate your object. 
BankAccount savings = new SavingsAccount(balance, annualInterest); 

do { 
try { 
output = "Enter the number of withdrawals:"; 
input = JOptionPane.showInputDialog(output); 

savings.numberOfWithdrawals = Integer.parseInt(input); 
if (savings.numberOfWithdrawals < 0) { 
throw new NumberFormatException(); 
} 
break; 
} catch (HeadlessException e) { 
errorMsg(); 
} catch (NumberFormatException e) { 
errorMsg(); 
} 
} while (true); 

do { 
try { 
output = "Enter the number of deposits:"; 
input = JOptionPane.showInputDialog(output); 

savings.numberOfDeposits = Integer.parseInt(input); 
if (savings.numberOfDeposits < 0) { 
throw new NumberFormatException(); 
} 
break; 
} catch (HeadlessException e) { 
errorMsg(); 
} catch (NumberFormatException e) { 
errorMsg(); 
} 
} while (true); 

// Add the interest to the balance: 
savings.calcInterest(); 

output = "Account Balance with Interest: $" + df.format(savings.getBalance()); 
output += "\nMonthly Charge that will be deducted: $" + df.format(savings.getMonthlyCharge()); 
output += "\nAccount Status: "; 
output += savings.getIsActive() ? "Is Active" : "Not Active"; 

JOptionPane.showMessageDialog(null, output); 

} 

private static void errorMsg() { 
String output; 
output = "Error: There was an error with your entry"; 
JOptionPane.showMessageDialog(null, output); 
} 
} 

BankAccount - balance double numDeposits int - numWithdrawals : int - interestRate double -monthlyServiceCharge double BankAc

Add a comment
Know the answer?
Add Answer to:
pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank...
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...

  • Design and implement the following 3 classes with the exact fields and methods (these names and c...

    Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract class named BankAccount (java file called BankAccount.java) Description Filed/Method Balance NumberDeposits NumberWithdrawals AnnualInterestRate MonthlyServiceCharge BankAccount SetHonthlyServiceCharges A method that accepts the monthly service charges as an argument and set the field value GetBalance GetNum berDeposits GetNum berWithdrawals GetAnnualinterestRate GetMonthlyServiceCharge A method that returns the monthly service charge Deposit field for the bank account balance A field for the number...

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

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

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

  • C++ Simple code please Thank you in advance B. Write a C++ program as per the...

    C++ Simple code please Thank you in advance B. Write a C++ program as per the following specifications: a. Define the class BankAccount to store a bank customer's account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

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