Finished estate management
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
91f79ab7ab
commit
5587936cd8
|
@ -84,7 +84,7 @@ public class Main {
|
||||||
System.out.println("Please insert the username and password of a valid estate agent.");
|
System.out.println("Please insert the username and password of a valid estate agent.");
|
||||||
String username = FormUtil.readString("Username");
|
String username = FormUtil.readString("Username");
|
||||||
String passwordInput = FormUtil.readPassword();
|
String passwordInput = FormUtil.readPassword();
|
||||||
EstateAgent agent = _orm.get(username);
|
EstateAgent agent = _orm.getAgent(username);
|
||||||
return agent != null && agent.getPassword().equals(passwordInput);
|
return agent != null && agent.getPassword().equals(passwordInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,119 +112,216 @@ public class Main {
|
||||||
newEstate();
|
newEstate();
|
||||||
break;
|
break;
|
||||||
case LIST_ESTATES:
|
case LIST_ESTATES:
|
||||||
//listEstates();
|
listEstates();
|
||||||
break;
|
break;
|
||||||
case BACK:
|
case BACK:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new estate agent after the usesr has entered the necessary data.
|
* Creates a new estate agent after the usesr has entered the necessary data.
|
||||||
*/
|
*/
|
||||||
private static void newEstate() {
|
private static void newEstate() {
|
||||||
String input = FormUtil.readString("Apartmnet(A)/House(H)");
|
String input = FormUtil.readString("Apartment(A)/House(H)");
|
||||||
boolean apartment = input.equals("A") || input.equals("a");
|
boolean isApartment = input.equals("A") || input.equals("a");
|
||||||
if(apartment){
|
Estate estate;
|
||||||
Apartment estate = new Apartment();
|
if(isApartment){
|
||||||
|
estate = new Apartment();
|
||||||
estate.setCity(FormUtil.readString("Name"));
|
|
||||||
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
estate.setCity(FormUtil.readString("Name"));
|
||||||
estate.setStreet(FormUtil.readString("Street"));
|
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
||||||
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
estate.setStreet(FormUtil.readString("Street"));
|
||||||
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
||||||
|
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
||||||
estate.setFloor(FormUtil.readInt("Floor"));
|
|
||||||
estate.setRent(FormUtil.readInt("Rent"));
|
Apartment apartment = (Apartment) estate;
|
||||||
estate.setRooms(FormUtil.readInt("Rooms"));
|
apartment.setFloor(FormUtil.readInt("Floor"));
|
||||||
input = FormUtil.readString("Balcony(Y/N)");
|
apartment.setRent(FormUtil.readInt("Rent"));
|
||||||
estate.setBalcony(input.equals("Y") || input.equals("y"));
|
apartment.setRooms(FormUtil.readInt("Rooms"));
|
||||||
input = FormUtil.readString("Built-in Kitchen(Y/N)");
|
input = FormUtil.readString("Balcony(Y/N)");
|
||||||
estate.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
apartment.setBalcony(input.equals("Y") || input.equals("y"));
|
||||||
|
input = FormUtil.readString("Built-in Kitchen(Y/N)");
|
||||||
//_orm.persist(estate);
|
apartment.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
||||||
|
|
||||||
System.out.println("Estate with the ID " + estate.getId() + " was created.");
|
//_orm.persist(estate);
|
||||||
}
|
|
||||||
else{
|
System.out.println("Estate with the ID " + estate.getId() + " was created.");
|
||||||
House estate = new House();
|
}
|
||||||
|
else{
|
||||||
estate.setCity(FormUtil.readString("Name"));
|
estate = new House();
|
||||||
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
|
||||||
estate.setStreet(FormUtil.readString("Street"));
|
estate.setCity(FormUtil.readString("Name"));
|
||||||
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
||||||
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
estate.setStreet(FormUtil.readString("Street"));
|
||||||
|
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
||||||
estate.setFloors(FormUtil.readInt("Floors"));
|
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
||||||
estate.setPrice(FormUtil.readInt("Price"));
|
|
||||||
input = FormUtil.readString("Garden(Y/N)");
|
House house = (House) estate;
|
||||||
estate.setGarden(input.equals("Y") || input.equals("y"));
|
house.setFloors(FormUtil.readInt("Floors"));
|
||||||
|
house.setPrice(FormUtil.readInt("Price"));
|
||||||
//_orm.persist(estate);
|
input = FormUtil.readString("Garden(Y/N)");
|
||||||
|
house.setGarden(input.equals("Y") || input.equals("y"));
|
||||||
System.out.println("Estate with the ID " + estate.getId() + " was created.");
|
}
|
||||||
}
|
|
||||||
}
|
//_orm.persist(estate);
|
||||||
|
System.out.println("Estate with the ID " + estate.getId() + " was created.");
|
||||||
/**
|
}
|
||||||
* TODO Change an estate agent after the user has entered the necessary data.
|
|
||||||
*/
|
/**
|
||||||
private static void changeEstate() {
|
* Lists estates.
|
||||||
//Choose Estate from List
|
*/
|
||||||
Estate estate = new Estate();//choosen Estate
|
private static void listEstates() {
|
||||||
|
List<?> estates = _orm.getAll(Type.ESTATE);
|
||||||
estate.setCity(FormUtil.readString("Name"));
|
Menu listEstates = new Menu("Please select the estate you want to modify or delete");
|
||||||
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
System.out.println("List of Estates");
|
||||||
estate.setStreet(FormUtil.readString("Street"));
|
|
||||||
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
final int BACK = 0;
|
||||||
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
|
||||||
|
for (Object o : estates) {
|
||||||
if(estate instanceof Apartment){
|
Estate estate = (Estate) o;
|
||||||
Apartment apartment = (Apartment) estate;
|
listEstates.addEntry("ID: " + estate.getId() + ", Address: " + estate.getStreet() + " "
|
||||||
|
+ estate.getStreetNumber() + ", " + estate.getPostalCode() + " " + estate.getCity(),
|
||||||
|
estate.getId());
|
||||||
apartment.setFloor(FormUtil.readInt("Floor"));
|
}
|
||||||
apartment.setRent(FormUtil.readInt("Rent"));
|
listEstates.addEntry("Back to the Estate management menu", BACK);
|
||||||
apartment.setRooms(FormUtil.readInt("Rooms"));
|
|
||||||
String input = FormUtil.readString("Balcony(Y/N)");
|
// process input
|
||||||
apartment.setBalcony(input.equals("Y") || input.equals("y"));
|
while(true) {
|
||||||
input = FormUtil.readString("Built-in Kitchen(Y/N)");
|
int response = listEstates.show();
|
||||||
apartment.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
|
||||||
|
switch (response) {
|
||||||
//_orm.persist(apartment);
|
case BACK:
|
||||||
|
return;
|
||||||
System.out.println("Estate with the ID " + estate.getId() + " was updated.");
|
default:
|
||||||
}
|
showEstate(response);
|
||||||
else{
|
break;
|
||||||
House house = (House)estate;
|
}
|
||||||
|
}
|
||||||
estate.setCity(FormUtil.readString("Name"));
|
|
||||||
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
}
|
||||||
estate.setStreet(FormUtil.readString("Street"));
|
|
||||||
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
/**
|
||||||
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
* Shows a selected estate.
|
||||||
|
*
|
||||||
house.setFloors(FormUtil.readInt("Floors"));
|
* @param id the id of the selected estate
|
||||||
house.setPrice(FormUtil.readInt("Price"));
|
*/
|
||||||
String input = FormUtil.readString("Garden(Y/N)");
|
private static void showEstate(int id) {
|
||||||
house.setGarden(input.equals("Y") || input.equals("y"));
|
Estate estate = _orm.getEstate(id);
|
||||||
|
|
||||||
//_orm.persist(house);
|
System.out.println("Estate");
|
||||||
|
printEstateDetails(estate);
|
||||||
System.out.println("Estate with the ID " + estate.getId() + " was updated.");
|
|
||||||
}
|
final int MODIFY = 1;
|
||||||
}
|
final int DELETE = 2;
|
||||||
|
final int BACK = 3;
|
||||||
/**
|
|
||||||
* TODO Deletes an estate.
|
Menu showEstateMenu = new Menu("Do you want to modify or delete the estate?");
|
||||||
*/
|
showEstateMenu.addEntry("Modify", MODIFY);
|
||||||
private static void deleteEstate() {
|
showEstateMenu.addEntry("Delete", DELETE);
|
||||||
//Choose estate from list.
|
showEstateMenu.addEntry("Back to the list of estates", BACK);
|
||||||
Estate estate = new Apartment();//choosen estate.
|
|
||||||
//Delete Agent
|
while(true) {
|
||||||
System.out.println("Estate with the ID " + estate.getId() + " was deleted.");
|
int response = showEstateMenu.show();
|
||||||
}
|
|
||||||
|
switch (response) {
|
||||||
|
case MODIFY:
|
||||||
|
modifyEstate(estate);
|
||||||
|
break;
|
||||||
|
case DELETE:
|
||||||
|
deleteEstate(estate);
|
||||||
|
break;
|
||||||
|
case BACK:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the estate details to command line.
|
||||||
|
*
|
||||||
|
* @param estate the estate from which the details should be printed to commandline
|
||||||
|
*/
|
||||||
|
private static void printEstateDetails(Estate estate) {
|
||||||
|
System.out.println("------------------");
|
||||||
|
System.out.println("ID: " + estate.getId());
|
||||||
|
System.out.println("Street: " + estate.getStreet() + " " + estate.getStreetNumber());
|
||||||
|
System.out.println("PostalCode: " + estate.getPostalCode());
|
||||||
|
System.out.println("City: " + estate.getCity());
|
||||||
|
System.out.println("SquareArea: " + estate.getSquareArea());
|
||||||
|
if (estate instanceof House) {
|
||||||
|
House house = (House) estate;
|
||||||
|
System.out.println("Price: " + house.getPrice());
|
||||||
|
System.out.println("Floors: " + house.getFloors());
|
||||||
|
System.out.println("Garden: " + (house.hasGarden() ? "yes" : "false"));
|
||||||
|
}
|
||||||
|
else if (estate instanceof Apartment) {
|
||||||
|
Apartment apartment = (Apartment) estate;
|
||||||
|
System.out.println("Floor: " + apartment.getFloor());
|
||||||
|
System.out.println("Rooms: " + apartment.getRooms());
|
||||||
|
System.out.println("Rent: " + apartment.getRent());
|
||||||
|
System.out.println("Balcony: " + (apartment.hasBalcony() ? "yes" : "no"));
|
||||||
|
System.out.println("Built-in Kitchen: " + (apartment.hasBuiltinKitchen() ? "yes" : "no"));
|
||||||
|
}
|
||||||
|
System.out.println("------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify estate.
|
||||||
|
*
|
||||||
|
* @param estate the modified estate
|
||||||
|
*/
|
||||||
|
private static void modifyEstate(Estate estate) {
|
||||||
|
System.out.println("Modify Estate");
|
||||||
|
printEstateDetails(estate);
|
||||||
|
|
||||||
|
estate.setCity(FormUtil.readString("Name"));
|
||||||
|
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
||||||
|
estate.setStreet(FormUtil.readString("Street"));
|
||||||
|
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
||||||
|
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
||||||
|
|
||||||
|
if(estate instanceof Apartment){
|
||||||
|
Apartment apartment = (Apartment) estate;
|
||||||
|
apartment.setFloor(FormUtil.readInt("Floor"));
|
||||||
|
apartment.setRent(FormUtil.readInt("Rent"));
|
||||||
|
apartment.setRooms(FormUtil.readInt("Rooms"));
|
||||||
|
String input = FormUtil.readString("Balcony(Y/N)");
|
||||||
|
apartment.setBalcony(input.equals("Y") || input.equals("y"));
|
||||||
|
input = FormUtil.readString("Built-in Kitchen(Y/N)");
|
||||||
|
apartment.setBuiltinKitchen(input.equals("Y") || input.equals("y"));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
House house = (House)estate;
|
||||||
|
|
||||||
|
estate.setCity(FormUtil.readString("Name"));
|
||||||
|
estate.setPostalCode(FormUtil.readString("Postal Code"));
|
||||||
|
estate.setStreet(FormUtil.readString("Street"));
|
||||||
|
estate.setStreetNumber(FormUtil.readInt("Street Number"));
|
||||||
|
estate.setSquareArea(FormUtil.readInt("Square Area"));
|
||||||
|
|
||||||
|
house.setFloors(FormUtil.readInt("Floors"));
|
||||||
|
house.setPrice(FormUtil.readInt("Price"));
|
||||||
|
String input = FormUtil.readString("Garden(Y/N)");
|
||||||
|
house.setGarden(input.equals("Y") || input.equals("y"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//_orm.persist(estate);
|
||||||
|
|
||||||
|
System.out.println("------------------");
|
||||||
|
System.out.println("Estate with the ID " + estate.getId() + " was modified.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an estate.
|
||||||
|
*
|
||||||
|
* @param estate the estate that should be deleted
|
||||||
|
*/
|
||||||
|
private static void deleteEstate(Estate estate) {
|
||||||
|
_orm.delete(estate);
|
||||||
|
System.out.println("Estate with the ID " + estate.getId() + " was deleted.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the estate agent management.
|
* Shows the estate agent management.
|
||||||
|
@ -311,7 +408,7 @@ public class Main {
|
||||||
* @param id the id of the selected agent
|
* @param id the id of the selected agent
|
||||||
*/
|
*/
|
||||||
private static void showEstateAgent(int id) {
|
private static void showEstateAgent(int id) {
|
||||||
EstateAgent agent = _orm.get(id);
|
EstateAgent agent = _orm.getAgent(id);
|
||||||
|
|
||||||
System.out.println("EstateAgent");
|
System.out.println("EstateAgent");
|
||||||
System.out.println("------------------");
|
System.out.println("------------------");
|
||||||
|
|
Loading…
Reference in New Issue