new to java(question on equals)

i'm trying to make a program for my niece. it kind of a shopping game. i am very new to java and any other programming. i keep having a problem with the equals sign(=) i want it to be

publicboolean is016000413702()

{

return item = HAMBURGER_HELPER;

}

but it tells me there is a problem

but it excepts <= , >= , != , and == but i'm not sure if it going to give the same effect

you can find the whole code at

http://www.geocities.com/robmorales2004/JenesisShopping.java or

http://www.geocities.com/robmorales2004/jenesishoppinggame.txt

[756 byte] By [handsomeroba] at [2007-10-1 1:37:50]
# 1
If you want to return true if item is hamburger and false if it's not, then use ==. The single = is for assignment, and == is for comparison.
jverda at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 2
The operator "==", which returns a boolean value, is used for the primitive type variables. (For objects other than primitive types, methods "equals" or the similar are used.)
fsato4a at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 3
return item = HAMBURGER_HELPER;heh, can't help but laugh
MrRoboto11a at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 4

> The operator "==", which returns a boolean value, is

> used for the primitive type variables.

> (For objects other than primitive types, methods

> "equals" or the similar are used.)

To clarify: You can use the == operator for reference types, but most of the time what you want is the equals() method.

jverda at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 5

item = HAMBURGER_HELPER is an assignment, ie you are assigning the value HAMBURGER_HELPER to your variable item.

You obviously are looking to do a comparison if the variable item is equal to HAMBURGER_HELPER. There are two ways to do this: the first is the == operator which tests to see if the two objects are the exact same object. Meaning that they ARE the same object in that they are located at the same location in memory, not just two different objects that happen to have the same contents. The other method of comparison is the .equals() method which is probably what you should use in this case.

return item.equals(HAMBURGER_HELPER);

carr_onstotta at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 6
Since he said that >= and <= work, item and HH must be primitives, not references, so .equals() won't even compile.
jverda at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 7

yeah .equals() won't compile and and i think that they are primitives because i have hamburger helper as double HAMBURGER_HELPER = 2.67;

right after the main method. plus i'm having troubles with numbers in another file. i'm trying to get it to where you enter a 12 digit number and then it associated it with a product but if the number is that long i get a error number "to big" and if you you shrink it to ten numbers it works as long as the first number isn't higher than one is there anyway is can get around this (i've tried making a double and a long). thanks for all of your help here is all of the code if you see any errors a noob like me couldn't. if you have any ideals on how to make a game where you enter the product bar code number and it bring up the product and stores it in memory for a total let me know.

public class JenesisShopping

{

private double item;

public static final double HAMBURGER_HELPER = 2.67;

public static final double EASY_CHEESE = 2.95;

public static final double COCOA_PUFFS = 1.75;

public static final double YELLOW_RICE = 1.95;

public static final double KRAFT_SPIRALS = 1.25;

public static final double MAC_CHEESE = .99;

public static final double GRAVY_CHICKEN = 3.05;

public static final double GRAPE_JUICE = 3.45;

public JenesisShopping(double aItem)

{

item = aItem;

}

public void setItem(double aItem)

{

item = aItem;

}

public double getItem()

{

return item;

}

public boolean is016000413702()

{

return item = HAMBURGER_HELPER;

}

public boolean is044000045524()

{

return item = EASY_CHEESE;

}

public boolean is016000116740()

{

return item = COCOA_PUFFS;

}

public boolean is071072013090()

{

return item = YELLOW_RICE;

}

public boolean is021000658978()

{

return item = KRAFT_SPIRALS;

}

public boolean is070253467905()

{

return item = MAC_CHEESE;

}

public boolean is013000798204()

{

return item = GRAVY_CHICKEN;

}

public boolean is028000008703()

{

return item = GRAPE_JUICE;

}

}

handsomeroba at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 8
Hello there... You have set the return type of your function to be BOOLEAN so you can't return item = "" as it is not BOLLEAN value.
Ashish.Kumar.Aggarwala at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 9

an assignment returns the same type as the variable being assigned.

If you're assigning a boolean to a boolean it returns a boolean, in which case you'd get no compiler error but probably unexpected results.

As you're assigning a numeric value, you're trying to return a numeric value from a method which has a boolean return type.

In Java this is not allowed (in C it is allowed as long as the number is an integer number).

jwentinga at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 10
http://www.javacoffeebreak.com/articles/toptenerrors.htmlError no. 8
LarsDahla at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 11

What about (a bit clumsy, but it should work):if (youBought.equals("016000413702")) {

System.out.println("Hamburger: " + HAMBURGER_HELPER);

total = total + HAMBURGER_HELPER;

} else if (youBought.equals("044000045524")) {

System.out.println("Cheese: " + EASY_CHEESE);

total = total + EASY_CHEESE;

} else if (youBought.equals("016000116740")) {

... e.t.c.

The idea is to let the user enter the number in a String youBought;

LarsDahla at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...
# 12

... and do not use doubles if it can be avoided.

Better to represent prices:int HAMBURGER_HELPER = 267;

Thandouble HAMBURGER_HELPER = 2.67;

Formatting output with the import java.text.DecimalFormat;

LarsDahla at 2007-7-8 1:57:28 > top of Java-index,Security,Event Handling...