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 22 of 22

Thread: I need help on this one :(

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default I need help on this one :(

    Hi folks, I am beginner and really struggling on this one please help me.

    2. Program 2: Demonstrate use of “selection” in the design and development of a Java program to guess who the user is thinking of.
    Andrew has fair hair and blue eyes.
    Suky has brown hair and brown eyes.
    Jasmine has black hair and brown eyes.
    Parminder has brown hair and hazel eyes.
    The program needs to ask two questions to find out the colour of hair and the colour of eyes. Design and code a solution to the problem.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

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

    cool (May 7th, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    nothing number guessing game makes sense to me but this doesn't. I fail to write a code where algorithm would be acceptable
    i was think if hair colour == black && eye colour == black or something but i am failing to compile it i know i might sound so stupid writing this but i have written and deleted code like million times and it doesnt work.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    Post a list of the steps the program must take to solve the problem.
    For example this looks like a step:
    The program needs to ask two questions
    to find out the colour of hair
    and the colour of eyes
    Also post the code that you have written that tries to implement those steps.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 7th, 2014)

  7. #5
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    import javax.swing.JOptionPane ;

    public class example2 {
    public static void main(String[] args) {
    eyecolour = JOptionPane.showInputDialog(null, "Enter the eye colour");
    haircolour = JOptionPane.showInputDialog(null, "Enter the hair colour");

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    That's the code for one of the steps.
    Now what are the rest of the steps the program needs to take?
    How would you do it manually?

    When posting code be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

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

    cool (May 7th, 2014)

  10. #7
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    now when it comes to algorithm its not make sense how do I write one which decides on bases of hair colour and eyecolour that who has user got in his/her mind

    --- Update ---

    well i would think if one has brown hair and brown eyes its suky but how do i write it?

    --- Update ---

    else if its fair hair n blue eyes its andrew

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    There are several Strings that contain data about each of the people.
    Looking at those String, given the colors, how would you manually find a match?
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 7th, 2014)

  13. #9
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    yes but I am stuck at algorithm I also want to know that do I have to list four people we are guessing against their hair and eyes?

    --- Update ---

    firstly I want to appreciate you for giving me excellent advice I really appreciate that

    --- Update ---

    manually It is easy as i know hair colour and eye colour is identification of the person but when I try to write it in java I struggle. do I write suky = brown && brown

    if eye colour == brown and hair colour == brown

    --- Update ---

    ok I am new I will make sure I follow the instructions, First time so pardon me

  14. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    Look at the sentences. Are they all the same format? <>s are used for meta data
    Andrew has fair hair and blue eyes.
    <name> has <typehair> hair and <eyecolor> eyes.

    If so, then the String class's split() method would be useful to separate the parts into a String array which will make searching easier.

    I'm finished for tonight, back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  15. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 7th, 2014)

  16. #11
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    ok thanks

    --- Update ---

    [ code= java]
    import javax.swing.JOptionPane ;

    public class example2 {
    public static void main(String[] args) {
    String guess;
    double haircolour;
    double eyecolour;

    guess = JOptionPane.showInputDialog(null, "Enter the eye colour");
    eyecolour = Double.parseDouble(guess);
    guess = JOptionPane.showInputDialog(null, "Enter the hair colour");
    haircolour = Double.parseDouble(guess);
    int Andrew=3;
    int Suky = 8;
    int Jasmine = 7;
    int Parminder = 9;
    int fair = 1;
    int blue = 2;
    int black =3;
    int brown = 4;
    int hazel= 5;


    if (Andrew == fair + blue){
    eyecolour = fair;
    haircolour = blue;
    System.out.println(" The person is " +Andrew);
    }
    else if (Suky == brown + brown) {
    eyecolour = brown;
    haircolour = brown;
    System.out.println(" The person is " +Suky);
    }
    else if (Jasmine == black + brown){
    eyecolour = brown;
    haircolour = black;
    System.out.println(" The person is " +Jasmine);
    }
    else if (Parminder == brown + hazel) {
    eyecolour = hazel;
    haircolour = brown;
    System.out.println(" The person is " +Parminder);
    }
    }
    }
    [/code]

    still not working lol sorry I am new.
    Last edited by cool; May 8th, 2014 at 06:32 PM.

  17. #12
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: I need help on this one :(

    Code tags can't have extra spaces (I think). Please fix them.

  18. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    The code defines a number of variables but does not give them any values.

    How will the user's guess of hair and eye colours be used to select an individual?
    If you don't understand my answer, don't ignore it, ask a question.

  19. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 8th, 2014)

  20. #14
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    how do I give them values? can you amend it for me so I have an idea please?

  21. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    I don't know how to use int values for this program. All the data is in Strings.

    How will the program get the data that associates the colors with the peoples names? The first posting shows 4 Strings. Will those 4 Strings be in an array in the program? Or how will their data be available to the program?
    If you don't understand my answer, don't ignore it, ask a question.

  22. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 8th, 2014)

  23. #16
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    Like I said I am like doing my first program so I am beginner so I am only following your instructions well this program is compiled but doesn't run. I am sure you could fix this issue better. I have tried my best to do it but it isn't working. It stops I just want user to have options of type a hair colour and type an eye colour so the program can guess the person out of these four people.

  24. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    Before writing any more code, you need to work on the design for the program. Look at the questions in post#15.
    How will the program save the attributes for all of the people?
    How will the user's input be used to search though those attributes?
    If you don't understand my answer, don't ignore it, ask a question.

  25. The Following User Says Thank You to Norm For This Useful Post:

    cool (May 8th, 2014)

  26. #18
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    post#15?

  27. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    Yes, read post#15 and answer the questions asked there. This is post#19
    If you don't understand my answer, don't ignore it, ask a question.

  28. #20
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    import javax.swing.JOptionPane;
    public class program2 {
      public static void main(String[] args) {
     
     
     
     String Hair = JOptionPane.showInputDialog(null, " Enter hair colour Brown,Black or Fair: ");
     while (!(Hair.equalsIgnoreCase("brown") ^ Hair.equalsIgnoreCase("fair") ^ Hair.equalsIgnoreCase("black"))){
     Hair = JOptionPane.showInputDialog(null,  "Plese try again: Enter brown, fair or black hair colour: ");
    }
     
     
     String Eyes = JOptionPane.showInputDialog(null, "Enter eye colour hazel, blue or brown: ");
     while (!(Eyes.equalsIgnoreCase("brown")^ Eyes.equalsIgnoreCase("blue") ^ Eyes.equalsIgnoreCase("hazel"))){
     Eyes = JOptionPane.showInputDialog(null, "Please try again: Enter eyes colour hazel, blue or brown: ");
     }
     
     if(("fair".equalsIgnoreCase(Hair)) && ("blue".equalsIgnoreCase(Eyes)))
     {
     System.out.print("Andrew");
     }
     
     if(("brown".equalsIgnoreCase(Hair)) && ("brown".equalsIgnoreCase(Eyes)))
     {
     System.out.print("Suky");
     }
     
     if(("black".equalsIgnoreCase(Hair)) && ("brown".equalsIgnoreCase(Eyes)))
     {
     System.out.print("Jasmine");
     }
     
     if(("brown".equalsIgnoreCase(Hair)) && ("hazel".equalsIgnoreCase(Eyes)))
     {
     System.out.print("Parminder");
     }
     }
     }


    --- Update ---

    Please help
    Last edited by cool; May 13th, 2014 at 12:04 AM. Reason: changed the code

  29. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: I need help on this one :(

    I suggest that you work out the design for the program before writing any code.
    I asked some questions about the design in post#15 and in post#17.

    What answers do you have for those questions?
    If you don't understand my answer, don't ignore it, ask a question.

  30. #22
    Junior Member
    Join Date
    May 2014
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: I need help on this one :(

    just getting four errors anyone can help. I have made another program which is working for this problem but I need help with this code

    --- Update ---

    solved