Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

HELP DEBUGGING Inventory Manager

  Asked By: Ashan    Date: Jul 12    Category: Java    Views: 1288
  

Can anyone help debug this inventory manager

public class InventoryObject
{
String id, Description;
int StQuant, RdrLvl;
float UCPr, USPr;

public InventoryObject()
{
id = " ";
Description = " ";
StQuant = 0;
UCPr=0;
USPr=0;
RdrLvl= 0;

}

public InventoryObject(String id, String des, int sq, float ucp,
float usp, int rl)
{
setID(id);
setDescrip(des);
setStQuant(sq);
setUCPr(ucp);
setUSPr(usp);
setRdrLvl(rl);

}
//ID
public void setID(String s)
{
id = s;
}

public String getID()
{
return id;
}

//DESCRIPTION
public void setDescrip (String Desc)
{
Description = Desc;
}

public String getDescrip()
{
return Description;
}

//STOCK QUANTITY
public void setStQuant(int SQ)
{
StQuant = SQ;
}

public int getStQuant()
{
return StQuant;
}

//UNIT COST PRICE

public void setUCPr (float ucp)
{
UCPr = ucp;
}

public float getUCPr()
{
return UCPr;
}


//UNIT SELLING PRICE
public void setUSPr(float usp)
{
USPr = usp;
}

public float getUSPr()
{
return USPr;
}


//REORDER LEVEL
public void setRdrLvl(int rl)
{
RdrLvl = rl;
}

public int getRdrLvl()
{
return RdrLvl;
}

public String toString()
{
String outData;
float PM = 0;
PM = getStQuant() * (getUSPr() - getUCPr());
outData =("\n" + getID()+"\n" + getDescrip()+"\n" + getStQuant
()+"\n" + getUCPr() + "\n" + getUSPr() + "\n" +getRdrLvl() + "\n" +
PM);

return outData;
}//toString



}//End public class InventoryObject

//********************INVENTORY MANAGER************************
//The password for ALL EDITING OPTIONS is PASSWORD in UPPERCASE
//Password protection was instituted to prevent accidental or
deliberate tampering
//of database


