Question

In: Computer Science

For an application of your choice, describe the problem you aim to solve, design the necessary...

For an application of your choice, describe the problem you aim to solve, design the necessary classes, and implement your design using Java. Your programs should contain at least two classes, and a driver class in which you demonstrate the functionality of your application.

You are required to submit the following documents at the completion of your project in Module 8:

  • Documentation of the project, containing the algorithm, produced in pseudocode or flowchart, as well as the UML diagram representing the class structure of the program.
  • All files that are part of the project, including source code with the appropriate internal documentation.
  • A file containing snapshots of the running program, or a short video showing the running program.

Solutions

Expert Solution

SOLUTION :-

Created 3 classes BankAccount, SavingsAccount, CheckingAccount and a driver class Driver.java.

BankAccount.java consists of basic bank account details including account number, balance, created date and a static variable numAccounts which keeps the track of created accounts. It has methods to deposit, withdraw and the required getters and a toString method.

SavingsAccount.java is extended from BankAccount. So it has an additional variable interestRate and a method to calculate interest rate as per the current balance.

CheckingAccount.java is also extended from BankAccount, with an additional monthlyFee attribute and deductFee() method.

The driver class will prompt the user to create one SavingsAccount object and one CheckingAccount object with initial balance, and performs several operations with it.

Javadoc comments are included and feel free to ask if you have any doubts.

//BankAccount.java

import java.util.Calendar;

import java.util.Date;

public class BankAccount{

      private static int numAccounts;

      protected int accNumber;

      protected double balance;

      protected Date createdDate;

      public BankAccount(double initbalance) {

            numAccounts++;

            accNumber = numAccounts;/*

                                          * so that each time an account gets created, it'll

                                          * get a new ID

                                          */

            balance = initbalance;

            createdDate = Calendar.getInstance().getTime();

      }

      /**

      * method to deposit amount

      */

      public void deposit(double add) {

            balance += add;

      }

      /**

      * method to withdraw amount

      */

      public void withdraw(double minus) {

            balance -= minus;

      }

      /**

      * required getters

      */

      public int getAccountNumber() {

            return accNumber;

      }

      public double getBalance() {

            return balance;

      }

      public Date getCreatedDate() {

            return createdDate;

      }

      /**

      * returns a string containing all data

      */

      @Override

      public String toString() {

            return "Account Number: " + accNumber + ", Balance: " + balance

                        + ", Date Created: " + createdDate.toString();

      }

}

//SavingsAccount.java

/**

* basic savings account class

*/

public class SavingsAccount extends BankAccount {

      private double interestRate;

      public SavingsAccount(double initbalance, double interestRate) {

            super(initbalance);

            this.interestRate = interestRate;

      }

      /**

      * returns the calculated interest amount (wont update the balance)

      */

      public double calculateInterest() {

            return getBalance() * interestRate/100;

      }

      /**

      * getter and setter for interest rate

      */

      public double getInterestRate() {

            return interestRate;

      }

      public void setInterestRate(double interestRate) {

            this.interestRate = interestRate;

      }

      /**

      * returns a string containing all data

      */

      @Override

      public String toString() {

            return super.toString() + ", Interest Rate: " + interestRate;

      }

}

//CheckingAccount.java

/**

* checking account class

*/

public class CheckingAccount extends BankAccount {

      private double monthlyFee;

      public CheckingAccount(double initbalance, double monthlyFee) {

            super(initbalance);

            this.monthlyFee = monthlyFee;

      }

      public void deductFee() {

            balance -= monthlyFee;

      }

      public double getMonthlyFee() {

            return monthlyFee;

      }

      public void setMonthlyFee(double monthlyFee) {

            this.monthlyFee = monthlyFee;

      }

      /**

      * returns a string containing all data

      */

      @Override

      public String toString() {

            return super.toString() + ", Monthly Fee: " + monthlyFee;

      }

}

//Driver.java

import java.util.Scanner;

public class Driver {

      public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);

            try {

                  System.out.println("Enter the amount of money to create a SavingsAccount");

                  double amount = Double.parseDouble(scanner.nextLine());

                  System.out.println("Enter the interest rate of the SavingsAccount");

                  double interest = Double.parseDouble(scanner.nextLine());

                  /**

                  * creating a saving account using input data

                  */

                  SavingsAccount savings = new SavingsAccount(amount, interest);

                  System.out.println("Savings account created,\n" + savings);

                  System.out.println("Enter the amount of money to create a CheckingAccount");

                  amount = Double.parseDouble(scanner.nextLine());

                  System.out.println("Enter the monthly fee of the CheckingAccount");

                  double fee = Double.parseDouble(scanner.nextLine());

                  /**

                  * creating a checking account using input data

                  */

                  CheckingAccount checking = new CheckingAccount(amount, fee);

                  System.out.println("Checking account created,\n" + checking);

                  System.out.println("Amount to deposit into the SavingsAccount?");

                  amount = Double.parseDouble(scanner.nextLine());

                  /**

                  * depositing amount to savings account

                  */

                  savings.deposit(amount);

                  System.out.println("Amount deposited,\n" + savings);

                  System.out.println("Amount to withdraw from the CheckingAccount?");

                  amount = Double.parseDouble(scanner.nextLine());

                  /**

                  * withdrawing amount from checking account

                  */

                  checking.withdraw(amount);

                  System.out.println("Amount withdrawn,\n" + checking);

                  System.out.println("Calculating and adding interest of SavingsAccount.");

                  /**

                  * calculating the interest amount depositing amount to savings

                  * account

                  */

                  double i = savings.calculateInterest();

                  savings.deposit(i);

                  System.out.println("Deducting monthly fee from CheckingAccount.");

                  /**

                  * deducting monthly rate from checking acc

                  */

                  checking.deductFee();

                  /**

                  * displaying final summary

                  */

                  System.out.println(savings);

                  System.out.println(checking);

            } catch (Exception e) {

                  System.out.println("Invalid input, program is quitting...");

                  System.exit(1);

            }

      }

}

