Hello,

I just needed some help with a code error. When I compile the code below, I keep getting this error:

Program2.java:12: error: ';' expected
Scanner keyboard = new Scanner(System.in);

1 error

Could somebody please let me know what I am doing wrong?

Thanks.

import java.util.Scanner;       // Needed for Scanner class
import java.text.DecimalFormat; // Needed for decimal place amounts

public class Program2
{
public static void main(String[] args)
{
BankAccount account;            // To reference a BankAccount object
double balance,                 // The acounts's starting balance interest rate

// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);

// Create an object for dollars and cents
DecimalFormat formatter = new DecimalFormat ("#0.00");

// Get the starting balance. 
System.out.print("What is your account's " + "starting balance? "); 
balance = keyboard.nextDouble(); 

// Get the Annual interest rate. 
System.out.print("What is your annual interest rate? "); 
interestRate = keyboard.nextDouble(); 

// Create a BankAccount object. 
account = new BankAccount(balance, interestRate); 

// Get the amount of pay for the month. 
System.out.print("How much were you paid this month? "); 
pay = keyboard.nextDouble(); 

// Deposit the user's pay into the account. 
System.out.println("We will deposit your pay " + "into your account."); 
account.deposit(pay); 
System.out.println("Your current balance is $" + formatter.format( account.getBalance() ));

// Withdraw some cash from the account. 
System.out.print("How much would you like " + "to withdraw? "); 
cashNeeded = keyboard.nextDouble(); 
account.withdraw(cashNeeded);

// Add the monthly interest to the account. 
account.addInterest(); 

// Display the interest earned and the balance. 
System.out.println("This month you have earned $" + formatter.format( account.getInterest() ) + " in interest.");
System.out.println("Now your balance is $" + formatter.format( account.getBalance() ) ); 
} 
}

double balance,

look at the above not comma ...should be ;

:)

It is amazing that one character can mess the whole script up. I tried your suggestion but now it gives me a whole slew of errors instead of just the original error. I think I have a lot more problems with my script than I originally thought. Anymore suggestions or help would be appreciated. Thanks.

well, if you let us know what errors you get now, we might be able to help easier

interestRate = keyboard.nextDouble();

I assume the above line gives you problems? you have to declare variables before using them.

When I tried ur code...it shows error that few of ur variables are not initialized....Please check the initialization of variables,,,

Since I dont have ur BankAccount class I get the following errors

varaibles cannot be resolved to a variable for the below variables

interestRate
pay
cashNeeded

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.