The first class
import java.io.*;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.*;
import java.util.Formatter;
public class Project implements Serializable
{
TestProject s=new TestProject();
Scanner sc=new Scanner(System.in);
private int accNo;
private String company;
private int type;
private int quantity;
private double price;
private int newQuantity;
private double newPrice;
static int x=0;
private int eq;
private Formatter output;
public Project()
{
// save(TestProject[] accessory);
}
public static void save(TestProject accessory [])
{
try {
ObjectOutputStream objOut = new ObjectOutputStream(new FileOutputStream("student.txt"));
objOut.writeObject(accessory);
objOut.close();
}
catch(Exception e)
{
System.out.println("E");
}
}
public Project(int update)
{
getaccNo();
}
public void setaccNo(int acc_No)
{
accNo=acc_No;
}
public void setCompany(String company1)
{
company=company1;
}
public void setType(int type1)
{
type=type1;
}
public void setQuantity(int quantity1)
{
quantity=quantity1;
}
public void setPrice(double price1)
{
price=price1;
}
public int getaccNo()
{
return accNo;
}
public int getEq()
{
return eq;
}
public void startj()
{
System.out.println("** Computer Accessories Store **\n"+"How Much Equipments do you have");
int eq=sc.nextInt();
}
public String getCompany()
{
return company;
}
public int getQuantity()
{
return quantity;
}
public double getPrice()
{
return price;
}
public int getType()
{
return type;
}
String show()
{
return(" "+accNo+" "+" "+company+" "+type+" "+quantity+
" "+" "+price);
}
public void add()
{
Scanner sc=new Scanner(System.in);
System.out.println("What is the Serial ID: ");
accNo=sc.nextInt();
System.out.println("What is the Company name: ");
company=sc.next();
System.out.println("What is the type of the equipment:\n1-Mouse\n2-KeyBoard\n3-Monitor\n4-Printer ");
type=sc.nextInt();
while((type>4)||(type<1))
{
System.out.println("Sorry, there's no such a type");
System.out.println("What is the type of the equipment:\n1-Mouse\n2-KeyBoard\n3-Monitor\n4-Printer ");
type=sc.nextInt();
}
System.out.println("What is the quantity of the equipment: ");
quantity=sc.nextInt();
System.out.println("How much it costs for each equipment: ");
price=sc.nextDouble();
}
}
The second class
import java.util.Scanner;
import java.io.*;
import java.io.File;
import javax.swing.*;
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.io.Serializable;
//import java.io.PrintWriter;
public class TestProjectSerializable
{
static int c=0;
static int eq=0;
static Project accessory[]=new Project[100];
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int arraylength=accessory.length;
try{
objOut = new ObjectOutputStream(new FileOutputStream("AA.txt"));
}
catch(Exception e)
{
System.out.println("E");
}
int choose=0;
System.out.println("** Computer Accessories Store **\n");
//arraylength-eq;
do{
System.out.println("1-Add new Accessory\n2-Update Accessory(Quantity,Price)\n3-Sell Accessory\n4-View Reports\n5-Exit");
choose=sc.nextInt();
switch(choose)
{
case(1):
{
System.out.println("How Much Equipments do you have");
eq=sc.nextInt();
//File file=new File("AAA.txt");
//OutputStream w=new ObjectOutputStream(file);
//OutputStream output = null;
for(int i=0;i<eq;i++)
{
System.out.println("Please Fill the information for the equipment number: "+(i+1));
accessory[c]=new Project();
accessory[c].add();
try{
objOut.writeObject(accessory);
objOut.flush();
objOut.close();
}
catch(Exception e)
{
System.out.println(e);
}
c++;
}
}
}
}
}
There's an error says that TestProjectSerializable is not Serializable.
please help :(