Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Code problems! HELP :)

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Code problems! HELP :)

    Sup fellas!

    I'm having some problems with my code.. Can you please help me out! Thanks

    Here is the 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..


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Code problems! HELP :)

    Quote Originally Posted by adi2609 View Post
    I'm having some problems with my code.. Can you please help me out! Thanks
    ....
    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.

  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    adi2609 (March 16th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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 '*'..

  5. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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.

  6. #5
    Member
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Code problems! HELP :)

    Please concentrate your scanner this is very simple issue

    you refer this link:How to use the Scanner class in java? - Stack Overflow
    Regards
    Android developer
    Trinay Technology Solutions
    http://www.trinaytech.com
    5705750475

  7. The Following User Says Thank You to Tamilarasi For This Useful Post:

    adi2609 (March 16th, 2013)

  8. #6
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default 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).

  9. The Following User Says Thank You to angstrem For This Useful Post:

    adi2609 (March 16th, 2013)

  10. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Code problems! HELP :)

    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

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Code problems! HELP :)

    Could you copy and post the full text of the compiler's error message?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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)."

  13. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  14. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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

  15. #12
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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.

  16. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #14
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: Code problems! HELP :)

    Quote Originally Posted by adi2609 View Post
    I'm using BlueJ IDE and when I click on Compile it says me incompatible types.. So, now I'm lost
    Norm I use BlueJ as well for my degree and the error it gives you is 'incompatible types', then highlight in red what code its referring to.
    i.e double miles = feet * foot;

  18. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Code problems! HELP :)

    The javac command gives more information that helps in fixing problems. Just saying look here often isn't enough.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Code problems
    By Alucard2487 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 27th, 2013, 06:02 PM
  2. problems with my code
    By poppe in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2012, 10:10 AM
  3. Problems with my code
    By poppe in forum Member Introductions
    Replies: 1
    Last Post: January 26th, 2012, 05:53 AM
  4. Problems with a code
    By oriol in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 9th, 2011, 08:02 PM
  5. Problems with Code?
    By Sean137 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 14th, 2010, 03:15 PM