Made In China Talk  

Go Back   Made In China Talk > International Business Talk > Export > Food & Beverage
Directory Register FAQ Members List Calendar Mark Forums Read 中文


HELP WITH JAVA ASSIGNMENT (BEGINNER)?


Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2009, 09:28 AM
Ideal Ideal is offline
Senior Member
 
Join Date: Jun 2008
Posts: 1,928
Feedback: (0)
Default HELP WITH JAVA ASSIGNMENT (BEGINNER)?

Java Tutorials-http://javatutorial.info/
Reply With Quote


  #2  
Old 07-01-2009, 09:28 AM
India India is offline
Senior Member
 
Join Date: May 2008
Posts: 2,080
Feedback: (0)
Default HELP WITH JAVA ASSIGNMENT (BEGINNER)?

The only thing you are really incrementing here is person. What you really need is another counter for each choice. For example, if choice == choice1, then increment choice1Count.Good luck. And try stepping through your code with the debugger to see what you missed. Remember, if you can't do it on a piece of paper with a pencil, you probably don't understand the problem well enough to tell the computer to do it and you probably aren't getting everything you need into the program.
Reply With Quote
  #3  
Old 07-01-2009, 09:28 AM
import import is offline
Senior Member
 
Join Date: May 2008
Posts: 2,213
Feedback: (0)
Default HELP WITH JAVA ASSIGNMENT (BEGINNER)?

hey guys, i'm really stuck on this program. It's basically a survey and I have to ask people what drinks they like. 1-4, coffee tea oj and lemonade.i'm having trouble counting the TOTAL NUMBER OF PEOPLE and counting how many people pick coffee tea oj or lemonade.i have the 5th option set as a sentinel, where the program ends.i need help like i said counting the total number of people who participated(person who quits doesn't count) and counting each drinkhelp?[ICODE]import java.util.Scanner;public class Assignment3{public static void main(String[]args){int choice = 1;int person = 1;int person1 = 0;int choice1 = 1, choice2 = 1, choice3 = 1, choice4 = 1;int total = 0, votes;double percent, perc1, perc2, perc3, perc4;Scanner keyboard = new Scanner(System.in);while (choice != 5){System.out.println("Enter choice for person# " + person);System.out.println("1. Coffee 2. Tea 3. Orange Juice 4. Lemonade 5. Quit");choice = keyboard.nextInt();if(choice < 1 || choice > 5){System.out.print("That was an invalid choice -- enter 1 through 5 only");choice = keyboard.nextInt();}if(choice == choice1)person++;elseif(choice == choice2)person++;elseif(choice == choice3)person++;elseif(choice == choice4)person++;}person=choice1+choice2+choice3+c hoice4;perc1 = choice1/person;perc2 = choice2/person;perc3 = choice3/person;perc4 = choice4/person;System.out.println("The total number of people surveyed: " + person);System.out.println("THe results are as follows");System.out.println();System.out.println( " Beverage Number of Votes Percentage");System.out.println("-------------------------------------------------------------------------------------");System.out.println();System.out.println("Co ffee "+choice1+ ""+perc1);System.out.println("Tea "+choice2+""+perc2);System.out.println("Orange Juice "+choice3+""+perc3);System.out.println("Lemona de "+choice4+""+perc4);}}[/ICODE]
Reply With Quote
Reply



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


| UK Articles | find a job in china | China Video Chat | Business | Free Articles | Luxury Homes in the US | Bluehost coupons | Bluehost coupons | Hostmonster coupons | Hostmonster coupons | Online Marketing Tips - Earn Cash Money

All times are GMT +9. The time now is 01:24 PM.


All rights reserved. Copyright © 2007 Made In China Talk