Sorry, I'm totally new and have no real idea about what I'm supposed to tell you. I just really need some help on my java homework so anything would be much appreciated. (:

I feel like I'm already asking for so much.. so I'm really sorry, but can someone explain what local variables, instance variables, class variables, constants & methods are and how I would spot them in my code?

& thanks again. :]

Also, this is the error that I keep getting:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method add(Component) in the type Container is not applicable for the arguments (String)
The method add(String, Component) in the type Container is not applicable for the arguments (String, int)
The method add(Component) in the type Container is not applicable for the arguments (String)

at HwkAssignment2Appl.<init>(HwkAssignment2Appl.java:62)
at HwkAssignment2Appl.main(HwkAssignment2Appl.java:45)

& On to the (not so) wonderful code!

//bring in the package swing components
import javax.swing.*;

public class HwkAssignment2Appl extends JFrame

	 * @param args
	//create object of JPanel
	JPanel mainPanel = new JPanel();
	//create 12 label objects for prompts that let user input three numbers. These three numbers are then added together and then multiplied together to get the tax that would be payed for these objects. The total price of purchase with tax is also displayed. The programmer name is also shown.
	JLabel firstNumberPromptLabel = new JLabel("First Number");
	JLabel firstNumberLabel = new JLabel("          ");
	JLabel secondNumberPromptLabel = new JLabel("Second Number");
	JLabel secondNumberLabel = new JLabel("          ");
	JLabel thirdNumberPromptLabel = new JLabel("Third Number");
	JLabel thirdNumberLabel = new JLabel("         ");
	JLabel resultPromptLabel = new JLabel("Result Number");
	JLabel resultLabel = new JLabel("          ");
	JLabel nameLabel = new JLabel("Programmer Name: Hira Rizvi");
	JLabel taxNumberLabel = new JLabel("Tax of items at 9.75% tax rate");
	JLabel taxLabel = new JLabel("            ");
	//set the tax rate to .0925
	final double TAX_RATE = .0925;

	public static void main(String[] args)
		// create an object of the class and set the close of the X button
		HwkAssignment2Appl myApp = new HwkAssignment2Appl();

	public HwkAssignment2Appl()
		//add label objects to the panel
		mainPanel.add("taxNumberLabel", getDefaultCloseOperation());
		//Create 3 String objects to store in the user entry
		String num1String, num2String, num3String;
		//create 4 integers for the user entries and result
		double num1Integer, num2Integer, num3Integer, resultInteger;
		//create 2 integers for the sum of three integers inputed by      user(additionInteger) and one for the sum of additionInteger and tax(taxInteger) 
		double additionInteger, taxInteger;
		//JOption dialog returns the user entry
		num1String = JOptionPane.showInputDialog(null, "Please enter the   number");
		num2String = JOptionPane.showInputDialog(null, "Please enter the number");
		num3String = JOptionPane.showInputDialog(null, "Please enter the number");
		//Convert from String object to integer
		num1Integer = Integer.parseInt(num1String);
		num2Integer = Integer.parseInt(num2String);
		num3Integer = Integer.parseInt(num3String);
		//add the numbers
		additionInteger = num1Integer + num2Integer + num3Integer;

		//multiply additionInteger by TAX_RATE in order to get the tax of items
		taxInteger = additionInteger * TAX_RATE;
		//add taxInteger and additionInteger to get the result
		resultInteger = additionInteger + taxInteger;		
		//display the variables in the label objects
		resultLabel.setText("" + resultInteger);
		nameLabel.setText("Programmer: Hira Rizvi");

		//add the panel object to the JFrame object
		//set the size and visibility of the JFrame

5 Years
Discussion Span
Last Post by hiralarious

you're calling methods with parameters that aren't of the correct type.
Read the API documentation for the classes and methods involved to figure out what you need to do and change your code accordingly.


The method add(Component) in the type Container is not applicable for the arguments (String)
at HwkAssignment2Appl.<init>(HwkAssignment2Appl.java:62)

At line 62 in your code, you call the add method with an incorrect argument.


Oh wow.
I just woke up and looked back at my code.
That was the easiest fix ever >.>

I really need to stop working at 2 AM. Hahah.
Sorry and thanks to both of you for all your help :]


I just realized that my code has my last name in it.. and that's kind of awkward.
Especially because it pops up when I google my name.
I was wondering if it was possible to delete this thread.. or just edit out my name?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.