|
What's wrong with this Java code?...
|
View this Thread in Original format
| Turbonium |
code: import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Freddie extends Applet implements ItemListener
{
int sandwiches = 0;
String fCode="", dCode="", cCode="";
Label sandwichPromptLabel = new Label("Number of sandwiches ordered:");
TextField sandwichInputField = new TextField(5);
Label friesLabel = new Label("Fries serving size: ");
CheckboxGroup friesGroup = new CheckboxGroup();
Checkbox smallFries = new Checkbox("Small",false,friesGroup);
Checkbox mediumFries = new Checkbox("Medium",false,friesGroup);
Checkbox largeFries = new Checkbox("Large",false,friesGroup);
Label drinkLabel = new Label("Drink serving size: ");
CheckboxGroup drinkGroup = new CheckboxGroup();
Checkbox smallDrink = new Checkbox("Small",false,drinkGroup);
Checkbox mediumDrink = new Checkbox("Medium",false,drinkGroup);
Checkbox largeDrink = new Checkbox("Large",false,drinkGroup);
Label condimentsLabel = new Label(" Condiments: ");
Checkbox catsupBox = new Checkbox("Catsup");
Checkbox mustardBox = new Checkbox("Mustard");
Checkbox picklesBox = new Checkbox("Pickles");
Label outputLabelSandwiches = new Label("");
Label outputLabelDrink = new Label("");
Label outputLabelFries = new Label("");
Label outputLabelCondiments = new Label("");
Label warningLabel = new Label("");
public void init()
{
setBackground(Color.red);
add(sandwichPromptLabel);
add(sandwichInputField);
sandwichInputField.requestFocus();
add(friesLabel);
add(smallFries);
smallFries.addItemListener(this);
add(mediumFries);
mediumFries.addItemListener(this);
add(largeFries);
largeFries.addItemListener(this);
add(drinkLabel);
add(smallDrink);
smallDrink.addItemListener(this);
add(mediumDrink);
mediumDrink.addItemListener(this);
add(largeDrink);
largeDrink.addItemListener(this);
add(condimentsLabel);
add(catsupBox);
catsupBox.addItemListener(this);
add(mustardBox);
mustardBox.addItemListener(this);
add(picklesBox);
picklesBox.addItemListener(this);
add(outputLabelSandwiches);
add(outputLabelFries);
add(outputLabelDrink);
add(outputLabelCondiments);
add(warningLabel);
}
//This method is triggered by the user clicking an option button
public void itemStateChanged(ItemEvent choice)
{
try
{
sandwiches = getSandwiches(0);
fCode = getFries("");
dCode = getDrink("");
cCode = getCondiments("");
sendOutput(sandwiches,fCode,dCode,cCode); <<<<< cannot resolve symbol
}
catch (NumberFormatException e)
{
warningLabel.setText("You must enter an integer value.");
sandwichPromptLabel.setText("");
sandwichPromptLabel.requestFocus();
}
}
public int getSandwiches(int sandwiches)
{
sandwiches = Integer.parseInt(sandwichInputField.getText());
return sandwiches;
}
public String getFries(String fCode)
{
fCode = "";
if (smallFries.getState()) fCode = "Small";
else
if (mediumFries.getState()) fCode = "Medium";
else
if (largeFries.getState()) fCode = "Large";
return fCode;
}
public String getDrink(String dCode)
{
dCode = "";
if (smallDrink.getState()) dCode = "Small";
else
if (mediumDrink.getState()) dCode = "Medium";
else
if (largeDrink.getState()) dCode = "Large";
return dCode;
}
public String getCondiments(String cCode)
{
cCode = "";
if (catsupBox.getState()) cCode = "1";
else
if (mustardBox.getState()) cCode = "2";
else
if (picklesBox.getState()) cCode = "3";
return cCode;
}
public void int String sendOutput(int sandwiches, String fCode, String dCode, String cCode)
{
outputLabelSandwiches.setText("# of sandwiches ordered: " + sandwiches);
outputLabelFries.setText("Size of fries ordered: " + fCode);
outputLabelDrink.setText("Size of drink ordered: " + dCode);
outputLabelCondiments.setText("Condiments ordered: " + cCode);
}
} <<<<< '(' expected
compiler errors are bolded in orange and described |
|
|
| Azz3D |
I don't know anything about java, but just a thought:
to make it easier to read use the [.code] tag. it lines up the brackets and makes the spacings look like on the compiler... :) |
|
|
| Turbonium |
| quote: | Originally posted by Azz3D
I don't know anything about java, but just a thought:
to make it easier to read use the [.code] tag. it lines up the brackets and makes the spacings look like on the compiler... :) |
Yea, it definitely needed that. Thanks. |
|
|
| whiskers |
| well, what kind of sandwiches are you trying to send? |
|
|
| Turbonium |
| quote: | Originally posted by whiskers
well, what kind of sandwiches are you trying to send? |
integer value ones, you dumbass
go back to programming class you n00b! |
|
|
| whiskers |
| quote: | Originally posted by Turbonium
integer value ones, you dumbass
|
there's your problem, your sandwiches don't have any cheese in them, how can you have sandwiches without any cheese? |
|
|
| nchs09 |
| quote: | Originally posted by whiskers
there's your problem, your sandwiches don't have any cheese in them, how can you have sandwiches without any cheese? | ya DUH! sandwhich with out cheese. suckz0r! |
|
|
| igottaknow |
all this programming talk making me hungry...
while your at it would you mind sending me an italian assorted with the works thanks in advance :D
 |
|
|
| GQMr2 |
| haha I haven't programmed since highschool on Macintosh |
|
|
| mezzir |
yo i swear you need curly brackets to do if statements
so like instead of
if (smallFries.getState()) fCode = "Small";
else
....
return fCode;
you'd do:
if (smallFries.getState())//*is this a boolean?*/{ /* <-- { = then
fCode = "Small"
}else{
......
return fCode;
} |
|
|
| loconet |
code:
public void int String sendOutput(int sandwiches, String fCode, String dCode, String cCode)
dude, wtf? 3 return types? Stick with one - in this case probably void :) |
|
|
| mezzir |
| quote: | Originally posted by loconet
code:
public void int String sendOutput(int sandwiches, String fCode, String dCode, String cCode)
dude, wtf? 3 return types? Stick with one - in this case probably void :) |
wow i completely missed that
that should take care of the parenthases problem i think?
but still the cannot resolve symbol
this is gonna annoy me |
|
|
|
|