6 Replies - 268 Views - Last Post: 15 November 2012 - 09:13 AM Rate Topic: -----

#1 randerson  Icon User is offline

  • New D.I.C Head

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

My code keeps telling me im missing a bracket at the end

Posted 14 November 2012 - 06:13 PM

/*
    Chapter 4:  CandleLine's Web
    Programmer:	Rochelle Anderson
    Date:		November 6, 2012
    Filename:	CandleLineApplet.java
    Purpose:	This applet is to improve customer relations and gives its customers a choice and calculates their shipping costs before finalizing their order.
*/

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: My code keeps telling me im missing a bracket at the end

#2 slehmann101  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 146
  • Joined: 30-November 11

Re: My code keeps telling me im missing a bracket at the end

Posted 14 November 2012 - 06:20 PM

I think on line 105 there should be a closing bracket, instead of an opening
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: My code keeps telling me im missing a bracket at the end

Posted 14 November 2012 - 06:33 PM

View Postslehmann101, on 14 November 2012 - 06:20 PM, said:

I think on line 105 there should be a closing bracket, instead of an opening


It is still the same this is what its saying
CandleLine.Applet.java:109 '}' expected
Was This Post Helpful? 0
  • +
  • -

#4 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 849
  • View blog
  • Posts: 2,585
  • Joined: 29-July 11

Re: My code keeps telling me im missing a bracket at the end

Posted 14 November 2012 - 07:22 PM

After going through your code and adding fields and methods for everything that is missing, I did have to add a closing brace to proper;y end the class declaration.
Was This Post Helpful? 0
  • +
  • -

#5 WolverineX  Icon User is offline

  • New D.I.C Head

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

Re: My code keeps telling me im missing a bracket at the end

Posted 14 November 2012 - 11:06 PM

It just needs a "}" at the end.. How come you never found this mistake? Don't you run your codes on Eclipse? It will easily spot it out! If you don't have Eclipse then you really must get it. It'll make your life easier. Cheers!
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

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

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: My code keeps telling me im missing a bracket at the end

Posted 15 November 2012 - 09:06 AM

View PostWolverineX, on 15 November 2012 - 02:06 AM, said:

It just needs a "}" at the end.. How come you never found this mistake? Don't you run your codes on Eclipse? It will easily spot it out! If you don't have Eclipse then you really must get it. It'll make your life easier. Cheers!

Don't agree. Better to learn the hard way without an IDE.
After a few months you can start to think about it.
Was This Post Helpful? 1
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7806
  • View blog
  • Posts: 13,200
  • Joined: 19-March 11

Re: My code keeps telling me im missing a bracket at the end

Posted 15 November 2012 - 09:13 AM

View PostWolverineX, on 15 November 2012 - 01:06 AM, said:

It just needs a "}" at the end.. How come you never found this mistake? Don't you run your codes on Eclipse? It will easily spot it out! If you don't have Eclipse then you really must get it. It'll make your life easier. Cheers!



Bad advice. Learn to program instead- part of that is knowing the structure of your code.

When you write an opening bracket, brace, or paren, write the closing one immediately. Then go back and fill in the material that goes in between.

First this:
public void foo()  

Then this:
public void foo(int index, String str)


Then this:
public void foo(int index, String str){    
} 


And then fill in the code for the method.

Same thing for for loops, while loops, whatever.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1