Ok so Im trying to get the code to read from two files. Do alittle math and then write to a new file. My guess is it has something to do with the loop considering everything before the works. Heres the code
CODE
package lab05;
import java.util.Scanner;
import java.io.*;
import javax.swing.JOptionPane;
public class Main {
//Programmer: Kevin Thayer
//Date Due: October 14, 2008
//Project Number: 5
//Project Name: Inventory Tracker
//Project Describition:
// This program will be used to track inventory. The program will load the
// inventory data from a data file and will read transactions from a
// seperate transaction file. Once the inventory has ben updated, the
// program should display a product order report and should rewrite the
// orginal inventory file with the new, updated data.
public static void main(String[] args)throws IOException {
Scanner kbd = new Scanner(System.in);
String name;
String name2;
double quantity;
double price;
double shelf;
double reorder;
double quantitySold;
double orderAmount;
String inputFileName;
String inputFileName2;
//Get File Names
inputFileName = GetFileName();
inputFileName2 = GetFileName();
//Process Inventory Update
//Get Inventory Item
File inFileHandle = new File(inputFileName);
Scanner inFile = new Scanner (inFileHandle);
// Order Report Heading
System.out.println("Product Reorder Report:");
System.out.println("Product Name\t" + "Order Amount");
while(inFile.hasNext()) {
name = GetEntry(inFile);
quantity = Double.parseDouble(GetEntry(inFile));
price = Double.parseDouble(GetEntry(inFile));
shelf = Double.parseDouble(GetEntry(inFile));
reorder = Double.parseDouble(GetEntry(inFile));
inFile.close();
File inFileHandle2 = new File (inputFileName2);
Scanner inFile2 = new Scanner (inFileHandle2);
name2 = GetEntry(inFile2);
quantitySold = Double.parseDouble(GetEntry(inFile2));
inFile2.close();
//Update Inventory
quantity = quantity - quantitySold;
if(quantity <= reorder){
// How Much to Order
orderAmount = shelf - quantity;
System.out.println(name2 + "\t" + orderAmount);
}
FileWriter appendFile = new FileWriter("C:/Users/Kevin/Desktop/inventory2.txt", true);
PrintWriter outFile = new PrintWriter(appendFile);
outFile.println(name);
outFile.println(quantity);
outFile.println(price);
outFile.println(shelf);
outFile.println(reorder);
outFile.close();
}
}
public static String GetFileName() {
String fName;
fName = JOptionPane.showInputDialog(null, "Please enter a file name.");
return fName;
}
public static String GetEntry(Scanner inFile) {
throw new UnsupportedOperationException();
}
}
Also here is the output I get from it:
init:
deps-jar:
Compiling 1 source file to C:\Users\Kevin\Documents\NetBeansProjects\Lab05\build\classes
compile:
run:
Product Reorder Report:
Product Name Order Amount
Exception in thread "main" java.lang.UnsupportedOperationException
at lab05.Main.GetEntry(Main.java:93)
at lab05.Main.main(Main.java:46)
Java Result: 1
BUILD SUCCESSFUL (total time: 14 seconds)
Finally if this helps at all. The two files I have are called Inventory and Transactions. In the inventory file I have:
(Contains from Top to Bottum: Name, Quantity, Price, Shelf, Reorder)
20" TV
8
350.00
20
5
Ipod Touch
13
220.00
20
10
Nintendo Wii
2
250.00
15
5
DVD Movie
20
15.00
30
10
Playstion 3
5
400.00
10
5
Acer Laptop
3
600.00
5
1
In Transactions I have (From top to bottum: Name2, QuantitySold):
20" TV
3
Ipod Touch
4
Nintendo Wii
2
DVD Movie
8
Playstation 3
1
Acer Laptop
0
THANK YOU to Anyone who can help