My program is supposed to ask someone to enter a serial number and the price of an object.
Here is the class driver
import java.io.*;
import java.util.Scanner;
public class InventoryDriver {
public static void main(String[] args)throws IOException {
Inventory storeItem = new Inventory(" ", 1);
PrintWriter storeFile = new PrintWriter("StoreInventory.txt");
Scanner scan = new Scanner(System.in);
boolean running = true;
String itemNum = " ";
double originalPrice = 1;
while (running) {
System.out.println("Enter the item number or enter 0 when you are done.");
itemNum = scan.nextLine();
storeItem.setItemNum(itemNum);
storeFile.println(itemNum);
if(itemNum.equals("0")) break;
System.out.println("Enter the original price or enter 0 when you are done.");
originalPrice = scan.nextDouble();
storeItem.setOriginalPrice(originalPrice);
storeFile.println(originalPrice);
if(originalPrice == 0) break;
}
//create a scanner variable named myFile
Scanner myFile = new Scanner(new File("StoreInventory.txt"));
//Read my data from my file into the variablles
//itemNum = myFile.nextLine();
//originalPrice = myFile.nextDouble();
printSaleData(myFile, storeItem);
//Close the file
myFile.close();
storeFile.close();
}
}
After working perfectly the first time with this output
Enter the item number or enter 0 when you are done.
input
Enter the original price or enter 0 when you are done.
input
But when the loop goes back, it prints this
Enter the item number or enter 0 when you are done.
input
Enter the original price or enter 0 when you are done.
input
Enter the item number or enter 0 when you are done.
Enter the original price or enter 0 when you are done.
input
What about my code changes the loop after the first go?
P.S. Even after I break the loop the whole program stops, and won't call the "printSaleData" sub-module to the main module.