import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class CandleLineApplet extends Applet implements ItemListener
{
// Declare variables and construct a color
double answer, dollars;
int calculate;
Color cyan = newColor();
}
{
//Create components for applet
Label companyLabel = new Label("CandleLine--Candles Online");
TextField salesField = new TextField();
Label promptLabel = new Label("Please enter the total amount of your order:");
Label codeLabel = new Label("Please choose your method of shipping");
CheckboxGroup codeGroup = new CheckboxGroup();
Checkbox priorityBox = new Checkbox("Priority (Overnight)",false,
codeGroup);
Checkbox expressBox = new Checkbox("Express (2 business days)",false,
codeGroup);
Checkbox standardBox = new Checkbox("Standard (3 to 7 business days)",false,codeGroup);
Checkbox hiddenBox = new Checkbox("",true,codeGroup);
Label outputLabel = new Label("We guarantee on time delivery, or your money back.");
}
public void init()
{
setBackground(Color.cyan);
setForeground(Color.black);
add(companyLabel);
add(promptLabel);
add(salesField);
salesField.requestFocus();
salesField.setForeground(Color.white);
add(codeLabel);
add(priorityBox);
priorityBox.addItemListener(this);
add(expressBox);
expressBox.addItemListener(this);
add(standardBox);
standardBox.addItemListener(this);
add(outputLabel);
}
//This method is triggered by the user clicking an option button
public void itemStateChanged(ItemEvent choice)
{
try
{
dollars = getSales();
shippingCode = getCode();
answer = getSales(dollars, shippingCode);
output(answer, dollars);
}
catch(NumberFormatException e)
{
outputLabel.setText("You must enter a dollar amount greater than zero.");
hiddenBox.setState(true);
salesField.setText("");
salesField.requestFocus();
}
}
public double getSales()
{
sales = Double.parseDouble(salesField.getText());
if (sales <= 0) throw new NumberFormatException();
return sales;
}
public double getShipping(double shipping, int code)
{
double shipping = 0.0;
switch(code)
{
case 1:
sales = 16.95 + shipping;
break;
case 2:
sales = 13.95 + shipping;
break;
case 3:
sales = 7.95 + shipping;
break;
}
return shipping;
}
{
DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
outputLabel.setText("Your shipping of " + twoDigits.Format(sales) + " is " + twoDigits.Format(shipping));
}
Someone check this code it wont let me run
Page 1 of 13 Replies - 142 Views - Last Post: 15 November 2012 - 03:34 PM
#1
Someone check this code it wont let me run
Posted 14 November 2012 - 08:08 PM
Replies To: Someone check this code it wont let me run
#2
Re: Someone check this code it wont let me run
Posted 14 November 2012 - 08:09 PM
Can you copy and paste the result that it gave you?
#3
Re: Someone check this code it wont let me run
Posted 14 November 2012 - 09:08 PM
I tried but this is what it is saying
CandleLine.Applet.java:109: <identifier> expected
outputLabel.setText("Your shipping on sales of " + twoDigits.format(sales) + " is " + twoDigits.format(shipping));
CandleLine.Applet.java:109: <identifier> expected
outputLabel.setText("Your shipping on sales of " + twoDigits.format(sales) + " is " + twoDigits.format(shipping));
#4
Re: Someone check this code it wont let me run
Posted 15 November 2012 - 03:34 PM
you have a } { where you shouldn't
shippingCode in the StateChange() is not defined
you declare the variable
double shipping
while it is already a parameter
...
int calculate;
Color cyan = newColor(); // you need a space between new an Color
} <---
{ <---
shippingCode in the StateChange() is not defined
you declare the variable
double shipping
while it is already a parameter
...
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|