1 Replies - 2312 Views - Last Post: 24 September 2005 - 09:19 PM Rate Topic: -----

#1 big-bad-dave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-September 05

java program

Post icon  Posted 24 September 2005 - 08:40 PM

hello i need some help i have a program that is due on sunday i have gone over it and over can any help me i need to write a program in java code for a egg hunt using the nested if\else stamnet and a while stament input is each time an egg is turned in the program will allow entry of the sex a value of m or f of the competior along with the egg type a value of a,b,or c if the scorer enters q for sex of the competitor that is the signal to the program that the contest is over and that there will be no more egg discoveries enterd please use a scanner for input

output the progrm will print out the scores of the teams along with name of the winning team if the game is a tie then the output should specify a tie the out put should look like this

enter the gender of competitor : m
eneter the egg type : a
enter the gender of competitor: f
enter the egg type : c
enter the gender of competitor ; q

the girls scored 15 points and the boy scored 10 points the girsl are the champions

// could some one help me pleasea e- mail me the write code her is what i have so far

Attached File(s)

Is This A Good Question/Topic? 0
  • +

Replies To: java program

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 249
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: java program

Posted 24 September 2005 - 09:19 PM

Here are a few things that need to be corrected
int gender=M,f;

You are declaring the variable gender to be of type integer, then trying to assign it multiple character values, but the character values are not contained in quotes...it should probably look like this:
string gender="";

This will allow you to have a clear string in which to put the input from the user.

Next, you seem to be using the scanner input method, but have not instantiated a scanner object to use.

In the following section:
if (gender= M);{ 
            if (gender= F); 
             if  (egg_type)(A)+(B)+(C)=(total);

The first and third if statements...if statements do not end with a semi colon. Additionally, you are comapring what should likely be a string input to an unquoted character which will be interpreted as a variable. Finally, instead of using the comparative 'is equal to' operator, your are using the assignment operator...it is likely that these statements should look like this:
if(gender == "M"){

The second and fourth if statements will not be interpreted correctly...again, the assignment operator is being used, and the notation for the rest does not conform to java standards...could you specify in words what those statements are meant to say?

The while loop is by itself, holding only a message. Your while loop should contain the rest of the code (the code below it) and terminate once Q has been entered:
while(gender != "Q")
   //do rest of code

The final two lines of the code output only the strings specified...they contain no variables, and would therefore not output any calculated information.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1