QUOTE(Martyr2 @ 17 Oct, 2007 - 07:54 PM)

Just so you know, most programmers think of a sentinel as a specific numeric value... usually integer. But I will let you slide. The trick here is how you are comparing your values. In the string class you will see a function called
equals() which will be very useful here. The idea is this...
CODE
// Compare the value in sentinel against the item name.
while(!item_name.equals(SENTINEL)) {
// Block of code here
}
This function is nice and clean and very easy to use for comparing strings. It essentially takes the value passed to it and compares it to the string calling it. So in the code above it takes "999" and says "are you NOT equal to the value in item_name?" If the answer is yes, we continue.
Hopefully this makes some sense.
Enjoy!

Thanks for the leniency! Haha, thank you so much again.
QUOTE(sgmikewoody @ 17 Oct, 2007 - 07:56 PM)

QUOTE(Martyr2 @ 17 Oct, 2007 - 07:54 PM)

Just so you know, most programmers think of a sentinel as a specific numeric value... usually integer. But I will let you slide. The trick here is how you are comparing your values. In the string class you will see a function called
equals() which will be very useful here. The idea is this...
CODE
// Compare the value in sentinel against the item name.
while(!item_name.equals(SENTINEL)) {
// Block of code here
}
This function is nice and clean and very easy to use for comparing strings. It essentially takes the value passed to it and compares it to the string calling it. So in the code above it takes "999" and says "are you NOT equal to the value in item_name?" If the answer is yes, we continue.
Hopefully this makes some sense.
Enjoy!

Thanks for the leniency! Haha, thank you so much again.
UPCCodes.java:26: variable item_name might not have been initialized
while (!item_name.equals(SENTINEL))
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Still having a bit of difficulty with this one. I will play with it a bit more I suppose

CODE
import java.io.*;
import java.util.*;
public class UPCCodes
{
static final String SENTINEL = "999";
public static void main(String [] args) throws
FileNotFoundException
{
PrintWriter outFile = new
PrintWriter("c:\\Java\\invoice1.dat");
Scanner console = new Scanner(System.in);
double price;
String item_name;
int items_scanned = 0;
System.out.println("This order-processing program simulates "
+ "using a \ncode reader to scan an item "
+ "and create an invoice.\n");
System.out.println("Please scan the name of the first item: ");
item_name = console.next();
if(!item_name.equals(SENTINEL))
{
System.out.println("Please scan the price of the " +item_name
+": ");
price = console.nextDouble();
++items_scanned;
outFile.println(item_name);
outFile.println(price);
}
while (!item_name.equals(SENTINEL))
{
System.out.println("Please scan the name of the first item: ");
item_name = console.next();
if(!item_name.equals(SENTINEL))
{
System.out.println("Please scan the price of the " +item_name
+": ");
price = console.nextDouble();
++items_scanned;
outFile.println(item_name);
outFile.println(price);
}
}
System.out.print("\n" + items_scanned + " items scanned.");
outFile.close();
}
}
Think I got it =D
This post has been edited by sgmikewoody: 17 Oct, 2007 - 07:11 PM