Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 10-1: Account Balance Calculator Update the Account Balance Calculator so its code is stored in packages. The functionality of the application should stay the

Project 10-1: Account Balance Calculator

Update the Account Balance Calculator so its code is stored in packages. The functionality of the application should stay the same.

Console

Welcome to the Account application

Starting Balances

Checking: $1,000.00

Savings: $1,000.00

Enter the transactions for the month

Withdrawal or deposit? (w/d): w

Checking or savings? (c/s): c

Amount?: 500

Continue? (y/n): y

Withdrawal or deposit? (w/d): d

Checking or savings? (c/s): s

Amount?: 200

Continue? (y/n): n

Monthly Payments and Fees

Checking fee: $1.00

Savings interest payment: $12.00

Final Balances

Checking: $499.00

Savings: $1,212.00

Specifications

Your instructor should supply you with a starting project.

Add the following packages to the application:

yourLastName.app yourLastName.interfaces yourLastName.account yourLastName.presentation

Move the Balanceable, Depositable, and Withdrawable interfaces to the interfaces package. If the IDE identifies any errors, fix them. Then run the application to make sure it still works as expected.

Move the Account, CheckingAccount, and SavingsAccount classes to the account package. Move the Console class to the presentation package. And move the AccountBalanceApp class to the app package. If the IDE identifies any errors, fix them. Then run the application to make sure it still works as expected.

code:

1) Withdrawable.java

package savingsaccountcurrentaccount;

public interface Withdrawable { /** * Withdraw. * * @param amount the amount */ void withdraw(double amount); }

2) Depositable.java

package savingsaccountcurrentaccount;

public interface Depositable { /** * Deposit. * * @param amount the amount */ void deposit(double amount); }

3) Balancable.java

package savingsaccountcurrentaccount;

public interface Balanceable { double getBalance(); /** * Sets the balance. * * @param amount the new balance */ void setBalance(double amount); }

4) Account.java

/** * */ package savingsaccountcurrentaccount;

/** * @author PC * */ public class Account implements Depositable, Withdrawable, Balanceable {

private double balance; /** * default constructor */ public Account() { super(); }

/* * (non-Javadoc) * * @see savingsaccountcurrentaccount.Balanceable#getBalance() */ @Override public double getBalance() { return balance; }

/* * (non-Javadoc) * * @see savingsaccountcurrentaccount.Balanceable#setBalance(double) */ @Override public void setBalance(double amount) { if (amount > 0) this.balance = amount; }

/* * (non-Javadoc) * * @see savingsaccountcurrentaccount.Withdrawable#withdraw(double) */ @Override public void withdraw(double amount) { if (amount > 0 && this.balance - amount > 0) this.balance = this.balance - amount; else { System.out.println("Unable to withdraw, insufficient funds.."); }

}

/* * (non-Javadoc) * * @see savingsaccountcurrentaccount.Depositable#deposit(double) */ @Override public void deposit(double amount) { if (amount > 0) setBalance(this.balance + amount); }

}

5) SavingsAccount.java

/** * */ package savingsaccountcurrentaccount;

/** * @author PC * */ public class SavingsAccount extends Account { private double monthlyIntrestRate; private double monthlyIntrestPayment; /** * * @param monthlyIntrestRate */ public SavingsAccount(double monthlyIntrestRate) { super(); this.monthlyIntrestRate = monthlyIntrestRate; } /* * returns monthly interest payment */ public double getMonthlyInterestPayment(){ return monthlyIntrestPayment; } /* * calculates and sets the monthly interest payment */ private void setMonthlyInterestPayment(){ monthlyIntrestPayment = getBalance() * monthlyIntrestRate; } /* * adds interest to balance */ public void addMonthlyInterest(){ setMonthlyInterestPayment(); setBalance(getBalance()+ monthlyIntrestPayment); }

}

6) CheckingAccount.java

/** * */ package savingsaccountcurrentaccount;

/** * @author PC * */ public class CheckingAccount extends Account { private double monthlyFee;

/** * @param monthlyFee */ public CheckingAccount(double monthlyFee) { super(); this.monthlyFee = monthlyFee; } /* * Deduces monthly charges from balance */ public void chargeMonthlyFee(){ setBalance(getBalance()- monthlyFee); }

/** * @return the monthlyFee */ public double getMonthlyFee() { return monthlyFee; }

}

7) AccountBalanceApp.java

/** * */ package savingsaccountcurrentaccount;

import java.util.Scanner;

/** * @author PC * */ public class AccountBalanceApp {

/** * @param args */ public static void main(String[] args) { //for input Scanner sc = new Scanner(System.in); //creating objects of savings and checking accounts SavingsAccount savings = new SavingsAccount(0.01); CheckingAccount checking = new CheckingAccount(1);

//starting System.out.println("Welcome to the Account Application"); char again = 'Y'; //asking for initial balances System.out.println("Starting Balances");

System.out.print("Checking: $"); checking.deposit(sc.nextDouble()); System.out.print("Savings: $"); savings.deposit(sc.nextDouble());

System.out.println("Enter the transactions for the month");

//started taking monthly transactions do { char choice; //taking choice System.out.println("Withdrawal or deposit? (w/d): "); choice = sc.next().charAt(0); if (Character.toUpperCase(choice) == 'W') {//if withdrawal //taking choice System.out.println("Checking or savings? (c/s): "); choice = sc.next().charAt(0); if (Character.toUpperCase(choice) == 'C') { //for checking System.out.println("Amount?: "); checking.withdraw(sc.nextDouble());

} else if (Character.toUpperCase(choice) == 'S') { //for savings System.out.println("Amount?: "); checking.withdraw(sc.nextDouble()); } else { //invalid System.out.println("Invalid ! choice "); }

} else if (Character.toUpperCase(choice) == 'D') { //if deposit //taking choice System.out.println("Checking or savings? (c/s): "); choice = sc.next().charAt(0); if (Character.toUpperCase(choice) == 'C') { //for checking System.out.println("Amount?: "); checking.deposit(sc.nextDouble());

} else if (Character.toUpperCase(choice) == 'S') {//for savings System.out.println("Amount?: "); savings.deposit(sc.nextDouble()); } else { //invalid System.out.println("Invalid ! choice "); }

} else { //invalid System.out.println("Invalid ! choice try again"); } //taking option System.out.println("Continue? (y/n):"); again = sc.next().charAt(0); } while (Character.toUpperCase(again) != 'N'); //loop till enterd n/N //adding monthly charges and interests savings.addMonthlyInterest(); checking.chargeMonthlyFee(); //printing monthly summary System.out.println(" Monthly Payments and Fees"); System.out.printf("Checking fee: $%.2f ",checking.getMonthlyFee()); System.out.printf("Savings interest payment: $%.2f ",savings.getMonthlyInterestPayment());

System.out.println("Final Balances"); System.out.printf("Checking: $%.2f ",checking.getBalance()); System.out.printf("Savings: $%.2f ",savings.getBalance()); sc.close(); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

9. What is the first step in writing a formal report?

Answered: 1 week ago

Question

Explain the steps involved in training programmes.

Answered: 1 week ago