vendredi 26 août 2016

Reached end of file while parsing ERROR?

I am getting an error BankInterest(line 93): reached end of file while parsing, anyone know why i am getting this? Here is my code below so you can determine what the problem may be.

Thank you in advance.

import java.nio.file.*;
import java.util.*;
import java.io;

public class BankInterest {

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

/* TASK 1: Declare variables */

String accountType;
double principal;
double rate;
double balance;
int year;

/* Check if the expected command line is provided */

if (args.length < 1) {
/* Display the Usage */
System.out.println("Usage: java BankInterest interestRateFileName");
/* Programs quits with an error code */
System.exit(-1);
}
/* TASK 2: Read interest rates from a file */
try {

Scanner x = new Scanner(Paths.get("commbank.txt"));
System.out.println(x.nextDouble());
} catch (IOException e) {

/* TASK 3: Take user input - Which Account */

Scanner keyboard = new Scanner(System.in);
System.out.println("Which Account: ");
System.out.println("1 - Savings");
System.out.println("2 - Term Deposits");

String line = keyboard.nextLine();

if (line.equals("1")) {
accountType = "Savings";
} else if (line.equals("2")) {
accountType = "Term Deposits";
}

/* TASK 4: Take user input - Principal and Period */

Scanner input = new Scanner(System.in);
System.out.println("Principal: ");
principal = keyboard.nextDouble();

System.out.println("Years: ");
year = keyboard.nextInt();

/* TASK 5: Calculate balance for the chosen account type */

if (accountType == "Savings") {
balance = principal * Math.pow((1 + rate / 100), year);
} else if (accountType == "Term Deposits") {
balance = (principal * rate * time) / 100;
}

/* TASK 6: Display results */

if (accountType == "Savings") {
System.out.println("");
System.out.println("The Compound Interest is: " + balance);enter code here
} else if (accountType == "Term Deposits") {
System.out.println("");
System.out.println("The Simple Interest is: " + balance);
} else {
System.out.println("");
System.out.println("Error! Account is not recognized.");

} }

Aucun commentaire:

Enregistrer un commentaire