Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Text IO && Data Validation practice] In this assignment, we will get the user?s inputs to open an SavingAccount , CheckingAccount or CDAccount . Prompt

[Text IO && Data Validation practice]

In this assignment, we will get the user?s inputs to open an SavingAccount , CheckingAccount or CDAccount .

  • Prompt in the console to get users? input for the file location to save the information.

  • Prompt in the console to get users? inputs (balance and duration) to open a CDAccount if the duration is not 0. If the duration is 0, continue to ask the user to open either a SavingAccont or CheckingAccount . After the account creation, save the account info into a text file.

  • Write two methods to validate users? input,

double getDouble (Scanner sc , String prompt) - prompt for users' input until a valid double value

int getNonNegativeInt (Scanner sc , String prompt) - prompt for users' input until a valid non-negative integer

  • The driver program will generate the account ID.

    SetAnnualInterestRate= 3%, every three months duration the CDAccountCD annual interest rate will raise by 0.5%. For a SavingAccount the AnnualInterestRate is 3%, and 0% for a CheckingAccount.

  • Write the account number, balance, annual interest rate and account type into the text file that the user specify.

  • By the end of the driver program, format and print out the accounts info reading from the file in the console.

  • The user will provide info to create at least three accounts.

  • The text file will be created under the project (under the workspace) directory

  • COMSC255_FA18accou SWE212_...aFX_Ch16bin SWE212_...ntHandling accounts.txt 1001 1000.00 5.000 1002 2000.00 0.000 CheckingAccoPlease enter the file name: accounts.txt Provide the following information to open an Account Enter the initial deposit amoun

    public abstract class Account { ? ?private int id; private double balance; private static double annualInterestRate = 0.003; private java.util.Date dateCreated;

    ? ?protected Account() { ? ? ? ?id = 0; balance = 0; dateCreated = new Date(); ? ?}

    ? ?protected Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } ? ? ?protected void setBalance(double balance) { this.balance = balance; } ? ? ?public double getBalance() { return balance; } ? ? ? ?public void setId(int id) { this.id = id; } ? ? ? public int getId() { return id; } ? public static void setAnnualInterestRate(double annualInterestRate) { Account.annualInterestRate = annualInterestRate; } ? public static double getAnnualInterestRate() { return annualInterestRate; }

    public void setdateCreated(Date dateCreated) { ? ?this.dateCreated = dateCreated; } ? public Date getDateCreated() { return dateCreated; }

    public double getMonthlyInterestRate() { return annualInterestRate / 12 ; }

    public double getMonthlyInterest() { return balance * getMonthlyInterestRate() / 100; } ? public void withdraw(double amount) { balance -= amount; }

    public void deposit(double amount) { balance += amount; } ? @Override ? ?public String toString() { ? ?return "Account id: " + getId() + " Account balance: " + getBalance(); ? ? ? ? ? ? ? ? ? ? ?} ? @Override public boolean equals(Object o) { ? ?if ( o instanceof Account) { ? ? ? ?return (this.id == ((Account)o).id); ? ? ? ?} ? ?return false; ? ?} ? }

  • public class Checking extends Account{ ? ?private static double minBalance; ? ? ?public Checking(int id, double balance) { ? ? ? ?super(id, balance); ? ? ? ?minBalance = 0; ? ?}

    ? ?public static double getMinBalance() { return minBalance; } ? ? ?@Override ? ?public double getMonthlyInterest() { return getBalance() * getMonthlyInterestRate() / 12; } ? ? ?@Override public final void withdraw(double amount) { if (getBalance() System.out.println(toString()); System.out.println("Unable to perform withdraw."); System.out.println("No sufficient balance to perform the withdraw"); return; }

    setBalance(getBalance() - amount); System.out.println(toString()); System.out.println("Withdraw complete."); }

    ? ? ?@Override ? ?public String toString() { ? ?return "Account id: " + getId() + ", Account balance: $ " + getBalance(); ? ? ? ? ? ? ? ? ? ? ?} }

  • public class Saving extends Account{ ? ?private int numberWithdraw; ? ?private static double minBalance; ? ?private static int maxWithdraw;

    ? ?public Saving(int id, double balance) { ? ? ? ?super(id, balance); ? ? ? ?minBalance = 300; ? ?} ? ? ?public static double getMinBalance() { return minBalance; } ? ? ?public static double getMaxWithdraw() { ? ? ? ?return maxWithdraw; } ? ? ?public int getNumberWithdraw() { ? ? ? ?return numberWithdraw; ? ?} ? ? ?public void setNumberWithdraw(int numberWithdraw) { this.numberWithdraw = numberWithdraw; } ? ? ?@Override ? ?public double getMonthlyInterest() { return getBalance() * getMonthlyInterestRate() / 12; } ? ? ?@Override public final void withdraw(double amount) { if (getBalance() System.out.println(toString()); System.out.println("Unable to perform withdraw."); System.out.println("No sufficient balance to perform the withdraw"); return; }

    if ((getBalance() - amount) System.out.println(toString()); System.out.println("Unable to perform withdraw."); System.out.println(String.format("A SavingAccount should maintain a minimum balance of $%.01f", minBalance)); return; }

    if (numberWithdraw >= 3) { System.out.println(toString()); System.out.println("Unable to perform withdraw."); System.out.println("A SavingAccount can withdraw a maximum of 3 times in a month."); return; }

    numberWithdraw++; setBalance(getBalance() - amount); System.out.println(toString()); System.out.println("Withdraw complete."); } ? ? ?@Override ? ?public String toString() { ? ?return "Account id: " + getId() + ", Account balance: $ " + getBalance(); ? ? ? ? ? ? ? ? ? ? ?} ? }

COMSC255_FA18 SWE212_...aFX_Ch16 SWE212_...ntHandling C accounts.txt bin build.fxbuild src O 1001 1002 1003 1004 1000.00 5.000 CDAccount 2000.00 0.000 CheckingAccount 3000.00 3.000 SavingAccount 4000.00 4.000 CDAccount Please enter the file name: accounts.txt Provide the following information to open an Account Enter the initial deposit amount ($): 1000 Enter the account duration (months), 0 to open a Saving or Checking Account: 12 Enter 1 to open another Account: 1 Enter the initial deposit amount ($): 2000 Enter the account duration (months), 0 to open a Saving or Checking Account: 0 Enter 1 to open a Saving Account, 2 to open a Checking Account: 2 Enter 1 to open another Account: 1 Enter the initial deposit amount ($): 3000 Enter the account duration(months), 0 to open a Saving or Checking Account: 0 Enter 1 to open a Saving Account, 2 to open a Checking Account: 1 Enter 1 to open another Account: 1 Enter the initial deposit amount ($): 4000 Enter the account duration (months), 0 to open a Saving or Checking Account: 6 Enter 1 to open another Account: 0 Account Number Initial_Balance ($) Annual_Interest Rate(%) Account_Type ===============: 1001 1002 1003 1004 1000.00 2000.00 3000.00 4000.00 ============== 5.00 0.00 3.00 4.00 =================== CDAccount CheckingAccount SavingAccount CDAccount

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

This program takes too much time to complete The amount thats mentioned033 is very small amount to answer this question However I have answered it Ple... 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

Information Technology Auditing

Authors: James A. Hall

4th edition

1133949886, 978-1305445154, 1305445155, 978-1133949886

More Books

Students also viewed these International, Global, Thematic questions

Question

8. Communication scholars start with an inter-

Answered: 1 week ago