import java.io.*;
import javax.swing.JScrollPane;
import javax.swing .JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JDialog;
import javax.swing.JTextArea;
public class InventoryManager
{

public static void SearchID(int num, InventoryObject list[],
String Key)
{
int max = 100;
int FoundKey = -1;
float PM = 0;
for(int i =0; i<num; i++)
{
if(list[i].id.equals(Key)== true)
{
FoundKey = i;//If key is found then the index is kept
} //All IDs are unique.
}
if (FoundKey != -1)
{
PM = PrMn(list[FoundKey].UCPr,list[FoundKey].USPr,list
[FoundKey].StQuant);
String OUTJOP ="\nITEM ID " + list[FoundKey].id
+ "\nDESCRIPTION " +

list[FoundKey].Description + "\nUNIT COST PRICE $" + list
[FoundKey].UCPr + "\nUNIT SELLING

PRICE $"+ list[FoundKey].USPr + "\nSTOCK QUANTITY " + list
[FoundKey].StQuant + "\nREORDER

LEVEL "+ list[FoundKey].RdrLvl +"\nPROFIT MARGIN $" + PM
+ "\n\n";
//String OUTJOP =(list[FoundKey].toString());
JOptionPane.showMessageDialog(null,OUTJOP,"ITEM
ID Inventory Search

Results",JOptionPane.INFORMATION_MESSAGE);
EditInventory(list,FoundKey);//Function Call to Edit Record
if Found
}
else
{
JOptionPane.showMessageDialog(null,"Item with
ID NO: " + Key + " Not

Found","ITEM ID Inventory Search
Results ",JOptionPane.INFORMATION_MESSAGE);
}

} //End Search By Item ID

public static void SearchCost(int num, InventoryObject list
[], float Key)
{
int max = 100;
int count = -1;
float PM = 0;
InventoryObject TempArray[];
TempArray = new InventoryObject[max];
String OutputScr = "Search Results Cost Price $" + Key + "\n";
//Definition of variables for Scroll Pane for display of results
JTextArea outputText = new JTextArea(20,22);
JScrollPane scroller = new JScrollPane(outputText);

int FoundKey = -1;
for(int i =0; i<num; i++)
{
if(list[i].UCPr == Key)
{
FoundKey = i;
String Output = (list[FoundKey].toString());
// JOptionPane.showMessageDialog(null,Output
+ "\n" +

PrMn(list[FoundKey].UCPr,list[FoundKey].USPr,list
[FoundKey].StQuant),"UNIT COST PRICE Inventory

Search Result",JOptionPane.PLAIN_MESSAGE);

count = count + 1; //Keeps count of matches to search key

String Des = list[FoundKey].Description;
String ID = list[FoundKey].id;
float UCP = list[FoundKey].UCPr;
float USP = list[FoundKey].USPr;
int StQ = list[FoundKey].StQuant;
int RL = list[FoundKey].RdrLvl;

//Temporary array is used to hold matching queries that
will be sorted later in

function
TempArray[count] = new InventoryObject(ID,
Des,StQ,UCP,USP,RL);
}
}

if (FoundKey != -1)
{
//Display of Number of records found matching query
JOptionPane.showMessageDialog(null,(count + 1) + " Records
Matching Cost Price of $"

+ Key,"Search Cost Results",JOptionPane.INFORMATION_MESSAGE);

/*Sorting Options Menu called for Results of query the
number found is
greater than 2 */
if (count > 1)
{
String SortString = JOptionPane.showInputDialog
(null," 1 : Sort By ID\n 2 :

Sort By Cost Price\n 3 : Sort By Selling Price\n 4 : Sort
By Quantity\n 5 : Sort By

Reorder Level\n 6 : Sort By Description\n 7 : Sort By Profit
Margin","SORT

OPTIONS",JOptionPane.PLAIN_MESSAGE);
if (SortString.equals("1"))
{
SortID(count+1,TempArray);
}
else if (SortString.equals("2"))
{
SortCost(count+1,TempArray);
}
else if (SortString.equals("3"))
{
SortSelling(count+1,TempArray);
}
else if (SortString.equals("4"))
{
SortQuant(count+1,TempArray);
}
else if (SortString.equals("5"))
{
SortReord(count+1,TempArray);
}
else if (SortString.equals("6"))
{
SortDesc(count+1,TempArray);
}
else if (SortString.equals("7"))
{
SortPrMn(count+1,TempArray);
}
else
{
JOptionPane.showMessageDialog(null,"INVALID
CHOICE!!!!","OPTION

ERROR",JOptionPane.WARNING_MESSAGE);
}
} // end if count > 1
else //If less than 3 records found, these are not sorted
{
if(count == 0) //If one record is found, it is
prepared for output via Scroll

Pane
{
PM = PrMn(TempArray[0].UCPr,TempArray
[0].USPr,TempArray[0].StQuant);
OutputScr +="\nITEM ID\t\t" + TempArray[0].id
+ "\nDESCRIPTION\t\t" +

TempArray[0].Description + "\nUNIT COST PRICE \t$" +TempArray[0].UCPr
+ "\nUNIT SELLING

PRICE\t$"+ TempArray[0].USPr + "\nSTOCK QUANTITY\t" + TempArray
[0].StQuant + "\nREORDER LEVEL\t"+

TempArray[0].RdrLvl +"\nPROFIT MARGIN\t" + PM + "\n\n";
}
else//If two recourds found, they are prepared for
output via the Scroll Pane
{
PM = PrMn(TempArray[0].UCPr,TempArray
[0].USPr,TempArray[0].StQuant);
OutputScr +="\nITEM ID\t\t" + TempArray[0].id
+ "\nDESCRIPTION\t\t" +

TempArray[0].Description + "\nUNIT COST PRICE \t$" +TempArray[0].UCPr
+ "\nUNIT SELLING

PRICE\t$"+ TempArray[0].USPr + "\nSTOCK QUANTITY\t" + TempArray
[0].StQuant + "\nREORDER LEVEL\t"+

TempArray[0].RdrLvl +"\nPROFIT MARGIN\t" + PM + "\n\n";
PM = PrMn(TempArray[1].UCPr,TempArray
[1].USPr,TempArray[1].StQuant);
OutputScr +="\nITEM ID\t\t" + TempArray[1].id
+ "\nDESCRIPTION\t\t" +

TempArray[1].Description + "\nUNIT COST PRICE \t$" +TempArray[1].UCPr
+ "\nUNIT SELLING

PRICE\t$"+ TempArray[1].USPr + "\nSTOCK QUANTITY\t" + TempArray
[1].StQuant + "\nREORDER LEVEL\t"+

TempArray[1].RdrLvl +"\nPROFIT MARGIN\t" + PM + "\n\n";
// System.out.println(TempArray[q].toString());
}

//Setting the string Output to be displayed in the
Scroll Pane
outputText.setText(OutputScr);
JOptionPane.showMessageDialog(null,scroller,"UNIT
COST PRICE Inventory Search

Result",JOptionPane.PLAIN_MESSAGE);
}
JOptionPane.showMessageDialog(null,"To Edit Go to SEARCH BY
ITEM ID\n Edit by Cost

Price","Edit Option",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"Item with
Unit Cost Price of: $" + Key

+ " Not Found", "UNTI COST PRICE Inventory Search
Results",JOptionPane.INFORMATION_MESSAGE);
}

}//End Search By Unit Cost Price

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Dirck Jansen     Answered On: Jul 12

What specifically is the problem or bug you are encountering?

The InventoryManager uses a KeyBoard object and a FileOperations
object. They are not java  objects, did you create them yourself? It
looks like they would be i/o objects... look at the java tutorials
for help  with that.

java.sun.com/.../index.html

 
Didn't find what you were looking for? Find more on HELP DEBUGGING Inventory Manager Or get search suggestion and latest updates.




Tagged: