Results 1 to 10 of 10

Thread: Compiling help!

  1. #1
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Unhappy Compiling help!

    Hello! so I have a question to do a commission type calculator thing and this is what I have done so far

    import java.util.Scanner;
    public class Question1
    {
    public static void main(String[] args)
    {

    Scanner input = new Scanner(System.in);

    int saleprice =0;
    String residential="";
    String multidwelling="";
    String commercial="";



    System.out.print("Enter the property's salesprice: ");
    saleprice = input.nextInt();


    System.out.print("Entery the Property code according to the following: \nResidential enter r \nMulti-Dwelling enter m \nCommercial enter c \nChoose your code: ");

    int code = input.nextLine;
    while (code = 'r' || code = 'm' || code = 'c')
    {
    if (code != 'r' || code != 'm' || code != 'c')
    {
    System.out.print("Code must be either R, M, or C: ");
    }
    }
    return code;
    }
    }

    I still need to include a new method but first I have to ask for a selling price, and then to enter the proper property code (R,m,c) and looping it to ask again if the code is not entered as r, m, or c. This is as far as I've gotten...


    Now, when I try to compile it, it says the following :

    int code = input.nextLine;

    cannot find symbol - variable nextLine


    What am I doing wrong here?

    I think it should be int code = input.nextInt();
    but I dunno

    also when I do this, the compiler says that I cannot use || in my if and while statements... what could I do otherwise?
    Last edited by cloverrea; 10-12-2011 at 03:27 AM.

  2. #2
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: Compiling help!

    Guys, correct me if I'm wrong Scanner can't scan a char...

    Java Code:
    int code = input.nextLine; 
    while (code = 'r' || code = 'm' || code = 'c')
    { 
    if (code != 'r' || code != 'm' || code != 'c')
    {
    System.out.print("Code must be either R, M, or C: ");
    }
    }
    return code;
    }
    Java Code:
    int code = input.nextLine; 
    while (code = 'r' || code = 'm' || code = 'c')
    Your trying to filter an int or character or string?
    *By using .nextLine you're trying to scan for a String
    *in your your while condition, your tring to compare an int to char?
    *Why there is return code there? fyi your in main method, you should create another method that returns the code

  3. #3
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: Compiling help!

    Okay so I have tried it a different way but it still doen't completely work it compiles though... it runs and just shows some lines written in red ugghhhhh.....


    public class Question1
    {
    public static void main(String[] args)
    {

    Scanner input = new Scanner(System.in);

    double saleprice =0;
    double commission = 0;
    String propertytype= "";



    System.out.print("Enter the property's salesprice: ");
    saleprice = input.nextDouble();


    System.out.print("Enter Property code according to the following: \nResidential enter r\nMulti-Dwelling enter m\nCommercial enter c\n choose your code: ");

    if (propertytype.equals("r"))
    commission = 0.07;
    else if (propertytype.equals("m"))
    commission = 0.06;
    else if (propertytype.equals("c"))
    commission = 0.035;
    else
    {System.out.print("Code must be either r, m or c! ");
    System.exit(0);
    }
    }


    should I still create a new method??

  4. #4
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Compiling help!

    Java Code:
    int code = input.nextLine;
    It needs to be used as a method
    Java Code:
    int code = input.nextInt();
    but if you want to use a method of the String class you are going to declare code as a String.
    Java Code:
    String code = input.nextLine();
    your filter needs to be something like:
    Java Code:
    while(code.charAt(0) != 'r' || code.charAt(0) != 'm' //..............etc
    Last edited by mwr1976; 10-12-2011 at 04:46 AM.

  5. #5
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: Compiling help!

    Well for starters you need to put parenthesis at the end of nextLine. That will throw an error without it
    Java Code:
    int code = input.nextLine(); 
    while (code = 'r' || code = 'm' || code = 'c')
    { 
    if (code != 'r' || code != 'm' || code != 'c')
    {
    System.out.print("Code must be either R, M, or C: ");
    }
    }
    return code;
    }
    }
    Just as mwr1976 said...sorry was writing and did not refresh
    Last edited by kraigballa; 10-12-2011 at 04:49 AM.

  6. #6
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Compiling help!

    You are not displaying your output. Also since your commission rates are hard rates I would use Named Constants for those values. If you have to create another method you
    could create a method that figures the commission with the named constants you wont have to pass them as parameters to your new function. You could return a double that would be a commission amount, but you still have to define your output.

  7. #7
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: Compiling help!

    alrighty thank you! my problem is... I don't understand why my output is not being dsplayed, how do I go about doing this?

  8. #8
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Compiling help!

    How did you display the message that prompt the user for the input?

  9. #9
    cloverrea is offline Member
    Join Date
    Oct 2011
    Posts
    11
    Rep Power
    0

    Default Re: Compiling help!

    system.out.print??

  10. #10
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Compiling help!

    that's the right method, all you need is your parameter(s)

Similar Threads

  1. About compiling
    By edh in forum Advanced Java
    Replies: 2
    Last Post: 06-16-2011, 09:47 AM
  2. compiling error
    By Adeline in forum AWT / Swing
    Replies: 3
    Last Post: 12-03-2010, 07:18 PM
  3. Error while compiling
    By vibaviattigala in forum New To Java
    Replies: 3
    Last Post: 11-30-2010, 02:07 PM
  4. how to get compiling
    By philgrek in forum New To Java
    Replies: 1
    Last Post: 05-25-2010, 11:53 PM
  5. Help with compiling HelloWorldApp
    By JonBrad in forum New To Java
    Replies: 13
    Last Post: 01-09-2010, 04:04 PM

Tags for this Thread

Posting Permissions

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