Daniel Lonarkar - 1 year ago 37

Java Question

i am new to programming, and i was wondering if i could get some help. My program stops running at

`System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on.");`

`import java.util.Scanner;`

public class Interest

{

double userInput;

double interest;

double time;

double amount;

double answer;

Scanner myScanner = new Scanner(System.in);

public static void main(String[] args)

{

System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on.");

}

{

System.out.println("Please enter your percent of interest in a decimal format: ");

userInput = myScanner.nextDouble();

if(myScanner.hasNextDouble())

{

interest = userInput;

}

else

{

System.out.println("Please enter a integer for your percent of interest.");

}

}

{

System.out.println("Please enter the time the interest is applied for: ");

userInput = myScanner.nextDouble();

if(myScanner.hasNextDouble())

{

time = userInput;

}

else

{

System.out.println("Please enter an integer for the time the interest is applied for.");

}

}

{

System.out.println("Please enter your amount of money that the interest is applied to: ");

userInput = myScanner.nextDouble();

if(myScanner.hasNextDouble())

{

amount = userInput;

}

else

{

System.out.println("Please enter an integer for the amount of money that the interest is applied to.");

}

}

{

answer = (amount * interest * time);

}

{

System.out.println("Your interest is $" + answer + ".");

System.out.println("Your total payment is $" + (answer + amount) + ".");

}

}

Answer Source

Get rid of all the extra braces; they're outside your `main`

method.

```
public static void main(String[] args)
{
System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on.");
// } <-- remove
// { <-- remove
System.out.println("Please enter your percent of interest in a decimal format: ");
// -----SKIP-----
// } <-- remove
// { <-- remove
System.out.println("Your interest is $" + answer + ".");
System.out.println("Your total payment is $" + (answer + amount) + ".");
} // leave this here (end of method)
```