/*output*/

Enter the amount of money to create a SavingsAccount

120

Enter the interest rate of the SavingsAccount

7

Savings account created,

Account Number: 1, Balance: 120.0, Date Created: Tue Dec 05 09:19:35 IST 2017, Interest Rate: 7.0

Enter the amount of money to create a CheckingAccount

250

Enter the monthly fee of the CheckingAccount

40

Checking account created,

Account Number: 2, Balance: 250.0, Date Created: Tue Dec 05 09:19:47 IST 2017, Monthly Fee: 40.0

Amount to deposit into the SavingsAccount?

300

Amount deposited,

Account Number: 1, Balance: 420.0, Date Created: Tue Dec 05 09:19:35 IST 2017, Interest Rate: 7.0

Amount to withdraw from the CheckingAccount?

200

Amount withdrawn,

Account Number: 2, Balance: 50.0, Date Created: Tue Dec 05 09:19:47 IST 2017, Monthly Fee: 40.0

Calculating and adding interest of SavingsAccount.

Deducting monthly fee from CheckingAccount.

Account Number: 1, Balance: 449.4, Date Created: Tue Dec 05 09:19:35 IST 2017, Interest Rate: 7.0

Account Number: 2, Balance: 10.0, Date Created: Tue Dec 05 09:19:47 IST 2017, Monthly Fee: 40.0


Related Solutions

Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
Can anyone use python to solve this problem: Part B: List of lists The aim of...
Can anyone use python to solve this problem: Part B: List of lists The aim of Part B is to learn to work with list of lists. You may want to open the file lab05b_prelim.py in the editor so that you can follow the task description. The first part of the file lab05b_prelim.py defines a variable called datasets. The variable datasets is a list of 4 lists. This part consists of 2 tasks. Task 1: We ask you to type...
For your final project, you are to create a two-page web application of your choice. ASP.NET...
For your final project, you are to create a two-page web application of your choice. ASP.NET : C# You must include the following items: At least 5 different standard server controls At least 2 validation controls At least 1 navigation control ~ one must navigate back and forth to each page One session state element Upon completion of your two-page web application, you will provide a two page report describing the functions of the web application as well as each...
Describe a simple database of your choice or design, along with the table/s representing the data,...
Describe a simple database of your choice or design, along with the table/s representing the data, and illustrate the Insertion Anomaly through the real data or records there. Your database should be different from those already covered in the lectures or practicals.
For the topic choose an 'application' for using the model to solve a business problem. (In...
For the topic choose an 'application' for using the model to solve a business problem. (In what area could you see applying some of the strategies presented in the chapter, and audio. Provide a short example and set up the problem solution. 1) What is Queuing Queuing: a) Where would you apply some of this knowledge? b) Provide a quick setup with all the variables of the application you chose.
Discuss how your organization could use an operations management linear programming application to solve a problem...
Discuss how your organization could use an operations management linear programming application to solve a problem or improve a business process.
Discuss how your organization could use an operations management linear programming application to solve a problem...
Discuss how your organization could use an operations management linear programming application to solve a problem or improve a business process.
You are required to design a VoIP application. Discuss the requirements for such an application in...
You are required to design a VoIP application. Discuss the requirements for such an application in terms of its protocols and performance requirements. What types of protocols you would need to design a complete VoIP application (Hint: real time streaming protocols and signaling protocols, etc.)? [5 Marks] 2. Discuss the architecture of messanging app in terms of its protocols. Address and discuss all the essential protocols used by messaging app for communication.
You are tasked to design an application to keep track of sales for your company. Sales...
You are tasked to design an application to keep track of sales for your company. Sales should be tracked for two types of accounts: supplies and services. Complete the following:     Create a UML class diagram for the Account inheritance hierarchy. Your subclasses should be Supplies and Services.     All sales accounts will have an account ID (accountId).     You will need attributes to keep track of the number of hours (numberOfHours) and rate per hour of services provided (ratePerHour)....
1. You are required to design a VoIP application. Discuss the requirements for such an application...
1. You are required to design a VoIP application. Discuss the requirements for such an application in terms of its protocols and performance requirements. What types of protocols you would need to design a complete VoIP application (Hint: real time streaming protocols and signaling protocols, etc.)? [5marks] 2. Discuss the architecture of WhatsApp in terms of its protocols. Address and discuss all the essential protocols used by WhatsApp for communication. [5 Marks]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT