Log in

View Full Version : [solved] Java assignment: need help finding errors


Jess
May 31st, 2013, 03:53 PM
This is my current java code:
/* Calculate interest given the loan amount, rate, and years to be taken out
* written by Jessica Chen
* written on Friday, May 31, 2013
* Java 1.7.0_21 and Netbeans 7.3
*/
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Interest
{
public static void main (String [ ] args) {
DecimalFormat pattern = new DecimalFormat("##0.00");
double interest;
String input = JOptionPane.showInputDialog(null, "How many dollars "
+ "do you wish to borrow?");
double dollars = (double) (Double.parseDouble(input));
String input2 = JOptionPane.showInputDialog(null, "What is the "
+ "interest rate?");
double rate = (double) (Double.parseDouble(input2));
String input3 = JOptionPane.showInputDialog(null, "How many years "
+ "will you take the loan? (whole number)");
int years = (int) (Integer.parseInt(input3));
interest = dollars * years * rate/100;
JOptionPane.showMessageDialog(null, "If you borrow "
+ pattern.format(dollars) + " at an interest rate of " + rate
+ "\nfor " + years + " years, you will pay "
+ pattern.format(interest) + " in interest.");

}
}


[-]NetBeans tells me I have errors on lines 24-26 (starts with + pattern.format(dollars) ......).

On Line 24 it says ')' expected and "not a statement".
On Line 25 it says ';' expected.
On Line 26 it says ';' expected.

I really don't know where my mistake is. Help, please?[/-]

EDIT: Problem solved >_<