View Full Version : help on creating a class and main method..

AJ Muni
09-18-2007, 12:46 AM
import java.util.Scanner;

public class Assignment_1
public static void main(String args[])
double balance; // current balance for account
double depositAmount; // amount to be deposited to account
double withdrawalAmount; // amount to be withdrawn from account
double interestRate ; // e.g 5.0 for 5% interest rate
double interestAmount;// calculated interest

Scanner input = new Scanner(System.in);

System.out.print("Please enter current balance: ");
balance = input.nextDouble();

System.out.print("Please enter deposit amount: ");
depositAmount = input.nextDouble();


THis is what I get:

Please enter your balance: i enter a number (100) then...
Please enter your deposit amount: i enter another number (100)..

How do I get it to add my initial balance with my deposit amount?

I tried this: System.out.print("Your new balance is: " balance + depositAmount); but that didnt seem to work.. I get an error saying ")" expected...

09-18-2007, 01:57 AM
When you do String Concatenation you always have to include the + operator. So if I were to create the String Hello Aradon in two seperate parts I would do..

String hello = "Hello " + "Aradon";

In the same aspect, we also have to do this with system.out's

System.out.println("Hello " + "Aradon");

And if I wanted to say my age, for example, I could do this:

int age = 23;
System.out.println("Hello Aradon! You are " + age + " years old today!");

So, in ending. Look at your system.out.println, and look at mine. What is missing after your "balance is: "

09-18-2007, 05:43 AM
I'll add another hint. You're missing a "mathematical symbol" in your System.out.print statement which is why you're getting the compilation error.