Results 1 to 20 of 29
- 02-12-2009, 01:27 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 13
- Rep Power
- 0
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
- 02-12-2009, 02:12 AM #2
there are many tutorial on java. you can find it w/ google.
best of luck.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 02-12-2009, 03:13 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 31
- Rep Power
- 0
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.
- 02-12-2009, 03:15 AM #4
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.
- 02-12-2009, 03:52 AM #5
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.
- 02-12-2009, 04:00 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 02-12-2009, 06:31 AM #7
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
it is rarely to meet so generous progers )))
- 02-12-2009, 01:24 PM #8
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.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-12-2009, 01:48 PM #9
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.
- 02-12-2009, 07:39 PM #10
Member
- Join Date
- Feb 2009
- Posts
- 13
- Rep Power
- 0
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 :)
- 02-12-2009, 07:55 PM #11
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-12-2009, 09:47 PM #12
Member
- Join Date
- Feb 2009
- Posts
- 13
- Rep Power
- 0
Sure no problem, just have to get it off my college server tomorrow.
- 02-12-2009, 11:26 PM #13
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.
- 02-12-2009, 11:29 PM #14
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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.
- 02-13-2009, 12:20 AM #15
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.
We'll just have to work it out as it comes...
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-13-2009, 12:24 AM #16
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.
- 02-13-2009, 01:34 AM #17
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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
- 02-13-2009, 01:59 AM #18
... 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.though i can't say to err on the side of providing too much detail, it can be annoying sometimes =pTell me if you want a cool Java logo avatar like mine and I'll make you one.
- 02-13-2009, 02:12 AM #19
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.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-13-2009, 03:00 AM #20
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.one practically said 'go learn java'
javaNoob2, i look forward to your posting tommorrow... we will help you imporove it even better!USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
JAVA and XML Problem
By jackchang in forum XMLReplies: 4Last Post: 02-22-2009, 08:28 PM -
Problem in java
By saytri in forum New To JavaReplies: 4Last Post: 01-16-2008, 10:09 PM -
Problem in java
By saytri in forum New To JavaReplies: 6Last Post: 01-09-2008, 04:13 PM -
JAVA if problem
By toby in forum New To JavaReplies: 2Last Post: 07-25-2007, 07:58 PM -
java SE 6 problem
By techlance in forum Java AppletsReplies: 1Last Post: 06-28-2007, 10:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks