Question: please help with this assignement i have already written something but it does not produce an output as intended please update the code that i

please help with this assignement i have already written something but it does not produce an output as intended please update the code that i have written.

For this assignment you are required to design an algorithm or pseudocode and then develop a Java program to read a series of data from an input file and process the data for a group of people. Your program calculates the interest and print the details to the monitor, refer to the sample below. Terminate the program when the end of the file is reached. Prompt user for the data file name, open, read and process the data. Refer to the sample file below for the file organization. In this assignment there is no need to verify data. Your program will calculate the interest paid on the amount of money on deposit based on the number of years it has been on deposit amount, the associated interest rate, and number of times the interest is paid per year. The interest rate to be used on the deposit is based on the following schedule:

 Time on Deposit Interest Rate >= 5 years 4.5% Less than 5 and >=4 years 4% Less than 4 and >=3 years 3.5% Less than 3 and >=2 years 2.5% Less than 2 and >=1 years 2% Less than 1 year 1.5% 

The program will use the read code to determine the number of times compound interest is calculated and paid per year.

 Code Number of times calculated A 4 B 2 C 1 D 12 E 365 

Compute the interest using the following formula: ----> A = P(1+ r/n)^nt P = principal amount (the initial amount you borrow or deposit) r = annual rate of interest (as a decimal) t = number of years the amount is deposited or borrowed for. A = amount of money accumulated after n years, including interest. n = number of times the interest is compounded per year

Example:

An amount of $1,500.00 is deposited in a bank paying an annual interest rate of 4.3%, compounded quarterly. What is the balance after 6 years?

Solution: Using the compound interest formula, where P = 1500, r = 4.3/100 = 0.043, n = 4, t = 6. Therefore, Calculation: A = 1500(1+0.043/4)^(4 * 6) So, the balance after 6 years is approximately $1,938.84. Requirements:

  • Name the class CalcInterest and save it in a Java file named CalcInterest.java
  • Prompt user for file names
  • include minimum of 4 Methods, more is OK
  • Use good variable names
  • Must use arrays, assumes there are maximum 20 customers, but could be less. Make the arrays of size 20.

Output

Display the original deposit, years on deposit, the interest earned and the new balance (initial deposit +interest) in a table form. Your program will prompt user for the name of input and output files and will process all the data.

Refer to the samples below for input file organization and the output format to the monitor and the output file.

Input file format:

Name Amount deposited Years Code 

Input file sample:

Joseph Cardian III 1800 6 A Nancy Brown 6780 10 a 

Sample output 1

Enter Input File name: assign3.txt Enter Output File name: out.txt Name Years Deposit Amount Interest Earned New Balance Joseph Kardian III 6 $1500.00 $461.99 $1961.99 Nancy Brown 10 $6780.00 $3835.32 $10615.32 

Sample output 2 (Printed to the monitor only)

Enter File name: abc.txt Could not open file. Program terminated. 

Sample output 3 (Printed to the monitor only)

Enter File name: blank.txt There was no data in the file. Program terminated.

temp.txt is as follows:

Joseph Kardian III 1500 4 a Joe Karlton 1500 4 b Nancy Brown 1500 4 c Mike Hrady 1500 4 d Albert Wilson 1500 4 e

Assign1CS3.txt is as follows:

Joseph Kardian III 1500 4 a Joe Karlton 3000.00 4 A Nancy Brown 6780 6 b Mike Hrady 6780 6 C Albert Wilson 12000 12 C Mohadi Mudaber 2340 4 D Joe Ban Kei 1320 2 a Ali Mosaker 15500.85 6 d Kim Ji Yoo 7890.9 10 e Kelly Ma Tai 3456.9 4 e Larry Brownsen Jr. 78650 6 B Joseph Wilson 5500 4 E Ali Khan 30000.00 4 A Nancy Jones Brown 67800 6 A Mike Alisson 61780 2 B

my code//

import java.util.Scanner; import java.io.*; import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors public class Main { //method2 to take input filename from user public static String InputFileName() { System.out.print("Enter file name:"); //Input FileName from user and return Scanner sc=new Scanner(System.in); return sc.nextLine(); } //method 3 to find out Interest Rate public static double InterestRate(double yearOfDeposit) { //conditions if(yearOfDeposit>=5) return 4.5; else if(yearOfDeposit>=4) return 4; else if(yearOfDeposit>=3) return 3.5; else if(yearOfDeposit>=2) return 2.5; else if(yearOfDeposit>=1) return 2; else return 1.5; } //method 4 to find number of times interest calculated public static int noOfTimeInterest(char code) { //conditions if(code=='A'||code=='a') return 4; else if(code=='B'||code=='b') return 2; else if(code=='C'||code=='c') return 1; else if(code=='D'||code=='d') return 12; else return 365; } //method 5 to calculate total earning public static double EarnedTotal(double p,double r,int n,double t) { double total_Interest=(p*(Math.pow((1+(r/(100.0*n))),(n*t)))); return total_Interest; } //method 6 open file public static void openFile(String filename) { try { //create a file Object File myObj = new File(filename); //Scanner Object to read data from file Scanner myReader = new Scanner(myObj); //if file is not empty if(myReader.hasNextLine()) { System.out.println("Name Years Deposit Amount Interest Earned Total"); //loop until file have data while (myReader.hasNextLine()) { //read a line and store in name String name = myReader.nextLine(); //read next line and store in data String data = myReader.nextLine(); //split the string to fetch different values String values[]=data.split(" "); //fetch values double Amount=Double.parseDouble(values[0]); double Deposited_Years=Double.parseDouble(values[1]); char code=values[2].charAt(0); //calling method to find InterestRate double rate=InterestRate(Deposited_Years); //calling method noOfTimeInterest int n=noOfTimeInterest(code); //total Amount double total=EarnedTotal(Amount,rate,n,Deposited_Years); total=(double) Math.round(total * 100) / 100; //calculating total_Interest by calling method InterestEarnedTotal double total_Interest=total-Amount; total_Interest=(double) Math.round(total_Interest * 100) / 100; //print output and formatting System.out.printf( "%-20s %-10.0f %10s %15s %15s %n", name, Deposited_Years,"$"+Amount,"$"+total_Interest,"$"+total); } myReader.close(); } else { System.out.println("There was no data in the file. Program terminated."); } } //if file not exists catch (FileNotFoundException e) { System.out.println("Could not open file. Program terminated."); } } public static void main(String[] args) {

//calling InputFileName to take Input File name String filename=InputFileName(); //openFile for calculation openFile(filename); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!