Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default I Need help with solveing a java problem :)

    Hey guys i need help with this I have lost some if not all of my notes from class.

    I was given this task to do and im lost without my notes could someone help me with this problem. I know its a bit much for my second post but il be a regular on this forum trying to understand java ive listed the problem below any help will be appreciated :D

    Thanks :)

    The program will take user input from 20 people. It will run through a survey asking the same questions for each person starting at person 1 through to 20
    1. Output a message to the output screen asking the user to input their favourite hobbies ,music genre , drink ,political party
    2. On a newline output to the screen a list of 5 hobbies (for example) numbered 1 – 5.
    E.g. 1. Running, 2. Reading, 3. Resting, and so on.
    3. On another new line send a message to the screen asking the user to input the number of their favourite hobby (a number between 1 and 5).
    4. Take the user input, which is the number of their favourite hobby, and store it in a variable, e.g., favHobby.
    5. Based on the number they entered, record the number of people who like each of the 5 hobbies (E.g., Set up and initialise variables for each of the hobby at the start of the program. If the hobby entered is ‘1’, add 1 to Running. If the hobby entered is ‘2’, then add 1 to Reading and so on). If any other number is entered then give a message to the screen that they have entered an invalid number.



    Once all 1-20 people have inputted their favourite subject:

    1. Output a message to the screen saying, for example, ‘the number of people who like Running are
    2. On a new line output to the screen the (integer) number of the people who liked Running.
    3. Repeat steps 1 and 2 for all hobbies.
    4. Now check if the number of people who liked Running is greater than half the people tested (which is 11 out of a class of 20), then give a message to the screen saying that the students love Running. Otherwise, give a message to the screen saying that the people don’t like Running. Repeat for each hobby

    Last edited by javaNoob2; 02-12-2009 at 01:30 AM. Reason: just noticed spelling mistakes including the topic heading lol

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    there are many tutorial on java. you can find it w/ google.
    best of luck.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    carlodelmundo is offline Member
    Join Date
    Aug 2008
    Posts
    31
    Rep Power
    0

    Default

    Hi.

    For inputting/reading from a file. See the Scanner Class.

    Scanner (Java 2 Platform SE 5.0)

    It will help you out on this project.

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    I'm not trying to encourage you setting requirements on the table for us to complete, the forums are for help, but I'm working on something that will do what you asked. Check back later when I post it.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #5
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default there you go.

    Your Welcome. Don't expect this kind of help all the time, you're extremely lucky I took the time to do this.
    Java Code:
    import java.util.Scanner;
    
    /**
     * ...
     *
     * @author MK12
     * @version 1.0 - 02/11/09
     */
    public class HobbySurvey {
        private int videogames = 0;
        private int reading = 0;
        private int jogging = 0;
        private int javaprog = 0;
        private int drawing = 0;
        private int numOfPeople;
        public HobbySurvey(int numOfPeople) {
            this.numOfPeople = numOfPeople;
        }
        public void getSurveyInput() {
            Scanner input = new Scanner(System.in);
            int favHobby;
            for(int i = 0; i < numOfPeople; i++) {
                System.out.println("What is your favourite Hobby?: (Enter Number)");
                System.out.println("1 - Video Games\n2 - Reading\n3 - Jogging\n4 - Java Programming\n5 - Drawing\n");
                favHobby = input.nextInt();
                switch(favHobby) {
                    case 1: videogames++; break;
                    case 2: reading++; break;
                    case 3: jogging++; break;
                    case 4: javaprog++; break;
                    case 5: drawing++; break;
                    default:
                        System.out.print("You Must enter A number from 1 to 5. Please try Again.");
                        i--;
                        continue;
                }
            }
            input.close();
        }
        public static void main(String[] args) {
            HobbySurvey hs = new HobbySurvey(20);
            hs.getSurveyInput();
            System.out.println("\n\n");
            String[] hobbies = { "Video Games", "Reading", "Jogging", "Java Programming", "Drawing" };
            int[] surveyResults = { hs.videogames, hs.reading, hs.jogging, hs.javaprog, hs.drawing };
            for(int i = 0; i < 5; i++) {
                System.out.println("-----------------------------------------------------");
                System.out.println("The number of people who like " + hobbies[i] + " is:\n" + surveyResults[i]);
                if(surveyResults[i] > 11) {
                    System.out.println("The students LOVE " + hobbies[i]);
                } else {
                    System.out.println("The students aren't too big on " + hobbies[i]);
                }
            }
        }
    }
    Last edited by MK12; 02-12-2009 at 03:55 AM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by MK12 View Post
    Your Welcome. Don't expect this kind of help all the time, you're extremely lucky I took the time to do this.
    Yes it is. Not a good practice all the time MK. Better to courage people to try something. Actually I'm doing the same thing sometimes, very rarely. ;)

  7. #7
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    it is rarely to meet so generous progers )))

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Aaarrrgggg....

    It has nothing to do if you're generous, the OP is lucky or if Santa Claus exists. You may think you're helping somebody, but you're really doing a lot of damage. Important question and I beleive it has to do with the purpose of this forum:

    Did the OP learn something?... no!

    Hints, suggestions, explanations, links, code snippets, etc are all great and should be used, but complete code solutions don't help the OP.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Well he got what he wanted. He might not understand it, and he lost all his notes so he wants someone else to do it, but thats his fault. If he understands it, he could learn something by going over it and seeing how each part works.... normally people here don't like someone that asks for you to do a whole project for them because this forum isn't meant for that. But anyway if it does damage to him maybe he'll learn to try himself... He asked, I did it for him, its his own fault if he doesn't try to understand it or learn.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  10. #10
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by MK12 View Post
    Your Welcome. Don't expect this kind of help all the time, you're extremely lucky I took the time to do this.
    Java Code:
    import java.util.Scanner;
    
    /**
     * ...
     *
     * @author MK12
     * @version 1.0 - 02/11/09
     */
    public class HobbySurvey {
        private int videogames = 0;
        private int reading = 0;
        private int jogging = 0;
        private int javaprog = 0;
        private int drawing = 0;
        private int numOfPeople;
        public HobbySurvey(int numOfPeople) {
            this.numOfPeople = numOfPeople;
        }
        public void getSurveyInput() {
            Scanner input = new Scanner(System.in);
            int favHobby;
            for(int i = 0; i < numOfPeople; i++) {
                System.out.println("What is your favourite Hobby?: (Enter Number)");
                System.out.println("1 - Video Games\n2 - Reading\n3 - Jogging\n4 - Java Programming\n5 - Drawing\n");
                favHobby = input.nextInt();
                switch(favHobby) {
                    case 1: videogames++; break;
                    case 2: reading++; break;
                    case 3: jogging++; break;
                    case 4: javaprog++; break;
                    case 5: drawing++; break;
                    default:
                        System.out.print("You Must enter A number from 1 to 5. Please try Again.");
                        i--;
                        continue;
                }
            }
            input.close();
        }
        public static void main(String[] args) {
            HobbySurvey hs = new HobbySurvey(20);
            hs.getSurveyInput();
            System.out.println("\n\n");
            String[] hobbies = { "Video Games", "Reading", "Jogging", "Java Programming", "Drawing" };
            int[] surveyResults = { hs.videogames, hs.reading, hs.jogging, hs.javaprog, hs.drawing };
            for(int i = 0; i < 5; i++) {
                System.out.println("-----------------------------------------------------");
                System.out.println("The number of people who like " + hobbies[i] + " is:\n" + surveyResults[i]);
                if(surveyResults[i] > 11) {
                    System.out.println("The students LOVE " + hobbies[i]);
                } else {
                    System.out.println("The students aren't too big on " + hobbies[i]);
                }
            }
        }
    }

    Thanks alot i had over half it done last night and got most of it done today in class but I done it diffrently to what you posted and i would not use that exact code . I understand everything in that code. This isnt a project it was just a small task that i had to get done and wasnt sure as what to do i just started off learning java in January and im slowly geting the hang of it.

    Thanks again :)

  11. #11
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Please post...

    JN2... Please post your solution and that way we have two ways to solve the same problem. Also, your code will be reviewed by others and you can receive feedback form them.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  12. #12
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    Sure no problem, just have to get it off my college server tomorrow.

  13. #13
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    see, my code did no harm, maybe helped improve his own. He wasn't just trying to order someone to code something for him. I'm glad I was of help javaNoob2, also glad you didn't just take my code and hand it in for something important without understanding it. Sorry for sounding a bit rude in my posts, but it was hard to tell what your were intending.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  14. #14
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    just to mention that if you have done work and are stuck on a specific part, please indicate so in your original post. you'll get more relevant input (and less annoyed input) that way.

  15. #15
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default No problem...

    MK12... I also apologize if I seemed a bit uptight. The purpose of the forum is to help people with their java code. In this case, it appears that giving a complete solution worked out, but like you said "you got extremelly lucky". Most of the time it's just "gimme da code" and the OP runs away with it... let give you some examples:
    • There was an OP who requested "complete working code" and gave an email address were it could be sent (this happens a lot).
    • Another case was that the OP requested complete code, got it in this forum and when to another forum indicating that HE had coded it and wanted to add something else to it.
    So... that's why I'm usually not a champion of complete code solutions. I don't know how many times I've seen "URGENT: Due for tomorrow !!!"... in this case it might have been merited (lost homework).

    We'll just have to work it out as it comes...

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  16. #16
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Its fine. Well he wasn't a "gimme da code" person, but anyway, if he was, he would have deserved the potential damage of using my complete code, right? And I actually wanted to do that for fun anyway, and it helped him out. But he was a bit more polite in his post then some people are who request full code, but he never actually did specifically request anything, just help, so I would have doubted your second bullet. So in the end, nothing bad for Us could have happened in this situation, most likely.
    Last edited by MK12; 02-13-2009 at 12:26 AM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  17. #17
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    i'm just mentioning this because if you look at the 2 replies prior to yours, one practically said 'go learn java' and the other mentioned reading files with the scanner class, which has nothing to do with the original post.

    though i can't say to err on the side of providing too much detail, it can be annoying sometimes =p

  18. #18
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    though i can't say to err on the side of providing too much detail, it can be annoying sometimes =p
    ... I understood you saying what the first to posts said, but could you explain that quote? I can't understand what you're trying to say.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  19. #19
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    I believe mcn is indicating that maybe (notice the "maybe") we might overflow the new OPs with too much detail in our responses... "look at this", "look at that", etc
    This might be (notice the "might") because we've seen the stuff we recommend so many times that we almost dream it and it is natural to us, were as a newbie would find it alien and strange (almost akin to Bontoc).
    I'm rambling.. aren't I? oh well.. it's been a long day.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  20. #20
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    one practically said 'go learn java'
    haha that's me, i was just repeating what i've seen on this forum so far when someone post a homework assignment like that. Which is true, if you lost you notes, google is your next best thing.

    javaNoob2, i look forward to your posting tommorrow... we will help you imporove it even better!
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Page 1 of 2 12 LastLast

Similar Threads

  1. JAVA and XML Problem
    By jackchang in forum XML
    Replies: 4
    Last Post: 02-22-2009, 08:28 PM
  2. Problem in java
    By saytri in forum New To Java
    Replies: 4
    Last Post: 01-16-2008, 10:09 PM
  3. Problem in java
    By saytri in forum New To Java
    Replies: 6
    Last Post: 01-09-2008, 04:13 PM
  4. JAVA if problem
    By toby in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 07:58 PM
  5. java SE 6 problem
    By techlance in forum Java Applets
    Replies: 1
    Last Post: 06-28-2007, 10:10 AM

Posting Permissions

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