Question

In: Computer Science

I am using Java and what do you mean samples? Creation of Program Application (Development Task...

I am using Java and what do you mean samples?

Creation of Program Application (Development Task 2)

This program should use a class file you create called: SavingsAccount.

This class file should store the following information: Annual Interest Rate (this can be hardcoded) Starting Balance (use a constructor to accept this information)

Create method to add all Deposits from Deposits.txt file.

Create method to subtract all Withdrawals from Withdrawals.txt file.

Create method to calculate the interest rate which is the annual rate divided by 12, added to the balance (if positive after all records have been read and calculated).

1. The program application should have the following inputs:

Deposists.txt

Withdrawls.txt

Starting Balance 2. The program application should have the following outputs:

Ending Balance

Total Amount of Deposits

Total Amount of Withdrawals

Total interest Earned

Solutions

Expert Solution

import java.io.*;
import java.util.*;

class SavingsAccount {
        double rate;
        double balance;

        SavingsAccount(double balance) {
                this.rate = 10.0;
                this.balance = balance;
        }

        double addDeposits() throws FileNotFoundException {
                FileReader deposit = new FileReader("./Deposits.txt");
                Scanner scan = new Scanner(deposit);

                double deposits = 0.0;
                while(scan.hasNext()) {
                        double dep = Double.parseDouble(scan.next().toString());
                        this.balance += dep;
                        deposits += dep;
                }
                return deposits;
        }

        double subtractWithdrawals() throws FileNotFoundException {
                FileReader withdraw = new FileReader("./Withdrawals.txt");
                Scanner scan = new Scanner(withdraw);

                double withdrawals = 0.0;
                while(scan.hasNext()) {
                        double with = Double.parseDouble(scan.next().toString());
                        this.balance -= with;
                        withdrawals += with;
                }
                return withdrawals;
        }

        double addInterest() throws Exception {
                double monthlyRate = rate / 12.0;
                if (this.balance < 0) {
                        throw new Exception("balance cannot be negative for interest");
                }
                double interest = (this.balance * monthlyRate) / 100.0;
                this.balance += interest;
                return interest;
        }

        public static void main(String args[]) throws Exception {
                // creating an object of this class
                SavingsAccount save = new SavingsAccount(10000.0);

                // calling methods
                double deposits = save.addDeposits();
                double withdrawals = save.subtractWithdrawals();
                double interest = save.addInterest();

                System.out.println("Ending Balance = " + save.getBalance());
                System.out.println("Total Amount of Deposits = " + deposits);
                System.out.println("Total Amount of Withdrawals = " + withdrawals);
                System.out.println("Total interest Earned = " + interest);

        }

        double getBalance() {
                return this.balance;
        }

        void setBalance(double balance) {
                this.balance = balance;
        }

}

Related Solutions

Creation of Program Application (Development Task 1) This program should create two output files. You may...
Creation of Program Application (Development Task 1) This program should create two output files. You may use .txt files. Create the following files: Deposists.txt Withdrawls.txt 1. The program application should have the following inputs: Amount for Deposits (Only Accept Positive Amounts) Amount for Withdrawals (Only Accept Positive Amounts). The subsequent program will subtract the positive amount. 2. The program application should have the following outputs: Deposists.txt Withdrawals.txt Total of Deposits and Withdrawals back to the console
B. Creation of Program Application (Development Task 1) This program should ask the following questions to...
B. Creation of Program Application (Development Task 1) This program should ask the following questions to determine the number of hotdogs and buns (with minimum number of leftovers) needed for the Annual Hotdog Eating contest: Assumptions are as follows: • Hotdogs come in packages of 10. • Hotdog buns come in packages of 8. 1. The program application should have the following inputs: • How many people will be competing in the contest? • How many hotdogs will each person...
You will write a Java Application program to perform the task of generating a calendar for...
You will write a Java Application program to perform the task of generating a calendar for the year 2020. You are required to modularize your code, i.e. break your code into different modules for different tasks in the calendar and use method calls to execute the different modules in your program. Your required to use arrays, ArrayList, methods, classes, inheritance, control structures like "if else", switch, compound expressions, etc. where applicable in your program. Your program should be interactive and...
I am using NetBeans IDE Java to code and I am seeking comment to the code...
I am using NetBeans IDE Java to code and I am seeking comment to the code as well (for better understanding). Magic squares. An n x n matrix that is filled with the numbers 1, 2, 3, …, n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. Write a program that reads in 16 values from the keyboard, displays them in a 4...
in Java, I am writing a program where you need to pick a color. The color...
in Java, I am writing a program where you need to pick a color. The color must be red, blue, or green and is a user input. If they put in a different value I need the program to stop running. So I essentially need to write code that says, if variableColor does not equal "red", "blue", or "green" then I need to print the statement "invalid response" and exit the program. How can I write this?
PLEASE DO NOT OVERRIDE ANY EXCEPTIONS TASK: You want to develop a Java program that will...
PLEASE DO NOT OVERRIDE ANY EXCEPTIONS TASK: You want to develop a Java program that will allow you to keep track of a set of employees. In reviewing your employee list, you notice that your employees fall into two categories: Salaried and Hourly. The following table shows the information that you keep in your employee list for each type of employee. Field Type Salaried Hourly id int Yes Yes name String Yes Yes title String Yes No position String No...
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
Using Java. The following is a constructor I need to implement but I am not sure...
Using Java. The following is a constructor I need to implement but I am not sure how. It also must pass the Junit test. Please give reasoning while answering. public class LZWDictionary { // FIELDS // map (for ease of checking existence of entries) // list (ease of recall of an entry) LinkedHashMap<String, Integer> map; List<String> list; /** * Initializes the LZWDictionary to have an initial set of entries taken from * the set of unique characters in a provided...
IN JAVA: I am using binary and linear search methods in java. How can I Generate...
IN JAVA: I am using binary and linear search methods in java. How can I Generate a new array with 10000 elements, and initialize the elements to random values using Math.random() and how can i sort the array using Arrays.sort(). I just need examples, no exact code is necessary. The array must be of doubles.
The company I am using is Adidas, Inc for the year 2019. Your task is to...
The company I am using is Adidas, Inc for the year 2019. Your task is to determine the WACC for a given firm using what you know about WACC, as well as data you can find through research. Your deliverable is a brief report in which you state your determination of WACC, describe and justify how you determined the number, and provide relevant information as to the sources of your data. Select a publicly traded company that has debt or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT