Home > Back-end >  Java based problem
Java based problem

Time:05-10

Could you tell me why to delete building steps when an error, it should be how to modify?
 

import java.util.*;

Public class House {
Public String name="";
Public String telephone="";
Public String adress="";
Public String sent="";
Public String state="";
Public int id=0;

Boolean loop=true;
Scanner input=new Scanner(System.in);
String choice="";
The String key="";
Collection List=new ArrayList<> (a);

Public House (int id, String name, String telephone, String adress, String sent, String state) {
this.id=id;
this.name=name;
This. Telephone=telephone;
This. Adress=adress;
This. Sent=sent;
This. The state=state;
}

Public House () {

}

Public String getName () {
return name;
}

Public String getTelephone () {
Return the telephone;
}

Public String getAdress () {
The return adress.
}

Public String getSent () {
The return sent.
}

Public String getState () {
Return the state;
}

Public int getId () {
return id;
}

Public void elegantly-named setName (String name) {
this.name=name;
}

Public void setTelephone (String telephone) {
This. Telephone=telephone;
}

Public void setAdress (String adress) {
This. Adress=adress;
}

Public void setSent (String sent) {
This. Sent=sent;
}

Public void setState (String state) {
This. The state=state;
}

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

Public void HouseMenu () {
Do {
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- housing rental System -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
System. The out. Println (" t \ \ t 1 new homes ");
System. Out. Println (" t \ \ t find housing 2 ");
System. The out. Println (" three t \ \ t delete house ");
System. The out. Println (" t \ \ t 4 to modify housing information ");
System. The out. Println (" t \ \ t 5 housing list ");
System. The out. Println (" t \ \ t 6 back out ");
System. The out. Print (" please select (1-6) ");
Key=input. Next ();

The switch (key) {
Case "1" : this addHouse ();
break;
Case "2" : this. SearchHouse ();
break;
Case "3" : this. DeleteHouse ();
break;
Case "4" : this setHouse ();
break;
Case "5" : this. HouseList ();
break;
Case "6" : this. The exit ();
break;
Default:
System. The out. Println (" input is wrong, to choose, ");
}
} while (loop);
}

Public void addHouse () {
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- add house -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
System. The out. Print (" number: ");
Id=input. NextInt ();
System. The out. Print (" name: ");
Name=input. Next ();
System. The out. Print (" call: ");
Telephone=input. Next ();
System. The out. Print (" address: ");
Adress=input. Next ();
System. The out. Print (" rent: ");
Sent=input. Next ();
System. The out. Print (" state (not rent/lease) : ");
State=input. Next ();
House, House=new House (id, name, telephone, adress, sent, state);
List. The add (house);
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- add complete -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
}

Public void searchHouse () {
System. Out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- to find the house -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
System. The out. Print (" please input you want to find id: ");
Int n=input. NextInt ();
For (House House: list) {
If (house. GetId ()==n) {
System. Out.println (house. GetId () + "\ t" + house. The getName () + "\ t" + "house. GetTelephone () +" \ t "
+ house. GetAdress () + "\ t" + "house getSent () +" \ t "+ house. The getState ());
}
}
}

Public void deleteHouse () {
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- - removed houses -- -- -- -- -- -- -- -- -- -- -- -- ");
int n;

While (true) {
System. Out. Print (" please choose to delete number (1 exit) : ");
N=input. NextInt ();
If (n==1)
break;
System. The out. Println (" confirm whether delete (Y/N) : please be careful choice: ");
System. The out. Print (" please input your choice (Y/N) : ");
Choice=input. Next ();
If (" N ". The equals (choice) | | "Y". The equals (choice)) {
break;
}
}

If (choice) equals (" Y ")) {
For (House House: list) {
If (house. GetId ()==n) {
List. Remove (house);
}
}
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- - delete completed -- -- -- -- -- -- -- -- -- -- - ");
}
}

Public void setHouse () {
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- change houses -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Int m;
While (true) {
System. Out. Print (" please choose to modify the number (1 exit) : ");
M=input nextInt ();
If (m==1)
break;
For (House House: list) {
If (house. GetId ()==m) {
System. Out. Print (" name (" + "house. The getName () +") ");
String name=input. Next ();
House. Elegantly-named setName (name);

System. The out. Print (" telephone (" + "house. GetTelephone () +") ");
String telephone=input. Next ();
House. SetTelephone (telephone);

Address System. Out. Print (" (" + "house. GetAdress () +") ");
String adress=input. Next ();
House. SetAdress (adress);

Rent System. Out. Print (" (" + "house. GetSent () +") ");
The String sent=input. Next ();
House. SetSent (sent);

State System. Out. Print (" (" + "house. GetState () +") ");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related