Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help on creating a class and main method..

    Code:
    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...

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    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..

    Code:
    String hello = "Hello " + "Aradon";
    In the same aspect, we also have to do this with system.out's

    Code:
    System.out.println("Hello " + "Aradon");
    And if I wanted to say my age, for example, I could do this:

    Code:
    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: "
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #3
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •