📄 mainlist.java~11~
字号:
package phonebook;
import javax.swing.JOptionPane;
import java.io.*;
import java.util.*;
public class MainList {
public static void main(String[] args) {
int i =1,j=1,k=0;
String name;
PhoneList list = new PhoneList();
PersonInformation editPerson = new PersonInformation();
String choice = JOptionPane.showInputDialog("Enter your choice");
while(!choice.equalsIgnoreCase("quit")){
editPerson = new PersonInformation();
if(choice.equalsIgnoreCase("add")){
editPerson.inputInformation();
editPerson.outputInformation();
if(list.isEmpty())
list.add(editPerson);
else
i = list.myAdd(editPerson);
}
if(choice.equalsIgnoreCase("del")){
try{
list.remove(i);
}
catch(NoSuchElementException e){
System.out.println("The list is empty");
}
}
if(choice.equalsIgnoreCase("edit")){
editPerson.inputInformation();
editPerson.outputInformation();
try{
list.set(i,editPerson);
}
catch(NoSuchElementException e){
System.out.println("The list is empty");
}
}
if(choice.equalsIgnoreCase("search")){
name = JOptionPane.showInputDialog("Enter the name");
for(j = 1,k=0;j <= list.size();j++){
if(((PersonInformation)list.get(j)).name.equalsIgnoreCase(name)){
i = j;
k=1;
break;
}
}
if(k == 1)
((PersonInformation)list.get(i)).outputInformation();
else
System.out.println("the person is not in the list");
}
choice = JOptionPane.showInputDialog("Enter your choice");
}
}
}
class PersonInformation{
String name,telphone,mobile,email;
public PersonInformation(){
}
public void inputInformation(){
name = JOptionPane.showInputDialog("Enter the name");
telphone = JOptionPane.showInputDialog("Enter the telphone number");
mobile = JOptionPane.showInputDialog("Enter the mobilephone number");
email = JOptionPane.showInputDialog("Enter the email");
}
public void outputInformation(){
System.out.println("name: "+name+"\ntelphone num: "+telphone+"\n mobilephone num: "+mobile+"\nemail: "+email);
}
}
class PhoneList extends LinkedList{
public int myAdd( PersonInformation inform ){
int i =1;
while ((inform.name.compareToIgnoreCase(((PersonInformation)this.get(i)).name) > 0 )||(i == this.size()+1))
i++;
if(i == 1)
this.addFirst((Object)inform);
else if(i <= this.size())
this.add( i, (Object)inform );
else
this.add((Object)inform);
return i;
}
}
class DiskFile{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -