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....
Code....
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
Comment