3 Replies - 259 Views - Last Post: 15 November 2012 - 03:34 PM Rate Topic: -----

#1 randerson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 12

Someone check this code it wont let me run

Posted 14 November 2012 - 08:08 PM

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));
	}



Is This A Good Question/Topic? 0
  • +

Replies To: Someone check this code it wont let me run

#2 WolverineX  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 49
  • Joined: 11-November 12

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?
Was This Post Helpful? 0
  • +
  • -

#3 randerson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-November 12

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));
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Someone check this code it wont let me run

Posted 15 November 2012 - 03:34 PM

you have a } { where you shouldn't

	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

...
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1