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...
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.
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...
I am having an issue with the Java program with a tic tac toe. it isn't...
I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
I am struggling with this java code Objectives: Your program will be graded according to the...
I am struggling with this java code Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1. Create a new project and class in Eclipse and add the main method. (10 points) 2. Construct a Scanner to read input from the keyboard. (10 points) 3. Use the Scanner to read the name, number of balls, and yards per ball of a yarn type specified by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT