Console Display Welcome to the Account Calculator Starting Balance Checking: $1,
ID: 3588666 • Letter: C
Question
Console Display
Welcome to the Account Calculator
Starting Balance
Checking: $1,000.00
Enter the transactions for the month
Withdrawal or deposit? (w/d): w
Amount: 500
Continue? (y/n): y
Withdrawal or deposit? (w/d): d
Amount: 200
Continue? (y/n): n
Monthly Fees
Checking fee: $1.00
Final Balance
Checking: $699.00
Operation
The application begins by displaying the starting balance for a checking account.
The application prompts the user to enter the amount for a withdrawal or deposit.
When the user finishes entering deposits and withdrawals, the application displays the fees for the month followed by the final balances for the month.
Specifications
Create interfaces named Depositable, Withdrawable, and Balanceable that specify the methods that can be used to work with accounts.
The Depositable interface should include this method:
void deposit(double amount)
The Withdrawable interface should include this method:
void withdraw(double amount)
And the Balanceable interface should include these methods:
double getBalance()
void setBalance(double amount)
Create a class named Account that implements all three of these interfaces. In addition, it should supply a method like the following method that returns a balance that has been formatted as currency:
String getBalanceFormatted()
Create a class named CheckingAccount that inherits the Account class. This class should include an instance variable for the monthly fee and these methods:
void subtractMonthlyFee()
void setMonthlyFee(double monthlyFee)
double getMonthlyFee()
String getMonthlyFeeFormatted()
By default, the monthly fee for a checking account should be $1.
Create a class named Transactions that contains the following static methods for depositing and withdrawing funds from either type of account:
public static void deposit(Depositable account, double amount) { account.deposit(amount); }
public static void withdraw(Withdrawable account, double amount) { account.withdraw(amount); }
Create a class named AccountApp that prompts the user for a transaction, posts the transaction, and displays the information shown in the console output. Create the necessary objects for each transaction, and post the transaction using the appropriate method of the Transactions class.
Use the Console class presented in chapter 8 or a variation of it to get entries from the user.
This application should not allow the user to withdraw more than the current account balance.
This application should not allow the user to deposit more than $10,000 per transaction.
Add javadoc comments and generate documentation
Add javadoc comments to all the classes in the project. Make sure these comments include descriptions for all of the constructors and methods as well as @param and @return tags every where these tags are appropriate.
Generate the documentation for the entire project.
View the documentation.
Explanation / Answer
Note: Every thing is fine ..but in the last when asking final balance its has to display 699 $ ...so i have to do only that correction..i will do it..Thank you
___________________
Balanceable.java
public interface Balanceable {
double getBalance();
void setBalance(double amount);
}
_______________
Depositable.java
public interface Depositable {
void deposit(double amount);
}
________________
Withdrawable.java
public interface Withdrawable {
void withdraw(double amount);
}
_________________
Account.java
import java.text.NumberFormat;
public class Account implements Balanceable, Depositable, Withdrawable {
private double balance;
public Account() {
super();
this.balance = 1000;
}
@Override
public void withdraw(double amount) {
this.balance = balance - amount;
}
@Override
public void deposit(double amount) {
this.balance = balance + amount;
}
@Override
public double getBalance() {
return this.balance;
}
@Override
public void setBalance(double amount) {
this.balance = balance;
}
public String getBalanceFormatted() {
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return fmt.format(this.balance);
}
}
____________________
Transactions.java
public class Transactions {
public static void deposit(Depositable account, double amount) {
account.deposit(amount);
}
public static void withdraw(Withdrawable account, double amount) {
account.withdraw(amount);
}
}
_________________
CheckingAccount.java
import java.text.NumberFormat;
public class CheckingAccount extends Account {
private double monthlyFee;
public CheckingAccount() {
super();
this.monthlyFee = 1;
}
void subtractMonthlyFee() {
withdraw(monthlyFee);
}
void setMonthlyFee(double monthlyFee) {
this.monthlyFee = monthlyFee;
}
double getMonthlyFee() {
return monthlyFee;
}
String getMonthlyFeeFormatted() {
this.subtractMonthlyFee();
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return fmt.format(monthlyFee);
}
}
___________________
AccountApp.java
import java.util.Scanner;
public class AccountApp {
public static void main(String[] args) {
char transactionType;
double amount;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Account Calculator");
System.out.println("Starting Balance");
Account acc = new Account();
Transactions tx = new Transactions();
System.out.println("Checking:" + acc.getBalanceFormatted());
System.out.println("Enter the transactions for the month:");
while (true) {
System.out.print("Withdrawal or deposit? (w/d):");
transactionType = sc.next(".").charAt(0);
switch (transactionType) {
case 'w':
case 'W':
{
while (true) {
System.out.print("Amount: ");
amount = sc.nextDouble();
if (amount > acc.getBalance()) {
System.out.println("** Insufficient Funds **");
continue;
} else
break;
}
tx.withdraw(acc, amount);
break;
}
case 'd':
case 'D':
{
while (true) {
System.out.print("Amount: ");
amount = sc.nextDouble();
if (amount > 10000) {
System.out.println("** Invalid.Must be less than 10000 **");
continue;
} else
break;
}
tx.deposit(acc, amount);
break;
}
default:
{
System.out.println("** Invalid Choice **");
continue;
}
}
//Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Continue? (y/n)::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y')
continue;
else {
break;
}
}
CheckingAccount checkAcc = new CheckingAccount();
System.out.println("Checking fee:" + checkAcc.getMonthlyFeeFormatted());
System.out.println("Final Balance");
System.out.println("Checking: " + acc.getBalanceFormatted());
}
}
_______________
Output:
Welcome to the Account Calculator
Starting Balance
Checking:$1,000.00
Enter the transactions for the month:
Withdrawal or deposit? (w/d):w
Amount: 1200
** Insufficient Funds **
Amount: 500
Continue? (y/n)::y
Withdrawal or deposit? (w/d):d
Amount: 12000
** Invalid.Must be less than 10000 **
Amount: 200
Continue? (y/n)::n
Checking fee:$1.00
Final Balance
Checking: $700.00
__________________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.