Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2011, 09:40 PM   PM User | #1
syronix
New Coder

 
Join Date: Oct 2011
Location: Norfolk, VA
Posts: 19
Thanks: 11
Thanked 0 Times in 0 Posts
syronix is an unknown quantity at this point
Compile errors but seems correct.

This is my second post in the past couple of hours about a compiler error, but that was my fault. This time I'm almost 100% i followed the steps correctly in the tutorial and this simple class should compile just fine. I've listed the errors as comments.
Code:
import java.util.Scanner;

class VersatileSnitSoft {

       public static void main(String args[]) {
              Scanner myScanner - new Scanner(System.in); 
             //error ';' expected line 6 ^
              double amount;
             //Now here I've set the keyword double to the variablename amount
             
            System.out.print("What's the price of a CD-ROM? ");
            amount - myScanner.nextDouble();
            //error: not a statement line 10 ^
            amount - amount + 25.00;
            //error: not a statement line 11 ^

            System.out.print("We will bill $");
            System.out.print(amount);
            System.out.println(" to your credit card.");
       }
}
any help would be greatly appreciated thank you for your time.
I really just want to know why my amount - myScanner.nextDouble(); isnt' a statement and how do I make it a statement.
I just started with variables and I by no means am good at this yet.

Last edited by syronix; 10-21-2011 at 10:18 PM.. Reason: add on to the question
syronix is offline   Reply With Quote
Old 10-21-2011, 10:44 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
These should be assignments, not subtractions.
Java is smart, it won't let you perform operations on something that would provide a distinct result without actually assigning it to something. i++ is fine, but i + 1 would require an assignment.
Fou-Lu is offline   Reply With Quote
Old 10-21-2011, 10:46 PM   PM User | #3
syronix
New Coder

 
Join Date: Oct 2011
Location: Norfolk, VA
Posts: 19
Thanks: 11
Thanked 0 Times in 0 Posts
syronix is an unknown quantity at this point
assignments

So are you saying I need to assign the variable to something for the class to call?
syronix is offline   Reply With Quote
Old 10-21-2011, 11:40 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No I'm saying these need to be assignments for the variables themselves. This class will run standalone since it already has a main method constructed. Unless I misunderstand what you mean?

This: Scanner myScanner - new Scanner(System.in); should be Scanner myScanner = new Scanner(System.in); , and same for the assignments below with the amount variable.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
syronix (10-21-2011)
Old 10-21-2011, 11:46 PM   PM User | #5
syronix
New Coder

 
Join Date: Oct 2011
Location: Norfolk, VA
Posts: 19
Thanks: 11
Thanked 0 Times in 0 Posts
syronix is an unknown quantity at this point
Thank you so much that fixed my compile errors, Honestly i thought it should look like this but I didn't want to differ from my instruction just in case i was wrong. Again thanks.
syronix is offline   Reply With Quote
Reply

Bookmarks

Tags
beginner, class, compile, error, java

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 PM.


Advertisement
Log in to turn off these ads.