# Code problems! HELP :)

• March 14th, 2013, 07:38 PM
Code problems! HELP :)
Sup fellas!

Here is the code:

Code :

```import java.util.Scanner; public class Paint { public static void main(String[] args) { final int COVERAGE = 350; //paint covers 350 sq ft/gal   //declare integers length, width, and height; String length; String width; String height;   //declare double totalSqFt; Double totalSqFt; //declare double paintNeeded; Double paintNeeded;   //declare and initialize Scanner object //Prompt for and read in the length of the room Scanner len; System.out.println("Enter the length of the room: "); length = len.next();   //Prompt for and read in the width of the room Scanner wid; System.out.println("Enter the width of the room: "); width = wid.next();   //Prompt for and read in the height of the room Scanner hei; System.out.println("Enter the hight of the room: "); height = hei.next();   //Compute the total square feet to be painted--think //about the dimensions of each wall   totalSqFt = (len * hei) + (wid * hei);   //Compute the amount of paint needed   paintNeeded = totalSqFt - 350;   //Print the length, width, and height of the room and the //number of gallons of paint needed.   System.out.println("The length is "+len); System.out.println("The width is "+wid); System.out.println("The height is "+hei); System.out.println("The number of gallons of paint needed is: "+paintNeeded); } }```

The comments in the code are telling you what are you supposed to do..
• March 14th, 2013, 07:58 PM
curmudgeon
Re: Code problems! HELP :)
Quote:

....
The comments in the code are telling you what are you supposed to do..

First and foremost, I think that you'll want to go into detail on just what problems you may be having. The better and more informative your question, usually the better and more informative our answers can be. Also consider editing your original post and surrounding your posted code with [code] [/code] tags so that it retains its formatting and is readable.
• March 14th, 2013, 08:05 PM
Re: Code problems! HELP :)
Mmm actually I was looking how to put the code to look better but I couldn't find it. Sorry I'm new here :).. I guess now it looks better

So the thing is when I go to Compile the code in the line where is my equation totalSqFt = (len * hei) + (wid * hei); it says me that the bold thing has bad operand types for binary operator '*'..
• March 14th, 2013, 10:23 PM
curmudgeon
Re: Code problems! HELP :)
What type of variable is hei?

--- Update ---

Note: I know the answer to this question, but I want YOU to see why this is important. ;)
• March 15th, 2013, 05:16 AM
Tamilarasi
Re: Code problems! HELP :)

you refer this link:How to use the Scanner class in java? - Stack Overflow
• March 15th, 2013, 05:45 AM
angstrem
Re: Code problems! HELP :)
Seems that len, wid, hei all point to null. You haven't created your scanners. And than you try to perform mathematical operations on that scanners or print them out, which is incorrect... You have height, width and length variables for that purposes. Actually, you can't perform mathematical operations on objects such as Scanner (with certain exceptions like Integer, String).
• March 17th, 2013, 08:57 PM
Re: Code problems! HELP :)
Code :

```import java.util.Scanner; public class Paint { public static void main(String[] args) { final int COVERAGE = 350;   Scanner len = new Scanner(System.in); System.out.println("Enter the length of the room: "); int length = len.nextInt();   Scanner wid = new Scanner(System.in); System.out.println("Enter the width of the room: "); int width = wid.nextInt();   Scanner hei = new Scanner(System.in); System.out.println("Enter the height of the room: "); int height = hei.nextInt();   //Compute the total square feet to be painted--think //about the dimensions of each wall   Double totalSqFt = (length*height)+(width*height);   //Compute the amount of paint needed   Double paintNeeded = totalSqFt - 350;   //Print the length, width, and height of the room and the //number of gallons of paint needed.   System.out.println("The length is "+length); System.out.println("The width is "+width); System.out.println("The height is "+height); System.out.println("The number of gallons of paint needed is: "+paintNeeded); } }```

Alright, my code looks like this now.. I guess that I did good job with scanners but I don't really understand what am I supposed to do with the equation.. now the error is: Double totalSqFt = (length*height)+(width*height); and it says "incompatible types"... Someone help, please :)
• March 17th, 2013, 09:01 PM
Norm
Re: Code problems! HELP :)
Could you copy and post the full text of the compiler's error message?
• March 17th, 2013, 09:08 PM
Re: Code problems! HELP :)
"There was an expression of a certain type required here.
You provided an expression of a different type that is not
compatible. (E.g. you wrote a String an int was expected)."
• March 17th, 2013, 09:25 PM
Norm
Re: Code problems! HELP :)
That's a strange error message from the compiler. Not very specific.
Here is a sample of what I get from the compiler:
Code :

```TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^```
• March 17th, 2013, 09:43 PM
Re: Code problems! HELP :)
I'm using BlueJ IDE and when I click on Compile it says me incompatible types.. So, now I'm lost :)
• March 17th, 2013, 09:47 PM
curmudgeon
Re: Code problems! HELP :)
If you're getting a new error and need help, you should print the full error message here as well as show the lines of text involved. At this point we shouldn't have to be reminding you to do this.
• March 17th, 2013, 09:48 PM
Norm
Re: Code problems! HELP :)
You need to find out how to use your IDE so it will give you full texted error messages. Or how to have it give you more details about what the problem is.

Quote:

it says me incompatible types.
The compiler will say what type was found and what type is required.

Or use the javac command in a command prompt window to get full error messages.
• March 19th, 2013, 04:15 PM
StephenCoyle
Re: Code problems! HELP :)
Quote: