📄 address.java
字号:
public void clear()
{
for(int i=1;i<=24;i++)
System.out.println();
System.out.println("*******************************************************************");
}
public void listAll()
{
clear();
note temp1,temp2;
int i=1;
for(temp1=head,temp2=head.next;temp1!=null;)
{
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
temp1=temp2;
if(temp1!=null)
{
temp2=temp2.next;
i++;
}
else break;
}
current_head=current_tail=current=head;
System.out.println("*******************************************************************");
}
public void listCustomizeNext(int n)
{
note temp1=null,temp2=null;
int i=1;int done=1;
if((current_head==head)&&(current_tail==head))
{
temp1=head;
temp2=temp1.next;
current_head=temp1;
for(;temp1!=null&&i<=n;)
{
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
temp1=temp2;
if(temp1!=null)
{
temp2=temp2.next;
i++;
}
else
{
System.out.println("You have reache end of the list.");
break;
}
}
if(temp1!=null)
current_tail=temp1.prior;
else
current_tail=tail;
}
else
{
if(current_tail.next==null)
System.out.println("You have reached end of the list.");
else
{
temp1=current_tail.next;
temp2=temp1.next;
current_head=temp1;
for(;temp1!=null&&i<=n;)
{
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
temp1=temp2;
if(temp1!=null)
{
temp2=temp2.next;
i++;
}
else
{
System.out.println("you have reached end of the list.");
break;
}
}
if(temp1==null)
current_tail=tail;
else
current_tail=temp1.prior;
}
}
System.out.println("*******************************************************************");
}
public void listCustomizePrivious(int n)
{
note temp1,temp2,temp;
int i=1;
if((current_tail==head)&&(current_head==head))
{
temp1=head;
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
System.out.println("You have reached head of the list.");
}
else
{
if(current_head==head)
System.out.println("You have reached head of the list.");
else
{
temp1=current_head.prior;
temp2=temp1.prior;
current_tail=temp1;
for(;temp1!=null&&i<=n;)
{
temp1=temp2;
if(temp1!=null)
{
temp2=temp2.prior;
i++;
}
else
break;
}
if(temp1==null)
{
i=1;
current=current_head=head;
for(temp1=head;temp1!=current_tail.next;temp1=temp1.next,i++)
{
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
}
System.out.println("You have reached head of the list.");
}
else
{
i=1;
for(current_head=temp1.next,temp1=current_head;temp1!=current_tail.next;temp1=temp1.next,i++)
{
System.out.print(i+"\nNAME: "+temp1.name+"\nTEL: ");
System.out.println(temp1.telephone_num+"\nEMAIL: "+temp1.email+"\nADDRESS: "+temp1.address);
k=i;
}
}
}
}
System.out.println("*******************************************************************");
}
public int getK()
{
return k;
}
public void help()
{
System.out.println("*******************************************************************");
System.out.println("add --Add a new record. "+
"\ndelete n --Delete a reocrd.for example:delete 2 .You will delete second record.\n Of course,you should list some records or find a record first."+
"\nedit n --Edit a record.for example: edit 2 .You will edit second record.\n Of course,you should list some records or find a record first."+
"\nfind name --find the record called 'name'.for example:find Jackson"+"\nclear --Clear the screen."+
"\nhelp --Get the help."+
"\nsave --Save the changes to disk."+"\nlistall --List all the record."+"\nquit --Quit the program"+
"\nfirst n --List first n records."+"\nlast n --List last n records."+
"\nnext n --list next n records."+"\nprevious n --List previous n records."+
"\ncounte --Counte the num of all the records."+
"\n\ncautions:when you add or edit a record ,you should make sure:\n 1 The name should not be aparted.for example :'Haiwil Jackson' is illegl."+
"\n 2 The name,email and address should not content numbers,on the opposite,the TEL. should content numbers only."+
"\n 3 The name,email and address can content chinese.So you can add a record just like 张三.");
System.out.println("*******************************************************************");
}
public int counteList(note head) {
note temp = head;
int i = 1;
if (temp.next != null) {
i = i + counteList(temp.next);
}
return i;
}
public void counte()
{
System.out.println("The num of records is "+counteList(head));
System.out.println("*******************************************************************");
}
}
public class address {
public static void main(String args[]) throws IOException {
build action= new build();
String input,NAME,EMAIL,ADDRESS;
double TEL;
int n;
BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
StreamTokenizer in=new StreamTokenizer(buffer);
in.eolIsSignificant(false);
in.wordChars(33,122);
do
{
in.nextToken();
input=in.sval;
if(input.equals("quit"))
System.exit(0);
else if(input.equals("find"))
{
in.nextToken();
input=in.sval;
if( !action.find(input))
System.out.println("Sorry ,can't find the record.");
}
else if(input.equals("add"))
{
System.out.print("Name: ");
in.nextToken();
NAME=in.sval;
System.out.print("TEL: ");
in.nextToken();
TEL=in.nval;
System.out.print("EMAIL: ");
in.nextToken();
EMAIL=in.sval;
System.out.print("Address: ");
in.nextToken();
ADDRESS=in.sval;
action.add(NAME, TEL, EMAIL, ADDRESS);
System.out.println("record has been added.");
}
else if(input.equals("delete"))
{
in.nextToken();
n=(int)Math.round(in.nval);
if(n>action.getK()||n<=0)
System.out.println("Sorry,can't find the record.");
else
{
if(action.delete(n))
System.out.println(" Record has been deleted.");
else
System.out.println("Sorry,can't find the record to delete");
}
}
else if(input.equals("edit"))
{
in.nextToken();
n=(int)Math.round(in.nval);
if(n>action.getK()||n<=0)
System.out.println("Sorry,can't find the record.");
else
{
System.out.print("Name: ");
in.nextToken();
NAME=in.sval;
System.out.print("TEL: ");
in.nextToken();
TEL=in.nval;
System.out.print("EMAIL: ");
in.nextToken();
EMAIL=in.sval;
System.out.print("Address: ");
in.nextToken();
ADDRESS=in.sval;
if( action.edit(n, NAME, TEL, EMAIL, ADDRESS))
System.out.println("record has been changed.");
else
System.out.println("Sorry,can't changed the record");
}
}
else if(input.equals("listall"))
{
action.listAll();
}
else if(input.equals("first"))
{
in.nextToken();
n=(int)Math.round(in.nval);
action.first(n);
}
else if(input.equals("last"))
{
in.nextToken();
n=(int)Math.round(in.nval);
action.last(n);
}
else if(input.equals("next"))
{
in.nextToken();
n=(int)Math.round(in.nval);
action.listCustomizeNext(n);
}
else if(input.equals("previous"))
{
in.nextToken();
n=(int)Math.round(in.nval);
action.listCustomizePrivious(n);
}
else if(input.equals("clear"))
{
action.clear();
}
else if(input.equals("save"))
{
action.save();
System.out.println("File is saved.");
}
else if(input.equals("help"))
{
action.help();
}
else if(input.equals("counte"))
action.counte();
else
{
System.out.println("error:command not found!");
}
}while(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -