Error in CandleLine Java code Please Help?

Hi everyone could someone please help me in solving this one error that i have in this code. This is an Applet that calculates the shipping costs of items purchased by customers:


import java.applet.*;
import java.awt.*;
import java.awt.event.ItemListener;
import java.text.DecimalFormat;

public class CandleLine extends Applet implements ItemListener
{
//Declare Variables
double dollars, answer;
int shippingCode;

//Construct Components for applet
Label welcome = new Label("Welcome to CandleLine online");
Label OrderEntryLabel = new Label("Please Enter the total amount of you order");
TextField OrderEntryField = new TextField(7);

Label codeLabel = new Label("Select the appropriate shipping method");

CheckboxGroup codeGroup = new CheckboxGroup();
Checkbox PriorityBox = new Checkbox("Priority Delivery; overnight",false,codeGroup);
Checkbox ExpressBox = new Checkbox("Express Delivery; 2 business days",false,codeGroup);
Checkbox StandardBox = new Checkbox("Standard Delivery; 3-7 business days",false,codeGroup);
Checkbox hiddenBox = new Checkbox("",true,codeGroup);

Label Guarantee = new Label("We will guarantee on-time delivery, or your money back ");
Label outputLabel = new Label("");

public void init()
{
setForeground(Color.black);
setBackground(Color.cyan);
add(welcome);
add(OrderEntryField);
add(OrderEntryLabel);
add(PriorityBox);
PriorityBox.addItemListener(this);
add(ExpressBox);
ExpressBox.addItemListener(this);
add(StandardBox);
StandardBox.addItemListener(this);
add(outputLabel);
add(Guarantee);
}

public void ItemStateChanged(ItemListener choice)
{
try
{
dollars = getSales();
shippingCode = getCode();
answer = getShipping(dollars,shippingCode);
output(answer, dollars);
}
catch(NumberFormatException e)
{
outputLabel.setText("You must enter a dollar amount greater than zero");

hiddenBox.setState(true);
OrderEntryField.setText("");
OrderEntryField.requestFocus();
}
}

public double getSales()
{
double total = Double.parseDouble(OrderEntryField.getText());

if(total <= 0) throw new NumberFormatException();

return total;
}

public int getCode()
{
int code = 0;
if (PriorityBox.getState()) code = 1;
else
if (ExpressBox.getState()) code = 2;
else
if (StandardBox.getState()) code = 3;
return code;
}

public double getShipping(double Total, int code)
{
double shipping = 0.0;
switch(code)
{
case 1:
shipping = 16.95;
break;

case 2:
shipping = 13.95;
break;

case 3:
if(Total>100) shipping = 0.0;
else if(Total<=100) shipping = 7.95;
break;
}
return shipping;
}

public void output(double shipping, double total)
{
DecimalFormat twoDigits = new DecimalFormat("$#,0000.00");
outputLabel.setText("Your shipping on sales of " + twoDigits.format(total) + " is "+twoDigits.format(shipping));
}
}

Error: C:\Course Technology\59850d\Chapter 04\CandleLine.java:17: CandleLine is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
public class CandleLine extends Applet implements ItemListener
^
1 error

Thank You :-)

Mahendra Shinde2012-02-07T00:25:35Z

Favorite Answer

error is at :
public class CandleLine extends Applet implements ItemListener

your class "CandleLine" is implementing an Interface "ItemListener" which has one method "itemStateChanges(ItemEvent evt){}

You need to override this method in same class.

2017-04-11T00:37:33.809Z