I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except the Delete and Modify Button. The Search button works but it only searchs the new .dat file or what is set in the array. Not sure what is going on there. But if I can get my delete and modify button to work that will be good.
Code.... -
-
import javax.swing.JFrame;
-
import java.awt.*;
-
import javax.swing.*;
-
import java.awt.event.*;
-
import java.io.*;
-
import java.text.NumberFormat;
-
import javax.swing.border.*;
-
import java.net.*;
-
import java.util.StringTokenizer;
-
-
// Begin Inventory Class
-
-
class Inventory extends JFrame implements Serializable
-
{
-
private Container cp = getContentPane();
-
private static int ItemNumber[] = new int[100];
-
private static String name[] = new String[100];
-
private static int Quantity[] = new int[100];
-
private static double Price[] = new double[100];
-
private static int i = 0;
-
-
public Inventory(){
-
setLayout(new FlowLayout());
-
}
-
-
public Inventory(int _ItemNumber, String _name, int _Quantity, double _Price)
-
{
-
ItemNumber[i] = _ItemNumber;
-
name[i] = _name;
-
Quantity[i] = _Quantity;
-
Price[i] = _Price;
-
i = i + 1;
-
}
-
public static int getItemNumber(int k) // Get ItemNumber
-
{
-
return ItemNumber[k]; // Return ItemNumber
-
}
-
public static String getItemName(int k) // Get ItemName
-
{
-
return name[k]; // Return name
-
}
-
public static int getItemQuantity(int k) // Get Item Quantity
-
{
-
return Quantity[k]; // Return Quantity
-
}
-
public static double getItemPrice(int k) // Get ItemPrice
-
{
-
return Price[k]; // Return Price
-
}
-
public static void setItemNumber(int k,int value) //Set ItemNumber
-
{
-
ItemNumber[k] = value;
-
}
-
public static void setItemName(int k,String value) // Set ItemName
-
{
-
name[k] = value;
-
}
-
public static void setItemQuantity(int k,int value) // Set ItemQuantity
-
{
-
Quantity[k] = value;
-
}
-
public static void setItemPrice(int k,double value) // Set ItemPrice
-
{
-
Price[k] = value;
-
}
-
-
public static void DeleteItem(int k) // DeleteItem old DeleteItemName
-
{
-
for(int j=k;j<getCount()-1;j++)
-
{
-
setItemNumber(j,getItemNumber(j+1));
-
setItemName(j,getItemName(j+1));
-
setItemQuantity(j,getItemQuantity(j+1));
-
setItemPrice(j,getItemPrice(j+1));
-
}
-
-
i-=1;
-
-
-
}
-
public static int SearchItem(String value) // Search Item old SearchItemName
-
{
-
int k = -1;
-
-
for(int j=0;j<getCount();j++)
-
{
-
if(getItemName(j).equals(value))
-
k = j;
-
}
-
return k;
-
}
-
-
public static double valueOfInventory(double p,int u) // value of Inventory
-
{
-
return p*u;
-
}
-
-
-
public static void swap(int j, int min)
-
{
-
String tmp;
-
tmp = name[j];
-
name[j] = name[min];
-
name[min] = tmp;
-
-
int temp = ItemNumber[j];
-
ItemNumber[j] = ItemNumber[min];
-
ItemNumber[min] = temp;
-
-
temp = Quantity[j];
-
Quantity[j] = Quantity[min];
-
Quantity[min] = temp;
-
-
double temp1 = Price[j];
-
Price[j] = Price[min];
-
Price[min] = temp1;
-
-
}
-
// Show Value of Inventory
-
-
public double showValueofInventory()
-
{
-
double totalVal = 0;
-
for (int j = 0; j < getCount(); j++)
-
{
-
totalVal = totalVal + valueOfInventory(Price[j], Quantity[j]);
-
}
-
return totalVal;
-
}
-
-
public static int getCount()
-
{
-
return i;
-
}
-
-
} // End Inventory Class
-
-
// Begin Products Class
-
-
class Products implements Serializable
-
{
-
public static double valueOfInventory(double p, double u,double rf)
-
{
-
double vOfI = (p * u) + (p*u*rf);
-
return (vOfI );
-
}
-
-
public static double valueOfRestockFee(double p, double rf)
-
{
-
double percent = 0;
-
percent = (p * 5) / 100;
-
return percent;
-
}
-
-
} // End Products Class
-
5 3356
More Code... -
-
// Being PC Class
-
-
class PC extends Inventory implements ActionListener,Serializable
-
{
-
-
static String manufacture[] = new String[100]; // Subclass to add to Workstation - Manufacture
-
static String Workstation_Type[] = new String[100]; // Subclass to add to Workstation - Workstation Type
-
static double restockingFee[] = new double[100]; // Restock Fee to add to inventory value
-
static int i; //removed = 0;
-
static double TotalVal;
-
static int navItem;
-
static Boolean isRecordLoadedFromFile = false;
-
-
private Container cp = getContentPane();
-
-
GridBagConstraints c;
-
GridBagConstraints cconstraint ;
-
Border titledborder;
-
JPanel pan,pan2;
-
-
String labels[] ={"ID:","Manufacture:", "Workstation ID:", "Workstation Name:","Workstation Type:", "Quantity:", "Price: $", "Restocking Fee: $", "Workstation Inventory Value with Fee: $", "Total Workstation Value with Fee: $" }; // field names
-
int len1 = labels.length;
-
JLabel lbl[] = new JLabel[len1];
-
JTextField txtfield1[] = new JTextField[len1];
-
-
String blabels[] ={ "First", "Previous", "Next", "Last" }; //Bottom Buttons
-
int blen = blabels.length;
-
JButton navigate[] = new JButton[blen];
-
-
String cmdlabels[] ={"Load File", "Add", "Modify", "Delete", "Search", "Save","Cancel" }; // Tops Buttons
-
int cmdlen = cmdlabels.length;
-
JButton cmdbutton[] = new JButton[cmdlen];
-
-
JLabel lblImg;
-
File file;
-
public String FileName;
-
-
public PC(String Manufacture,String Workstation_ID, double restockingFee, int Item_Number, String Item_Name, int Items_in_Stock, double Item_Price)
-
-
{
-
super(Item_Number, Item_Name, Items_in_Stock, Item_Price);
-
this.manufacture[i] = Manufacture;
-
this.Workstation_Type[i] = Workstation_ID;
-
this.restockingFee[i] = restockingFee;
-
i = i + 1;
-
}
-
-
public String toString()
-
-
{
-
StringBuffer sb = new StringBuffer("\nManufacture: ").append(manufacture).append("\n");
-
sb.append(super.toString());
-
-
return sb.toString();
-
}
-
-
public static double getRestockFee(int val)
-
-
{
-
return restockingFee[val];
-
}
-
-
public static void setWorkstation_ID(int k,String value)
-
-
{
-
Workstation_Type[k] = value;
-
}
-
-
public static void setManufacture(int k,String value)
-
-
{
-
manufacture[k] = value;
-
}
-
-
public static String getWorkstation_ID(int k) // Get Workstation_ID
-
-
{
-
return Workstation_Type[k]; // Return Workstation Type
-
}
-
-
public static String getManufacture(int k) // Get Manufacture
-
-
{
-
return manufacture[k]; // Return Manufacture
-
}
-
-
-
public static void DeleteItem(int k) // Delete PC Item
-
-
{
-
for(int j=k;j<getCount()-1;j++)
-
{
-
setItemNumber(j,getItemNumber(j+1));
-
setItemName(j,getItemName(j+1));
-
setItemQuantity(j,getItemQuantity(j+1));
-
setItemPrice(j,getItemPrice(j+1));
-
setWorkstation_ID(j,getWorkstation_ID(j+1));
-
setManufacture(j,getManufacture(j+1));
-
}
-
-
i = i - 1;
-
-
}
-
-
public void ShowInvent()
-
{
-
setLayout(new FlowLayout());
-
-
GridBagLayout contlayout = new GridBagLayout(); // layout for container
-
GridBagConstraints cconstraint = new GridBagConstraints(); // constraint for container
-
-
GridBagLayout gblayout = new GridBagLayout(); // layout for panel
-
GridBagConstraints gbconstraint = new GridBagConstraints(); // constraint for container
-
-
-
FileName = "C://data//inventory.dat"; // .dat file
-
-
try
-
{
-
String strDirectoy = "C://data"; // start location
-
boolean success = (new File(strDirectoy)).mkdir();
-
file = new File(FileName);
-
success = file.createNewFile();
-
-
// Add Top Buttons
-
pan = new JPanel();
-
gblayout = new GridBagLayout();
-
gbconstraint = new GridBagConstraints();
-
pan.setLayout(gblayout);
-
-
gbconstraint.gridwidth = 1;
-
gbconstraint.gridheight = 1;
-
gbconstraint.gridy = 0;
-
More Code -
for (int i = 0; i < cmdlen; i++)
-
{
-
cmdbutton[i] = new JButton(cmdlabels[i]);
-
cmdbutton[i].addActionListener(this);
-
gbconstraint.gridx = i;
-
pan.add(cmdbutton[i], gbconstraint);
-
}
-
-
titledborder = BorderFactory.createTitledBorder("Main Navigation");
-
pan.setBorder(titledborder);
-
-
// add panel to container
-
cconstraint.gridwidth = 4;
-
cconstraint.gridheight = 1;
-
cconstraint.gridx = 0;
-
cconstraint.gridy = 2;
-
cp.add(pan, cconstraint);
-
// addition complete
-
-
//create first panel
-
pan = new JPanel();
-
gblayout = new GridBagLayout();
-
gbconstraint = new GridBagConstraints();
-
pan.setLayout(gblayout);
-
-
for (int i = 0; i < 2; i++)
-
{
-
for (int j = 0; j < len1; j++)
-
{
-
int x = i;
-
int y = j;
-
if (x == 0)
-
{
-
lbl[j] = new JLabel(labels[j]);
-
lbl[j].setHorizontalAlignment(JLabel.LEFT);
-
lbl[j].setPreferredSize(new Dimension(250, 15));
-
gbconstraint.insets = new Insets(10, 0, 0, 0);
-
gbconstraint.gridx = x;
-
gbconstraint.gridy = y;
-
pan.add(lbl[j], gbconstraint);
-
}
-
else
-
{
-
txtfield1[j] = new JTextField(15);
-
txtfield1[j].setHorizontalAlignment(JLabel.LEFT);
-
txtfield1[j].setEnabled(false);
-
lbl[j].setLabelFor(txtfield1[j]);
-
gbconstraint.gridx = x;
-
gbconstraint.gridy = y;
-
pan.add(txtfield1[j], gbconstraint);
-
}
-
}
-
} // first panel done
-
-
-
Border titledborder = BorderFactory.createTitledBorder("Workstation Inventory Information"); // Title - Border
-
pan.setBorder(titledborder);
-
-
// main panel
-
cconstraint.gridwidth = 1;
-
cconstraint.gridheight = 1;
-
cconstraint.gridx = 0;
-
cconstraint.gridy = 0;
-
cp.add(pan, cconstraint);
-
// main panel created.
-
-
// add image to panel
-
pan = new JPanel();
-
gblayout = new GridBagLayout();
-
gbconstraint = new GridBagConstraints();
-
pan.setLayout(gblayout);
-
-
gbconstraint.gridwidth = 1; gbconstraint.gridheight = 1;
-
gbconstraint.gridy = 0;
-
-
lblImg = new JLabel((new ImageIcon(getClass().getResource("pclogo.jpg")))); // logo
-
lblImg.setPreferredSize(new Dimension(120, 120));
-
pan.add(lblImg);
-
-
cconstraint.gridwidth = 1;
-
cconstraint.gridheight = 1;
-
cconstraint.gridx = 0;
-
cconstraint.gridy = 1;
-
cp.add(pan, cconstraint);
-
// image added
-
-
-
//Create Bottom Button Panel
-
pan = new JPanel();
-
gblayout = new GridBagLayout();
-
gbconstraint = new GridBagConstraints();
-
pan.setLayout(gblayout);
-
gbconstraint.gridwidth = 1; gbconstraint.gridheight = 1;
-
gbconstraint.gridy = 0;
-
-
for (int i = 0; i < blen; i++)
-
{
-
navigate[i] = new JButton(blabels[i]);
-
gbconstraint.gridx = i;
-
pan.add(navigate[i], gbconstraint);
-
-
navigate[i].addActionListener(this);
-
}
-
-
titledborder = BorderFactory.createTitledBorder("Button Navigation"); // bottom button navigation
-
pan.setBorder(titledborder);
-
// Bottom Button Panel Created
-
-
// add panel to container
-
cconstraint.gridwidth = 4;
-
cconstraint.gridheight = 1;
-
cconstraint.gridx = 1;
-
cconstraint.gridy = 1;
-
cp.add(pan, cconstraint);
-
// panel added
-
}
-
catch (Exception e)
-
{
-
e.printStackTrace();
-
}
-
}
-
public void setContents(File aFile, String aContents)
-
{
-
BufferedWriter output = null;
-
try
-
{
-
//use buffering
-
output = new BufferedWriter(new FileWriter(aFile, true));
-
output.write(aContents);
-
String newLine = System.getProperty("line.separator");
-
output.write(newLine);
-
}
-
-
catch (Exception ex)
-
{
-
ex.printStackTrace();
-
}
-
-
finally
-
{
-
try
-
{
-
//Buffering
-
if (output != null) output.close();
-
}
-
catch (java.io.IOException e)
-
{
-
e.printStackTrace();
-
}
-
}
-
}
-
public void AddModifyInventory(String Mode)
-
{
-
if (Mode.equals("Insert"))
-
{
-
String Content = txtfield1[1].getText() + "\t" + txtfield1[2].getText() + "\t" + txtfield1[3].getText() + "\t" + txtfield1[4].getText() + "\t" + txtfield1[5].getText() + "\t" + txtfield1[6].getText();
-
setContents(file, Content);
-
JOptionPane.showMessageDialog(null, "Item Successfully Inserted");
-
}
-
}
-
public void ShowInventory(int ItemNo)
-
{
-
txtfield1[0].setText(Integer.toString(ItemNo));
-
txtfield1[1].setText(manufacture[ItemNo]);
-
txtfield1[2].setText(Integer.toString(Inventory.getItemNumber(ItemNo)));
-
txtfield1[3].setText(Inventory.getItemName(ItemNo));
-
txtfield1[4].setText(Workstation_Type[ItemNo]);
-
txtfield1[5].setText(Integer.toString(Inventory.getItemQuantity(ItemNo)));
-
txtfield1[6].setText(Double.toString(Inventory.getItemPrice(ItemNo)));
-
txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(ItemNo), getRestockFee(ItemNo))));
-
txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(ItemNo), Inventory.getItemQuantity(ItemNo), getRestockFee(ItemNo))));
-
txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
-
}
-
public void EnableFields(boolean bflag)
-
{
-
// txtfield1[0].setEnabled(bflag);
-
txtfield1[1].setEnabled(bflag);
-
txtfield1[2].setEnabled(bflag);
-
txtfield1[3].setEnabled(bflag);
-
txtfield1[4].setEnabled(bflag);
-
txtfield1[5].setEnabled(bflag);
-
txtfield1[6].setEnabled(bflag);
-
}
-
-
public double GetTotalInvVal()
-
{
-
TotalVal = 0;
-
for (int j = 0; j < Inventory.getCount(); j++)
-
{
-
TotalVal += Products.valueOfInventory(Inventory.getItemPrice(j), Inventory.getItemQuantity(j), getRestockFee(j));
-
}
-
return TotalVal;
-
}
-
public Integer GetRecordCount()
-
{
-
FileReader fr;
-
BufferedReader br;
-
LineNumberReader lnr;
-
String line;
-
int lno = 0;
-
-
try
-
{
-
lnr = new LineNumberReader(new BufferedReader(new FileReader(FileName)));
-
-
while ((line = lnr.readLine()) != null)
-
{
-
lno = lnr.getLineNumber();
-
}
-
-
lnr.close();
-
}
-
catch (IOException ioErr)
-
{
-
System.out.println(ioErr.toString());
-
System.exit(100);
-
}
-
return lno;
-
}
-
public void showInventory(int itemNo)
-
{
-
int i;
-
FileReader fr;
-
BufferedReader br;
-
LineNumberReader lnr;
-
StringTokenizer st;
-
String line;
-
int item = itemNo + 1;
-
-
int ItemNo = 0;
-
int Items = 0;
-
String ItemManufacture = "";
-
String ItemName = "";
-
String ItemWorkstation_ID = "";
-
double ItemPric = 0;
-
double Total = 0;
-
Integer rFee = 0;
-
int lno;
-
More Code -
-
try
-
{
-
lnr = new LineNumberReader(new BufferedReader(new FileReader(FileName)));
-
-
while ((line = lnr.readLine()) != null)
-
{
-
lno = lnr.getLineNumber();
-
-
-
String s1[];
-
if (item == lno)
-
{
-
s1 = new String[lno];
-
s1[0] = line;
-
st = new StringTokenizer(s1[0]);
-
ItemManufacture = st.nextToken();
-
ItemNo = Integer.parseInt(st.nextToken());
-
ItemName = st.nextToken();
-
ItemWorkstation_ID = st.nextToken();
-
Items = Integer.parseInt(st.nextToken());
-
ItemPric = Double.parseDouble(st.nextToken());
-
-
}
-
s1 = new String[lno];
-
s1[0] = line;
-
st = new StringTokenizer(s1[0]);
-
st.nextToken();
-
st.nextToken();
-
st.nextToken();
-
st.nextToken();
-
Integer Quantity = Integer.parseInt(st.nextToken());
-
Double Price = Double.parseDouble(st.nextToken());
-
Total += Products.valueOfInventory(Price, Quantity, 0.05);
-
}
-
-
lnr.close();
-
}
-
catch (IOException ioErr)
-
{
-
System.out.println(ioErr.toString());
-
System.exit(100);
-
}
-
-
txtfield1[0].setText(Integer.toString(itemNo));
-
txtfield1[1].setText(ItemManufacture);
-
txtfield1[2].setText(Integer.toString(ItemNo));
-
txtfield1[3].setText(ItemName);
-
txtfield1[4].setText(ItemWorkstation_ID);
-
txtfield1[5].setText(Integer.toString(Items));
-
txtfield1[6].setText(Double.toString(ItemPric));
-
txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(ItemPric, 0.05)));
-
txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(ItemPric, Items, 0.05)));
-
txtfield1[9].setText(String.format("%3.2f", Total));
-
}
-
-
public void actionPerformed(ActionEvent e) // button navigation
-
{
-
String btnClicked = ((JButton)e.getSource()).getText();
-
-
-
if(btnClicked.equals("First")) // First Button
-
{
-
-
EnableFields(false);
-
if (isRecordLoadedFromFile)
-
{
-
navItem = 0;
-
showInventory(navItem);
-
}
-
else
-
{
-
navItem = 0;
-
ShowInventory(navItem);
-
}
-
}
-
if (btnClicked.equals("Next")) // Next Button
-
{
-
EnableFields(false);
-
if (isRecordLoadedFromFile)
-
{
-
if (navItem == GetRecordCount() - 1)
-
{
-
navItem = 0;
-
}
-
else
-
{
-
navItem += 1;
-
}
-
if ((GetRecordCount() - 1) >= navItem)
-
showInventory(navItem);
-
else
-
showInventory(GetRecordCount() - 1);
-
}
-
else
-
{
-
if (navItem == getCount() - 1)
-
{
-
navItem = 0;
-
}
-
else
-
{
-
navItem += 1;
-
}
-
ShowInventory(navItem);
-
}
-
}
-
if (btnClicked.equals("Previous")) // Previous Button
-
{
-
EnableFields(false);
-
if (isRecordLoadedFromFile)
-
{
-
if (navItem == 0)
-
{
-
navItem = GetRecordCount() - 1;
-
}
-
else
-
{
-
navItem = navItem - 1;
-
}
-
showInventory(navItem);
-
}
-
else
-
{
-
if (navItem == 0)
-
{
-
navItem = getCount() - 1;
-
}
-
else
-
{
-
navItem = navItem - 1;
-
}
-
ShowInventory(navItem);
-
}
-
}
-
if (btnClicked.equals("Last")) // Last Button
-
{
-
EnableFields(false);
-
if (isRecordLoadedFromFile)
-
{
-
navItem = GetRecordCount() - 1;
-
showInventory(navItem);
-
}
-
else
-
{
-
navItem = getCount() - 1;
-
ShowInventory(navItem);
-
}
-
}
-
if (btnClicked.equals("Save")) // Save Button
-
{
-
AddModifyInventory("Insert"); // Insert Button
-
}
-
if (btnClicked.equals("Load File")) // Load File Button
-
{
-
isRecordLoadedFromFile = true;
-
if (GetRecordCount() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "No Records Found In File");
-
}
-
else
-
{
-
showInventory(0);
-
}
-
}
-
if (btnClicked.equals("Cancel")) // Cancel Button
-
{
-
EnableFields(false);
-
cmdbutton[4].setText("Search"); // Search Button
-
cmdbutton[2].setText("Modify"); // Modify Button
-
cmdbutton[1].setText("Add"); // Add Button
-
if(isRecordLoadedFromFile)
-
showInventory(navItem);
-
else
-
ShowInventory(navItem);
-
}
-
if(btnClicked.equals("Delete")) // Deleve Button
-
{
-
DeleteItem(Integer.parseInt(txtfield1[0].getText()));
-
navItem = getCount() -1;
-
JOptionPane.showMessageDialog(null, "Item Successfully Deleted"); // Field Update
-
ShowInventory(navItem);
-
}
-
if(btnClicked.equals("Search")) // Search Button
-
{
-
cmdbutton[4].setText("GO!"); // Go Button
-
txtfield1[3].setEnabled(true);
-
}
-
if(btnClicked.equals("GO!")) // Go Button
-
{
-
boolean valid = true;
-
if (txtfield1[3].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Workstation Name Required"); // Field Required
-
valid = false;
-
}
-
if(valid)
-
{
-
-
int k = Inventory.SearchItem(txtfield1[3].getText().trim());
-
if(k>=0)
-
{
-
txtfield1[0].setText(Integer.toString(k));
-
txtfield1[1].setText(manufacture[k]);
-
txtfield1[2].setText(Integer.toString(Inventory.getItemNumber(k)));
-
txtfield1[3].setText(Inventory.getItemName(k));
-
txtfield1[4].setText(Workstation_Type[k]);
-
txtfield1[5].setText(Integer.toString(Inventory.getItemQuantity(k)));
-
txtfield1[6].setText(Double.toString(Inventory.getItemPrice(k)));
-
txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(k), getRestockFee(k))));
-
txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(k ), Inventory.getItemQuantity(k), getRestockFee(k))));
-
txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
-
EnableFields(false);
-
cmdbutton[4].setText("Search");
-
-
}
-
else
-
{
-
JOptionPane.showMessageDialog(null, "No Matches Found");
-
cmdbutton[4].setText("Search");
-
EnableFields(false);
-
}
-
}
-
}
-
if(btnClicked.equals("Modify")) // Modify Button
-
{
-
EnableFields(true);
-
-
cmdbutton[2].setText("Click to Edit!");
-
}
-
if(btnClicked.equals("Click to Edit!"))
-
{
-
Boolean valid = true;
-
if (txtfield1[1].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Manufacture Required"); // Require Filed
-
valid = false;
-
}
-
try
-
{
-
Integer.parseInt(txtfield1[2].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Item Number - Only Number Allowed"); // Require Field
-
txtfield1[3].setText("");
-
valid = false;
-
}
-
-
if (txtfield1[3].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Workstation ID Required"); // Require Field
-
valid = false;
-
}
-
-
if (txtfield1[4].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Workstation Type Required"); // Require Field
-
valid = false;
-
}
-
-
try
-
{
-
Integer.parseInt(txtfield1[5].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Quantity in Stock - Only Numbers Allowed"); // Require Field
-
txtfield1[4].setText("");
-
valid = false;
-
}
-
try
-
{
-
Double.parseDouble(txtfield1[6].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Price - Only Numbers Allowed"); // Require Field
-
txtfield1[5].setText("");
-
valid = false;
-
}
-
-
if (valid)
-
{
-
-
//PC.setManufacture(navItem,txtfield1[1].getText());
-
Inventory.setItemNumber(navItem,Integer.parseInt(txtfield1[2].getText()));
-
Inventory.setItemName(navItem,txtfield1[3].getText());
-
setWorkstation_ID(navItem,txtfield1[4].getText());
-
Inventory.setItemQuantity(navItem,Integer.parseInt(txtfield1[5].getText()));
-
Inventory.setItemPrice(navItem,Double.parseDouble(txtfield1[6].getText()));
-
-
txtfield1[6].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(navItem), getRestockFee(navItem))));
-
txtfield1[7].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(navItem ), Inventory.getItemQuantity(navItem), getRestockFee(navItem))));
-
txtfield1[8].setText(String.format("%3.2f",GetTotalInvVal()));
-
EnableFields(false);
-
cmdbutton[2].setText("Modify");
-
-
}
-
}
-
if (btnClicked.equals("Add"))
-
{
-
EnableFields(true);
-
txtfield1[0].setText(Integer.toString(getCount()));
-
txtfield1[1].requestFocus();
-
-
txtfield1[1].setText("");
-
txtfield1[2].setText("");
-
txtfield1[3].setText("");
-
txtfield1[4].setText("");
-
-
txtfield1[5].setText("0");
-
txtfield1[6].setText("0.00");
-
cmdbutton[1].setText("Click to Add!");
-
}
-
if (btnClicked.equals("Click to Add!"))
-
{
-
Boolean valid = true;
-
if (txtfield1[1].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Manufacture Required"); // Require Field
-
valid = false;
-
}
-
try
-
{
-
Integer.parseInt(txtfield1[2].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Item Number - Only Number Numbers Allowed"); // Require Field
-
txtfield1[3].setText("");
-
valid = false;
-
}
-
-
if (txtfield1[3].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Workstation ID Required"); // Require Field
-
valid = false;
-
}
-
-
if (txtfield1[4].getText().trim().length() == 0)
-
{
-
JOptionPane.showMessageDialog(null, "Workstation Name Required"); // Require Field
-
valid = false;
-
}
-
-
try
-
{
-
Integer.parseInt(txtfield1[5].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Quanity - Only Numbers Allowed"); // Require Field
-
txtfield1[4].setText("");
-
valid = false;
-
}
-
try
-
{
-
Double.parseDouble(txtfield1[6].getText());
-
}
-
catch (Exception ex)
-
{
-
JOptionPane.showMessageDialog(null, "Invalid Price - Only Numbers Allowed"); // Require Field
-
txtfield1[5].setText("");
-
valid = false;
-
}
-
-
if (valid)
-
{
-
PC r = new PC(txtfield1[1].getText(),txtfield1[4].getText(), 0.05, Integer.parseInt(txtfield1[2].getText()), txtfield1[3].getText(), Integer.parseInt(txtfield1[5].getText()),
-
Double.parseDouble(txtfield1[6].getText()));
-
txtfield1[7].setText(String.format("%3.2f", Products.valueOfRestockFee(Inventory.getItemPrice(getCount() - 1), getRestockFee(getCount() - 1))));
-
txtfield1[8].setText(String.format("%3.2f", Products.valueOfInventory(Inventory.getItemPrice(getCount() -1 ), Inventory.getItemQuantity(getCount() -1), getRestockFee(getCount() - 1))));
-
txtfield1[9].setText(String.format("%3.2f",GetTotalInvVal()));
-
navItem = getCount() - 1;
-
EnableFields(false);
-
cmdbutton[1].setText("Add");
-
}
-
}
-
-
-
-
}
-
-
} // End PC Class
-
-
Last One -
import java.io.InputStreamReader;
-
import java.io.BufferedReader;
-
import java.io.IOException;
-
import javax.swing.JFrame;
-
-
//begin InvenotoryMain Class
-
-
class InventoryMain
-
{
-
public static void main( String[] args){
-
-
double restockFee = 0.05; // restock fee
-
-
//array Information
-
-
PC p = new PC("Dell","Home",restockFee, 100,"Dell-4400" , 10, 599.00);
-
-
p.ShowInvent();
-
p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
p.setVisible(true);
-
p.setSize(550, 600);
-
-
}
-
-
} // end InventoryMain Class
-
I know this is a lot to ask for in a short notice, but I have worked really hard until now and I just wish my teacher could he me its the last part of the program and I just want to do good in my class. Thanks, If someone could just tell me which part I need to look at and might need to change would help.
Thanks,
Sign in to post your reply or Sign up for a free account.
Similar topics
by: zaidalin79 |
last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
|
by: south622 |
last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
|
by: MonolithTMA |
last post by:
Greetings all,
I am new here, and aside from my introductory post, this will be my first.
I am working on an Inventory program for a class I am taking. I've searched the forums here and have...
|
by: mistb2002 |
last post by:
I am trying to modify my program to add and delete inventory items. I tried just adding but I am getting mutliple errors help.
This is what my program currently looks like
// Display The...
|
by: cblank |
last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory...
|
by: pinkf24 |
last post by:
I cannot figure out how to add the following:
Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
|
by: 100grand |
last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one
product at a time, including the item number, the name of the product, the number of
units in stock, the price...
|
by: blitz1989 |
last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the...
|
by: lilsugaman |
last post by:
I have to assignment which includes the following: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |