Hi,
may I know what is wrong with my following codes? It works fine for the very first time when data is entered. However, for the next item to be recorded, it is not possible to read in the code at all. I tried to use System.out.flush() but it seems it is of no avail.
do {
System.out.flush();
System.out.println("\nItems sold: "
;
System.out.println("=============="
;
try {
System.out.flush();
System.out.print("Enter product code: "
;
System.out.flush();
code = stdin.readLine();
} catch (NumberFormatException t)
{
System.out.println("\nPlease enter the correct product code: "
;
System.out.flush();
code = stdin.readLine();
}
try {
System.out.flush();
System.out.print("Enter quantity: "
;
quantity = Integer.parseInt (stdin.readLine());
} catch (NumberFormatException s)
{
System.out.println("\nPlease enter the correct quantity: "
;
System.out.flush();
quantity = Integer.parseInt (stdin.readLine());
}
try {
System.out.print("More items[Y/N]"
;
more = (char)stdin.read();
} catch (NumberFormatException r)
{
System.out.println("\nPlease enter the correct code: "
;
System.out.flush();
more = (char)stdin.read();
}
System.out.flush();
count++;
Item item = new Item(code, quantity);
while (cnt < quantity) {
sold.addElement(item);
cnt++;
}//while
System.out.flush();
} while ((more == 'Y')||(more == 'y'));
may I know what is wrong with my following codes? It works fine for the very first time when data is entered. However, for the next item to be recorded, it is not possible to read in the code at all. I tried to use System.out.flush() but it seems it is of no avail.
do {
System.out.flush();
System.out.println("\nItems sold: "
System.out.println("=============="
try {
System.out.flush();
System.out.print("Enter product code: "
System.out.flush();
code = stdin.readLine();
} catch (NumberFormatException t)
{
System.out.println("\nPlease enter the correct product code: "
System.out.flush();
code = stdin.readLine();
}
try {
System.out.flush();
System.out.print("Enter quantity: "
quantity = Integer.parseInt (stdin.readLine());
} catch (NumberFormatException s)
{
System.out.println("\nPlease enter the correct quantity: "
System.out.flush();
quantity = Integer.parseInt (stdin.readLine());
}
try {
System.out.print("More items[Y/N]"
more = (char)stdin.read();
} catch (NumberFormatException r)
{
System.out.println("\nPlease enter the correct code: "
System.out.flush();
more = (char)stdin.read();
}
System.out.flush();
count++;
Item item = new Item(code, quantity);
while (cnt < quantity) {
sold.addElement(item);
cnt++;
}//while
System.out.flush();
} while ((more == 'Y')||(more == 'y'));