0

Hi! I'm having trouble to figure out what is wrong with my program. I would appreciate if you could help me.
About the classes and their requirements to consider:
a.Create an Account class, which is the base class for all accounts that has public methods to get and set the balance as well as to withdraw, deposit, and transfer funds from one account to another.
b.Create classes for Checking and Savings that are derived from the Accounts class.
c.Create classes for Money Market and Certificate of Deposits that are derived from the Checking and Savings classes.
d.There is no penalty for withdrawing for Checking and Savings Accounts, but a $1.50 fee for Money Market Accounts and a 20% penalty of the amount withdrawn for Certificate of Deposits.

Finally, design a test class which:

a.Reads a supplied “transactions.txt” file, inputting each line of “|” delimited text into the appropriate banking object (defined above).
b.Performs the correct transaction on the account
c.Writes the resulting transaction list to an “output.txt” file, created by the test class.

So, here is how it should be:

(The Account class) Design a class named Account that contains:

• A private int data field named id for the account (default 0).
• A private double data field named balance for the account (default 0).
• A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate.
• A private Date data field named dateCreated that stores the date when the account was created.
• A no-arg constructor that creates a default account.
• A constructor that creates an account with the specified id and initial balance.
• The accessor and mutator methods for id, balance, and annualInterestRate.
• The accessor method for dateCreated.
• A method named getMonthlyInterestRate() that returns the monthly interest rate.
• A method named withdraw that withdraws a specified amount from the account.
• A method named deposit that deposits a specified amount to the account.

(The Checking class) Design a class named Checking that extends the Account class and contains:

• A constructor that creates a checking account with an initial balance.
• A method named toString that returns the following string representation of the class: “Account Type: Checking, Account #: [Account Number], Balance: [Balance], Rate: [interestRate];”

NOTE: [Text] should be replaced with actual values.

(The Savings class) Design a class named Savings that extends the Account class and contains:

• A private double data field named interestRate for the account (default 0).
• A constructor that creates a savings account with the specified interest rate.
• A method named toString that returns the following string representation of the class: “Account Type: Savings, Account #: [Account Number], Balance: [Balance], Rate: [interestRate];”

NOTE: [Text] should be replaced with actual values.

(The MoneyMarket class) Design a class named MoneyMarket class that extends the Checking class and contains:

• A private double data field named penalty for the account (default 0.2000).
• A no-arg constructor that creates a default Money Market account.
• A method named withdraw that withdraws a specified amount and a penalty from the account.
• A method named toString that returns the following string representation of the class: “Account Type: Money Market, Account #: [Account Number], Balance: [Balance], Rate: [interestRate];”

NOTE: [Text] should be replaced with actual values.

(The CertificateOfDeposit class) Design a class named CertificateOfDeposit that extends the Savings class and contains:

• A private double data field named penalty for the account (default 1.5000).
• A constructor that creates a certificate of deposit account with the specified interest rate.
• A method named withdraw that withdraws a specified amount and a penalty from the account.
• A method named toString that returns the following string representation of the class: “Account Type: Certificate of Deposit, Account #: [Account Number], Balance: [Balance], Rate: [interestRate];”

NOTE: [Text] should be replaced with actual values.

(The TextFile class) Design a class named TextFile that contains:

• A static method named read which reads the input file line by line, returning the contents of the input file in a string array (ex. String[]).
• A static method named write which writes the resultant transactions to the output file.

Each Account type must be followed by an initial balance and unique account id (at least 7 characters).
Each Deposit Amount or Withdraw Amount function must be followed by the amount value and target account id.

The output should be:
Account Type: Checking, Account Name: mycheck, Balance: $25.00
Account Type: Savings, Account Name: mysavings, Balance: $250.00, Rate: 1.50
Account Type: Money Market, Account Name: mymoney, Balance: $100.00, Rate: 0.2000
Account Type: Certificate Of Deposit, Account Name: mycertificate, Balance: $100.00, Rate 1.50

Below is what I have so far. I'm fairly new with java, so I appeciate any guidance. Thank you!

