Home > Back-end >  Java mobile phone address book, directly on the code inside also has a problem
Java mobile phone address book, directly on the code inside also has a problem

Time:11-23

IOperatorMobile. Java
Package com. Geminno. Mobile;


Public interface IOperatorMobile {
Public void addMobile ();
Public Mobile [] showMobile ();
Public Mobile [] showMobileByName (); 1. Want to ask this is what mean?
Public void deleteByName ();
Public void updateByName ();
}
Java Mobile.
Package com. Geminno. Mobile;


Public class Mobile {
Private int id;
Private String code;
private String name;
Private String tel;
Private String address;
Public Mobile (String code, String name, String tel, String address) {
Super ();
this.code=code;
this.name=name;
This. Tel=tel;
This. The address=address;
}

Public Mobile (int id, String code, String name, String tel, String address) {
Super ();
this.id=id;
this.code=code;
this.name=name;
This. Tel=tel;
This. The address=address;
}


Public int getId () {
return id;
}


Public void setId (int id) {
this.id=id;
}


Public Mobile () {
Super ();
//TODO Auto - generated constructor stub
}
Public String getCode () {
The return code.
}
Public void setCode (String code) {
this.code=code;
}
Public String getName () {
return name;
}
Public void elegantly-named setName (String name) {
this.name=name;
}
Public String getTel () {
Return tel;
}
Public void setTel (String tel) {
This. Tel=tel;
}
Public String getAddress () {
The return address.
}
Public void setAddress (String address) {
This. The address=address;
}


@ Override
Public int hashCode () {
Final int prime=31;
Int result=1;
Result=prime * result + ((address==null)? 0: address. HashCode ()); 2. The ternary operator is what meaning, why prime initial value assignment 31
Result=prime * result + ((code==null)? 0: code. HashCode ()); The result is what assignment 1?
Result=prime * result + id;
Result=prime * result + ((name==null)? 0: name. HashCode ());
Result=prime * result + ((tel==null)? 0: tel. HashCode ());
return result;
}


@ Override
Public Boolean equals (Object obj) {3. Here the Object obj mean what I think it should be a class,,,
If (this==obj)
return true;
If (obj==null)
return false;
If (getClass ()! )=obj. GetClass () 4) method can also is not equal to?
return false;
Mobile other=(Mobile) obj;
If (address==null) {
If (other address!=null)
return false;
} else if (! Address. Equals (other. Address))
return false;
If (code==null) {
If (other code!=null)
return false;
} else if (! Code. The equals (other code))
return false;
If (id!=other. Id)
return false;
If (name==null) {
If (other name!=null)
return false;
} else if (! Name. The equals (other name))
return false;
If (tel==null) {
If (other tel!=null)
return false;
} else if (! Tel. Equals (other. Tel))
return false;
return true;
}


}


MobileMain. Java
Package com. Geminno. Mobile;


Public class MobileMain {


Public MobileMain () {
System. Out.println (
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- welcome to use mobile phone address book -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -");
System. The out. Println (" \ t1 to view all ");
System. The out. Println (" \ t2 add personnel ");
System. The out. Println (" \ t3 modification information ");
System. The out. Println (" \ t4 delete personnel ");
System. The out. Println (" \ t5 find personnel ");
System. The out. Println (" \ t6 exit ");


System. The out. Print (" please select [1-6] : ");
}




}

OperatorMobileImpl. Java
Package com. Geminno. Mobile;


import java.util.Scanner;


Public class OperatorMobileImpl implements IOperatorMobile {
Mobile [] mobiles;
int index; 5. This index is not the assignment,,, why on earth didn't didn't also add static error? Initial value?
Int id=1;
Public OperatorMobileImpl () {
Mobiles=new Mobile [5].
}

@ Override
Public void addMobile () {
System. The out. Println (" add contacts ");
System. The out. Println (" please input your name: ");
Scanner sc=new Scanner(System.in);
String name=sc. NextLine ();
System. The out. Println (" please enter the phone number: ");
String tel=sc. NextLine ();
System. The out. Println (" please enter the qq number: ");
String qq=sc. NextLine ();
System. The out. Println (" please enter the address: ");
String address=sc. NextLine ();
Mobile person0=new Mobile (id, qq, name, tel, address).
If (index & lt; Mobiles. Length) {
Mobiles [index]=person0;
index++;


} else {
Mobile newperson []=new Mobile [mobiles. Length * 2];
for (int i=0; I & lt; The index; I++) {
Newperson [I]=mobiles [I];


}
Newperson [index]=person0;
Mobiles=newperson;
index++;
}
Id++;
System. The out. Println (" address book increase success,,,,,, ");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related