package Wardrobe;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;
源代码:
package Wardrobe;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String args[]) throws IOException, ClassNotFoundException, EOFException{
/**
* Data initialization
*/
ArrayList<FamilyMember> userData=new ArrayList<FamilyMember>();
StorageLocation bedroom=new StorageLocation("BedRoom",1);//initialize the default storageLocation
Wardrobe w1=new Wardrobe(bedroom,1);//initialize the wardrobe
FamilyMember father=new FamilyMember("Jack",1000,1000);
FamilyMember mother=new FamilyMember("Rose",1001,1001);
FamilyMember son=new FamilyMember("Billy",1002,1002);//three default familyMembers
userData.add(mother);
userData.add(father);
userData.add(son);//add default familyMembers to arrayList
Item i1=new Item("Nike","Black",500,2013,175,father,"Cloth","Nice");
Item i2=new Item("Adidas","White",300,2012,75,mother,"Bag","Too big");//two default items
w1.addItem(i1);
w1.addItem(i2);//add default items to wardrobe
/**
* login window
*/
System.out.println("===============================");
System.out.println("| Wardrobe System |");
System.out.println("===============================");
Scanner scanner=new Scanner(System.in);
int tempID=0,tempPassword=0;
boolean userCheckState=false;
System.out.printf("Please Input The UserID:");
tempID=scanner.nextInt();
System.out.printf("Please Input The Password:");
tempPassword=scanner.nextInt();//scan the ID number and password the user types in
for(FamilyMember i:userData){//check if it suits one of FamilyMember
if(i.getID()==tempID&&i.getPassword()==tempPassword){
System.out.println("Successfully login!");
userCheckState=true;
break;
}
}
if(!userCheckState){
System.out.println("Wrong ID or Password!");
}
FileInputStream fi=new FileInputStream("file");
ObjectInputStream oi=new ObjectInputStream(fi);
ArrayList<Wardrobe> SL=new ArrayList<Wardrobe>();
while(oi.readObject()!=null){
SL.add((Wardrobe)oi.readObject());//就是这行代码出错。。
}
/**
* function view for users to
* find the command which they
* want to operate
*/
System.out.println("================================");