Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
management -> person works
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 8, 2022
1 parent b4cc9f6 commit 64c8ce8
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 169 deletions.
4 changes: 2 additions & 2 deletions db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE property (
city VARCHAR2(255) NOT NULL,
state CHAR(2) NOT NULL
CHECK (state like '__'),
zipcode NUMBER(5) NOT NULL,
zipcode CHAR(5) NOT NULL,
PRIMARY KEY(id)
);

Expand Down Expand Up @@ -199,7 +199,7 @@ CREATE TABLE pet_on_lease (

CREATE TABLE person_on_lease (
lease_id NUMBER,
person_id NUMBER,
person_id NUMBER UNIQUE, -- Only one person per lease
PRIMARY KEY(lease_id, person_id),
FOREIGN KEY(lease_id) REFERENCES lease(id) ON DELETE CASCADE,
FOREIGN KEY(person_id) REFERENCES renter_info(person_id) ON DELETE CASCADE
Expand Down
7 changes: 7 additions & 0 deletions numa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ dependencies {

}

// Support Lehigh Sunlab Java JDK
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

testing {
suites {
// Configure the built-in test suite
Expand Down
2 changes: 1 addition & 1 deletion numa/src/main/java/numa/NUMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void main (String[] args) throws IOException {
System.out.println("IOException: " + e);
}
catch (ExitException e) {
System.out.println("\nExiting...");
System.out.println("Exiting...");
}

} catch (IOException e) {
Expand Down
134 changes: 122 additions & 12 deletions numa/src/main/java/numa/Portals/ManagementPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ public ManagementPortal(Connection conn, Reader input) throws IOException, ExitE
System.out.println("-----------------\n");

// Get management login
if (!getManagerLogin()) {
return;
}
// if (!getManagerLogin()) {
// return;
// }

System.out.println("[1] Properties");
System.out.println("[2] Tenants");
System.out.println("[2] People");
System.out.println("[3] Lease");
System.out.println("[4] Visit Registration");
System.out.println("[5] Change PIN");
System.out.println();
int mainChoice = super.portal(input, 5);

switch (mainChoice) {
case 1: properties(); break;
case 2: tenants(); break;
case 2: people(); break;
case 3: lease(); break;
case 4: visits(); break;
}
Expand All @@ -55,8 +56,7 @@ public Boolean getManagerLogin() throws SQLException, NumberFormatException, IOE
int pin = -1;
while (pin == -1) {
try {
System.out.print("Manager PIN: ");
pin = input.getMenuInt();
pin = input.getMenuInt("Manager PIN: ");
}
catch (NumberFormatException e) {
System.out.println("Invalid input. Please try again");
Expand All @@ -75,23 +75,133 @@ public Boolean getManagerLogin() throws SQLException, NumberFormatException, IOE
}
}

public void properties() throws SQLException {
public void properties() throws SQLException, NumberFormatException, IOException, ExitException, MenuException {
try (
Statement getProp = conn.createStatement();
) {
ResultSet propRes = getProp.executeQuery("select * from property");

ArrayList<Property> props = new ArrayList<Property>();

System.out.println(BOLD_ON + "Properties:" + BOLD_OFF);
int counter = 0;

while (propRes.next()) {
ArrayList<Lease> props = new ArrayList<Lease>();
int id = propRes.getInt("id");
String street = propRes.getString("street_name");
String city = propRes.getString("city");
String state = propRes.getString("state");
String zip = propRes.getString("zipcode");

Property tmp = new Property(id, street, city, state, zip);
props.add(tmp);
System.out.format(
"[%d] %s\n",
++counter, tmp.toString()
);
}
System.out.println();


int propId = -1;
while (true) {
System.out.format(
"View apartments under a property [1-%s], 'a' to add a property, 'm' to menu or 'q' to quit: ",
counter
);
propId = input.getAddPrompt();
if (propId >= 0 && propId <= counter) {
break;
}
System.out.println("Invalid input. Try again\n");
}
System.out.println();

try (
PreparedStatement getApts = conn.prepareStatement("select * from apartment where prop_id = ?");
) {
System.out.format(
"%s%s Apartments:%s\n",
BOLD_ON,
props.get(counter - 1).toString(),
BOLD_OFF
);

getApts.setInt(1, propId);
ResultSet aptRes = getApts.executeQuery();
ArrayList<Apartment> aptList = new ArrayList<Apartment>();

counter = 0;

while (aptRes.next()) {
int prop_id = aptRes.getInt("prop_id");
String apt = aptRes.getString("apt");
int square_footage = aptRes.getInt("square_footage");
int bed_count = aptRes.getInt("bed_count");
float bath_count = aptRes.getFloat("bath_count");
int rent = aptRes.getInt("rent");

Apartment tmp = new Apartment(prop_id, apt, square_footage, bed_count, bath_count, rent);
aptList.add(tmp);
System.out.format(
"[%d] %s\n",
++counter,
aptList.get(counter - 1).apt
);
}
System.out.println();

int aptIndex = -1;
while (true) {
System.out.format(
"View apartment details [1-%d], 'a' to add apartments, 'm' to menu or 'q' to quit: ",
counter
);
aptIndex = input.getAddPrompt();
if (aptIndex >= 0 && aptIndex <= counter) {
break;
}
System.out.println("Invalid input. Try again\n");
}
System.out.println();

System.out.println(aptList.get(aptIndex - 1).toString());
System.out.println();
}


System.out.println(BOLD_ON + "Properties:" + BOLD_OFF);
}
}

public void tenants() {
public void people() throws NumberFormatException, IOException, ExitException, MenuException, SQLException {
System.out.println("Search by:");
System.out.println("[1] Name");
System.out.println("[2] ID");
int choice = -1;
while (choice == -1) {
try {
choice = input.getMenuInt("Option [1-2]: ");
}
catch (NumberFormatException e) {
System.out.println("Invalid input. Please try again");
}
if (choice == 1 || choice == 2) break;
}

String sqlPrefix = String.format(
"select " +
"person.id as id, first_name, last_name, ssn, age, phone_number, email, credit_score, apt " +
"from " +
"(((person left outer join renter_info on renter_info.person_id = person.id) " +
"natural left outer join person_on_lease) " +
"left outer join lease on lease_id = lease.id)" +
"natural left outer join apartment "
);

switch (choice) {
case 1: Person.searchName(sqlPrefix, conn, input); break;
case 2: Person.searchId(sqlPrefix, conn, input); break;

}
}

public void lease() {
Expand Down
Loading

0 comments on commit 64c8ce8

Please sign in to comment.