📄 pimmanager.java
字号:
import java.io.*;
import java.util.*;
import java.text.*;
public class PIMManager
{
private static boolean ok = true;
private static String list = new String("List");
private static String create = "Create";
private static String save = "Save";
private static String load = "Load";
private static String quit = "Quit";
private static String cmd = new String(); //store the command
private static String cType = new String(); //store the create type
private static ArrayList PIMItem = new ArrayList(); //store the item
public static void saveItem() throws IOException
{
System.out.println("Saving file ...");
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("PIM.sav"));
output.writeObject(PIMItem);
output.close();
System.out.println("Done");
}
public static void loadItem() throws IOException,ClassNotFoundException
{
System.out.println("Loading file ...");
ObjectInputStream input = new ObjectInputStream(new FileInputStream("PIM.sav"));
PIMItem = (ArrayList)input.readObject();
input.close();
System.out.println("Done");
}
public static void main(String args[]) throws Exception
{
System.out.print("Welcome to PIM.\n");
while(ok)
{
System.out.println("---Enter a command (supported commands are List Create Save Load Quit)---");
try
{
BufferedReader enter = new BufferedReader(new InputStreamReader(System.in));
cmd = enter.readLine();
}
catch(IOException e)
{}
int index = cmd.length();
if(index == 0)
{
System.out.println("Unknown command:" + cmd); //if press enter key
continue;
}
else if(index<5&&list.substring(0,index).equalsIgnoreCase(cmd))
{
System.out.println("There are " + PIMItem.size() +" items.");
for(int i = 1;i < PIMItem.size()+1; i++)
{
System.out.println("Item "+ i +":" + PIMItem.get(i-1).toString());
}
}
else if(index<7&&create.substring(0,index).equalsIgnoreCase(cmd))
{
while(ok)
{
System.out.println("Enter an item type (todo, note, contact or appointment)");
try
{
BufferedReader Enter = new BufferedReader(new InputStreamReader(System.in));
cType = Enter.readLine();
}
catch(IOException e)
{}
int Tlong = cType.length();
if(Tlong<5&&"todo".substring(0,Tlong).equalsIgnoreCase(cType))
{
PIMTodo todo = new PIMTodo();
todo.managerTodo();
PIMItem.add(todo);
break;
}
else if(Tlong<5&&"note".substring(0,Tlong).equalsIgnoreCase(cType))
{
PIMNote note = new PIMNote();
note.managerNote();
PIMItem.add(note);
break;
}
else if(Tlong<8&&"contact".substring(0,Tlong).equalsIgnoreCase(cType))
{
PIMContact con = new PIMContact();
con.managerCon();
PIMItem.add(con);
break;
}
else if(Tlong<12&&"appointment".substring(0,Tlong).equalsIgnoreCase(cType))
{
PIMAppointment app = new PIMAppointment();
app.managerApp();
PIMItem.add(app);
break;
}
else
{
System.out.println("Unknown item type");
}
}
}
else if(index<5&&save.substring(0,index).equalsIgnoreCase(cmd))
{
saveItem();
}
else if(index<5&&load.substring(0,index).equalsIgnoreCase(cmd))
{
loadItem();
}
else if(index<5&&quit.substring(0,index).equalsIgnoreCase(cmd))
{
System.exit(0);
}
else
{
System.out.println("Unknown command:" + cmd); //there is not the command
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -