Question
Won't compile, please help: ----------------------------------------------------------- public class Account implements Depositable, Withdrawable, Balanceable { private double balance; public Account() { balance = 0; } @Override public
Won't compile, please help:
-----------------------------------------------------------
public class Account implements Depositable, Withdrawable, Balanceable { private double balance;
public Account() { balance = 0; }
@Override public void deposit(double amount) { balance += amount; }
@Override public void withdraw(double amount) { balance -= amount; }
@Override public double getBalance() { return balance; }
@Override public void setBalance(double amount) { balance = amount; } }
-----------------------------------------------------------
import java.util.Scanner;
public class Console { private static Scanner sc = new Scanner(System.in); public static String getString(String prompt) { String s = ""; boolean isValid = false; while (!isValid) { System.out.print(prompt); s = sc.nextLine(); if (s.equals("")) { System.out.println("Error! This entry is required. Try again."); } else { isValid = true; } } return s; }
public static String getString(String prompt, String s1, String s2) { String s = ""; boolean isValid = false; while (!isValid) { s = getString(prompt); if (!s.equalsIgnoreCase(s1) && !s.equalsIgnoreCase(s2)) { System.out.println("Error! Entry must be '" + s1 + "' or '" + s2 + "'. Try again."); } else { isValid = true; } } return s; } public static int getInt(String prompt) { int i = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextInt()) { i = sc.nextInt(); isValid = true; } else { System.out.println("Error! Invalid integer. Try again."); } sc.nextLine(); } return i; } public static int getInt(String prompt, int min, int max) { int i = 0; boolean isValid = false; while (!isValid) { i = getInt(prompt); if (i = max) { System.out.println( "Error! Number must be less than " + max + "."); } else { isValid = true; } } return i; } public static double getDouble(String prompt) { double d = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println("Error! Invalid number. Try again."); } sc.nextLine(); } return d; } public static double getDouble(String prompt, double min, double max) { double d = 0; boolean isValid = false; while (!isValid) { d = getDouble(prompt); if (d = max) { System.out.println( "Error! Number must be less than " + max + "."); } else { isValid = true; } } return d; } }
-----------------------------------------------------------
public class CheckingAccount extends Account { private double monthlyFee;
public CheckingAccount(double monthlyFee) { super(); this.monthlyFee = monthlyFee; }
public void subtractMonthlyFee() { double balance = super.getBalance(); double newBalance = balance - monthlyFee; super.setBalance(newBalance); }
public double getMonthlyFee() { return monthlyFee; } }
-----------------------------------------------------------
public class SavingsAccount extends Account { private double monthlyInterestRate; private double monthlyInterestPayment;
public SavingsAccount(double monthlyInterestRate) { super(); this.monthlyInterestRate = monthlyInterestRate; }
public void calculateMonthlyInterestPayment() { double balance = super.getBalance(); monthlyInterestPayment = monthlyInterestRate * balance; double newBalance = balance + monthlyInterestPayment; super.setBalance(newBalance); }
public double getMonthlyInterestPayment() { return monthlyInterestPayment; } }
-----------------------------------------------------------
public interface Balanceable { double getBalance(); void setBalance(double amount); }
-----------------------------------------------------------
public interface Depositable { void deposit(double amount); }
-----------------------------------------------------------
public interface Withdrawable { void withdraw(double amount); }
-----------------------------------------------------------
import java.text.NumberFormat;
public class AccountBalanceApp {
public static void main(String args[]) { NumberFormat currency = NumberFormat.getCurrencyInstance(); System.out.println("Welcome to the Account application ");
CheckingAccount checking = new CheckingAccount(1.0); SavingsAccount savings = new SavingsAccount(.01); checking.setBalance(1000.0); savings.setBalance(1000.0);
System.out.println("Starting Balances"); System.out.println("Checking: " + currency.format(checking.getBalance())); System.out.println("Savings: " + currency.format(savings.getBalance())); System.out.println();
System.out.println("Enter the transactions for the month ");
String choice = "y"; while (choice.equalsIgnoreCase("y")) { String transactionType = Console.getString("Withdrawal or deposit? (w/d): ", "w", "d"); String accountType = Console.getString("Checking or savings? (c/s): ", "c", "s"); Account account; if (accountType.equalsIgnoreCase("c")) { account = checking; } else { account = savings; } if (transactionType.equalsIgnoreCase("w")) { double amount = Console.getDouble("Amount?: ", 0, account.getBalance()); account.withdraw(amount); } else { // deposit double amount = Console.getDouble("Amount?: ", 0, 10000); account.deposit(amount); } System.out.println();
choice = Console.getString("Continue? (y): ", "y", "n"); System.out.println(); }
checking.subtractMonthlyFee(); savings.calculateMonthlyInterestPayment();
System.out.println("Monthly Payments and Fees"); System.out.println("Checking fee: " + currency.format(checking.getMonthlyFee())); System.out.println("Savings interest payment: " + currency.format(savings.getMonthlyInterestPayment())); System.out.println();
System.out.println("Final Balances"); System.out.println("Checking: " + currency.format(checking.getBalance())); System.out.println("Savings: " + currency.format(savings.getBalance())); System.out.println(); }
}
Needs to look like this:
Thank you!
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): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y): n Monthly Payments and Fees Checking fee: $1.00 Savings interest payment: $12.00 Final Balances Checking: $499.00 Savings: $1,212.00Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started