1. Expand the class Inventory, developed in the previous part of the project, by doing the following:
• Providing “pop-up” windows to ask for the names of the input and output files. Do this in the constructor; in other words, save the output file name for the finalizer.
• Handle any exceptions that might be generated in the class.
2. Create another program to make use of the class Inventory. The options – (1) modify the information for a part, (2) list the parts, (3) list the parts needing to be reordered, or (4) add a new part – should be menu driven. The “reports” (displays) should be neatly formatted. Your grade will be based on how well the program works and if it is “user friendly” – not how fancy the windows (if any) are.
Turn in the two files – the Inventory class file and the main program file.
Here is my code for the Inventory class file.
import java.io.*;
import java.util.*;
class InventoryExample{
static int SIZE = 100; // Max. size for arrays
int partNum[];
int quantity[];
double cost[];
double wholesaleCost[];
int reorderQuantity[];
String description[];
int invCnt;
private PrintWriter op;
//constructor
public InventoryExample() throws FileNotFoundException {
partNum = new int[SIZE];
quantity = new int [SIZE];
cost = new double[SIZE];
wholesaleCost = new double[SIZE];
reorderQuantity = new int[SIZE];
description = new String[SIZE];
invCnt = 0;
// Get filename and create the file
FileWriter writer = null;
BufferedReader user = new BufferedReader(
new InputStreamReader( System.in ) );
String fileName = "";
System.out.print("Enter Filename-->"); System.out.flush();
try
{
fileName = user.readLine().trim();
writer = new FileWriter( fileName );
}
catch ( IOException iox )
{
System.out.println("Error in creating file");
return;
}
}
//method to add a new part, cost, and quantity
public void addPart(int pn, int q, double c, double wc, int rq, String d){
for(int i=0; i<invCnt; i++)
if(partNum[i] == pn)
return; // part already exits
// otherwise, add part to data base
partNum[invCnt]=pn;
quantity[invCnt]=q;
cost[invCnt]=c;
wholesaleCost[invCnt] = wc;
reorderQuantity[invCnt] = rq;
description[invCnt] = d;
invCnt++;
}
//method to return the quantity of part 'pn' in stock
public int getQuantity(int pn){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn)
return quantity[i];
}
return -1; // failure to find part
}
//method to return the cost of part 'pn'
public double getCost(int pn){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn)
return cost[i];
}
return -1; // failure to find part
}
//method to return the wholesale cost of part 'pn'
public double getWholesale(int pn){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn)
return wholesaleCost[i];
}
return -1; // failure to find part
}
//method to return the reorder point of part 'pn'
public int getReorder(int pn){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn)
return reorderQuantity[i];
}
return -1; // failure to find part
}
//method to return the description of part 'pn'
public String getDescription(int pn){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn)
return description[i];
}
return "Not Found"; // failure to find part
}
//Accessors
//method to set the quantity of part 'pn' in stock
public void setQuantity(int pn, int quant){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn) quantity[i] = quant;
}
// failure to find part, nothing happens
}
//method to set the cost of part 'pn' in stock
public void setCost(int pn, double amnt){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn) cost[i] = amnt;
}
// failure to find part, nothing happens
}
//method to set the wholesale cost of part 'pn' in stock
public void setWholesale(int pn, double amnt){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn) wholesaleCost[i] = amnt;
}
// failure to find part, nothing happens
}
//method to set the reorder point of part 'pn' in stock
public void setReorder(int pn, int num){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn) reorderQuantity[i] = num;
}
// failure to find part, nothing happens
}
//method to change the description of part 'pn' in stock
public void setDescription(int pn, String str){
for(int i=0;i<invCnt;i++){
if(partNum[i]==pn) description[i] = str;
}
// failure to find part, nothing happens
}
//finalizer,
public void finalize(){
for (int i=0; i<invCnt; i++) {
op.print(partNum[i]+" ");
op.print(quantity[i]+" ");
op.print(cost[i]+" ");
op.print(wholesaleCost[i]+" ");
op.print(reorderQuantity[i]+" ");
op.println(description[i]);
}
op.println("-1 0 0 0 0 Last Line");
op.close();
}
}
I believe that I have the input file part correct and the output part correct too. The inventory class does compile without any errors but I haven't been able to test it yet because I cannot get a test program to compile and work. This is where I start having a lot of the trouble. I will post what I have so far and the errors that I get when I compile. Please keep the laughter to a minimum as I am very new to this.
import java.text.NumberFormat;
class InventoryTest {
public static void main(String args[])
{
// creates new inventory
InventoryExample = new InventoryExample( );
// add the software to the inventory
getDescription = new InventoryExample("Part");
InventoryExample.addpart(description);
getWholesale = new InventoryExample("10");
InventoryExample.addpart(description);
getCost = new InventoryExample("10");
InventoryExample.addpart(description);
getQuantity = new InventoryExample("10");
InventoryExample.addpart(description);
getReorder = new InventoryExample("10");
InventoryExample.addpart(description);
// sort by sftitle
InventoryExample.sortproduct( );
// prints inventory
for (int i = 0; i < InventoryExample.getproductCount(); i++) {
System.out.println(InventoryExample.getproduct(i));
System.out.println();
}
}
}
Here are the compile errors that I am getting.
----jGRASP exec: javac -g InventoryTest.java
InventoryTest.java:12: cannot find symbol
symbol : variable InventoryExample
location: class InventoryTest
InventoryExample = new InventoryExample( );
^
InventoryTest.java:16: cannot find symbol
symbol : variable getDescription
location: class InventoryTest
getDescription = new InventoryExample("Part");
^
InventoryTest.java:16: cannot find symbol
symbol : constructor InventoryExample(java.lang.String)
location: class InventoryExample
getDescription = new InventoryExample("Part");
^
InventoryTest.java:17: cannot find symbol
symbol : variable description
location: class InventoryTest
InventoryExample.addpart(description);
^
InventoryTest.java:19: cannot find symbol
symbol : variable getWholesale
location: class InventoryTest
getWholesale = new InventoryExample("10");
^
InventoryTest.java:19: cannot find symbol
symbol : constructor InventoryExample(java.lang.String)
location: class InventoryExample
getWholesale = new InventoryExample("10");
^
InventoryTest.java:20: cannot find symbol
symbol : variable description
location: class InventoryTest
InventoryExample.addpart(description);
^
InventoryTest.java:22: cannot find symbol
symbol : variable getCost
location: class InventoryTest
getCost = new InventoryExample("10");
^
InventoryTest.java:22: cannot find symbol
symbol : constructor InventoryExample(java.lang.String)
location: class InventoryExample
getCost = new InventoryExample("10");
^
InventoryTest.java:23: cannot find symbol
symbol : variable description
location: class InventoryTest
InventoryExample.addpart(description);
^
InventoryTest.java:25: cannot find symbol
symbol : variable getQuantity
location: class InventoryTest
getQuantity = new InventoryExample("10");
^
InventoryTest.java:25: cannot find symbol
symbol : constructor InventoryExample(java.lang.String)
location: class InventoryExample
getQuantity = new InventoryExample("10");
^
InventoryTest.java:26: cannot find symbol
symbol : variable description
location: class InventoryTest
InventoryExample.addpart(description);
^
InventoryTest.java:28: cannot find symbol
symbol : variable getReorder
location: class InventoryTest
getReorder = new InventoryExample("10");
^
InventoryTest.java:28: cannot find symbol
symbol : constructor InventoryExample(java.lang.String)
location: class InventoryExample
getReorder = new InventoryExample("10");
^
InventoryTest.java:29: cannot find symbol
symbol : variable description
location: class InventoryTest
InventoryExample.addpart(description);
^
InventoryTest.java:32: cannot find symbol
symbol : method sortproduct()
location: class InventoryExample
InventoryExample.sortproduct( );
^
InventoryTest.java:35: cannot find symbol
symbol : method getproductCount()
location: class InventoryExample
for (int i = 0; i < InventoryExample.getproductCount(); i++) {
^
InventoryTest.java:36: cannot find symbol
symbol : method getproduct(int)
location: class InventoryExample
System.out.println(InventoryExample.getproduct(i));
^
19 errors
Basically I think it would be easier to scrap the test file and start new. Thanks for any help in advance guys!!!

New Topic/Question
Reply



MultiQuote



|