import java.util.Date;

    public class Account{

        private String id;
        private double balance = 0;
        private static double annualInterestRate = 0;
        private Date dateCreated = new Date();

        Account(){}

        Account(String Id, double Balance){
            id = Id;
            balance = Balance;
        }

            public String getId(){
            return id;
        }

        public double getBalance(){
            return balance;
        }

        public double getAnnualInterestRate(){
            return annualInterestRate;
        }

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

        public Date getDateCreated(){
        return dateCreated;
        }

        public void setId(String Id){
            id = Id;
        }

        public void setBalance(double Balance){
            balance = Balance;
        }

        public static void setAnnualInterestRate(double Rate){
            annualInterestRate = Rate;
        }

        public void withdraw(double debit) throws Exception {
            if( debit < balance ){
                balance = balance - debit;
            }else throw new Exception();

        }

        public void deposit(double credit){
            balance = balance + credit;
        }    

        public static void ValidateId(String Id) {
        if(Id.matches("[\\d]{4}"+"-"+"[\\d]{5}")) 
            System.out.println("valid id");
        else    
            System.out.println("invalid id");
         }

        public String toString(){
            return "Account Type: ";
        }
    }

public class Checking extends Account {

        public Checking( ){

        }

        public Checking( double balance ){
            super.setBalance( balance );
        }

        public Checking( String id, double balance ){
            super.setBalance( balance );
            super.setId( id );
        }

        @Override
        public String toString( ){

            return super.toString() + "Checking, Account #: " + this.getId() + ", Balance: " + this.getBalance();
        }

    }

public class Savings extends Account {

        private double dInterestRate = 0;

        public Savings( double interestRate ){
            super();

            this.dInterestRate = interestRate;
        }

        public Savings( String accountName, double interestRate, double balance){
            this.setBalance( balance );
            this.setId( accountName );
            this.dInterestRate = interestRate;
        }

        public Savings() {
                }

        @Override
        public String toString(){
            return "Account Type: Savings, Account #: " + this.getId() + ", Balance: " + this.getBalance() + ", Rate: " + dInterestRate;

        }

    }

public class MoneyMarket extends Checking {

        private static double penalty = 0.2000;
        private double balance;

             MoneyMarket(){} 

             public MoneyMarket(double balance) {
                 super.setBalance(balance);
             }

              public void withdraw(double amount){
                 balance -= amount + amount * penalty;
              }

        public MoneyMarket( String id, double balance ){
            super.setBalance( balance );
            super.setId( id );
        }

        @Override
        public String toString( ){

            return super.toString() + "MoneyMarket, Account #: " + this.getId() + ", Balance: " + this.getBalance();
        }

    }


public class CertificateOfDeposit extends Savings {

            private double penalty = 1.5000;
            private double balance = 0;
            private double dInterestRate;

             public CertificateOfDeposit(double balance) {
                 super();
                 this.dInterestRate = penalty;
                 super.setBalance(balance);
             }


              public void withdraw(double amount){
                 balance -= amount + penalty;
              }

        public CertificateOfDeposit( String id, double balance ){
            super.setBalance( balance );
            super.setId( id );
        }

        @Override
        public String toString( ){

            return super.toString() + "Certificate Of Deposit, Account #: " + this.getId() + ", Balance: " + this.getBalance() + ", Rate: " + dInterestRate;
        }

    }

    import java.util.*;


import java.io.*;

public class TextFile {

    public static void main(String[] args) throws IOException {

        {
            double num;

            File file = new File("transactions.txt");


            Scanner inputFile = new Scanner(file);
            PrintWriter outputFile = new PrintWriter("output.txt");

            while (inputFile.hasNext()) {

                {
                    num = inputFile.nextDouble();
                    if (num > 0) {
                        outputFile.println(num);

                    }
                    System.out.println(num);
                }
                inputFile.close();
                outputFile.close();
            }
        }

    }
}
2
Contributors
1
Reply
26
Views
2 Years
Discussion Span
Last Post by stultuske
1

ok .. so you posted your entire assignment (no, I didn't read all of it, way to much) and all the code you have (no, I didn't read all of that neither, since I have no idea what it is you want us to look at).

Could you please add a specific question so we know what to look for/at ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.