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

Commit

Permalink
resident portal - view apt details function works
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 6, 2022
1 parent 7846adb commit 674de5e
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 20 deletions.
8 changes: 7 additions & 1 deletion numa/src/main/java/numa/NUMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static void main (String[] args) throws IOException {
try (
Connection conn = DriverManager.getConnection(DB_URL, loginInfo[0], loginInfo[1]);
) {
conn.setAutoCommit(false);

connected = true;
while (connected) {
try {
Expand Down Expand Up @@ -75,6 +77,10 @@ public static void main (String[] args) throws IOException {
}
catch (MenuException e) {
// Do nothing
}
catch (SQLException e) {
System.out.println("SQL Exception: " + e);
System.out.println("Returning to the main menu...\n");
}
}
}
Expand All @@ -83,7 +89,7 @@ public static void main (String[] args) throws IOException {
if (e.getErrorCode() == 1017) {
System.out.println("Login denied. Please try again\n");
} else {
System.out.println("SQLException: " + e);
System.out.println("Failed to connect to the database. Please try again at a later time");
}
}
catch (IOException e) {
Expand Down
69 changes: 69 additions & 0 deletions numa/src/main/java/numa/Portals/Lease.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package numa.Portals;

import java.sql.Timestamp;
import java.util.ArrayList;

public class Lease {
int prop_id;
String street_name;
String apt;
String city;
String state;
String zip;
Timestamp start_date;
int term_length;
int rent_amount;

public Lease(int prop_id, String street_name, String apt, String city, String state, String zip, Timestamp start_date, int term_length, int rent_amount) {
this.prop_id = prop_id;
this.street_name = street_name;
this.apt = apt;
this.city = city;
this.state = state;
this.zip = zip;
this.start_date = start_date;
this.term_length = term_length;
this.rent_amount = rent_amount;
}

public String toString() {
String outStr = String.format(
"Address:\n" +
"%s\n" +
"Apt %s\n" +
"%s, %s %s\n" +
"Lease Start: %s\n" +
"Lease Term Length: %d\n" +
"Rent: $%d\n",
street_name, apt, city, state, zip, start_date, term_length, rent_amount
);
return outStr;
}

public String toString(ArrayList<Amenity> amenities) {
String outStr = this.toString();
outStr += "Amenities:\n";
for (Amenity prop: amenities) {
outStr += prop.toString();
}
return outStr;
}
}

class Amenity {
String amenity;
int cost;

public Amenity(String amenity, int cost) {
this.amenity = amenity;
this.cost = cost;
}

public String toString() {
String outStr = String.format(
" - %s: $%d\n",
amenity, cost
);
return outStr;
}
}
14 changes: 7 additions & 7 deletions numa/src/main/java/numa/Portals/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Payment {
Reader input;
int resId;

public Payment(Connection conn, Reader input, int resId) throws NumberFormatException, IOException, ExitException, MenuException {
public Payment(Connection conn, Reader input, int resId) throws NumberFormatException, IOException, ExitException, MenuException, SQLException {
this.conn = conn;
this.input = input;
this.resId = resId;
Expand All @@ -36,18 +36,18 @@ public Payment(Connection conn, Reader input, int resId) throws NumberFormatExce

try {
switch(choice) {
case 1: addACH();
case 2: addCard(false);
case 3: addCard(true);
case 4: addVenmo();
default:
case 1: addACH(); break;
case 2: addCard(false); break;
case 3: addCard(true); break;
case 4: addVenmo(); break;
}

conn.commit();
}
catch (SQLException e) {
System.out.println("Error adding payment: " + e);
return;
}

System.out.println("Payment Method Accepted!");
}

Expand Down
76 changes: 64 additions & 12 deletions numa/src/main/java/numa/Portals/ResidentPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;

import javax.naming.spi.DirStateFactory.Result;

import numa.Reader;
import numa.Exceptions.*;

Expand Down Expand Up @@ -48,15 +47,13 @@ public ResidentPortal(Connection conn, Reader input) throws IOException, ExitExc

System.out.println("[1] My Info");
System.out.println("[2] Make Payment");
System.out.println("[3] View Apartment Details");
System.out.println("[4] Modify Lease");
int mainChoice = super.portal(input, 4);
System.out.println("[3] My Lease Details");
int mainChoice = super.portal(input, 3);

switch (mainChoice) {
case 1: resInfo(); break;
case 2: makePayment(); break;
case 3: viewAptDetails(); break;
case 4: modifyLease(); break;
}

super.sessionReset(input);
Expand Down Expand Up @@ -129,6 +126,7 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E
String handle = venmoInfo.getString("handle");
Venmo acc = new Venmo(handle);
venmoOut += acc.toString();
venmoOut += "\n";
}

while (achInfo.next()) {
Expand All @@ -137,6 +135,7 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E
String rout = achInfo.getString("routing_num");
ACH acc = new ACH(acct, rout, bank);
achOut += acc.toString();
achOut += "\n";
}

while (cardInfo.next()) {
Expand All @@ -149,6 +148,7 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E

Card acc = new Card(first, last, card_num, exp, cvv, pin);
cardOut += acc.toString();
cardOut += "\n";
}

System.out.println(infoOut);
Expand All @@ -157,18 +157,21 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E
System.out.println(BOLD_ON + "Venmo" + BOLD_OFF);
System.out.println();
System.out.println(venmoOut);
System.out.println();
}

if (achOut != "") {
System.out.println(BOLD_ON + "Bank ACH Transfers" + BOLD_OFF);
System.out.println();
System.out.println(achOut);
System.out.println();
}

if (cardOut != "") {
System.out.println(BOLD_ON + "Payment Cards" + BOLD_OFF);
System.out.println();
System.out.println(cardOut);
System.out.println();
}

System.out.print("Do you need to add a new payment? [Y/N]: ");
Expand All @@ -179,7 +182,6 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E
default: return;
}
}

}

/** Show all payments that need to be made and some details */
Expand All @@ -189,13 +191,63 @@ public void makePayment() {
/** Read only of apartment details */
public void viewAptDetails() throws SQLException {
try (
Statement getApt = conn.prepareStatement("");
PreparedStatement getApts = conn.prepareStatement(
"select prop_id, street_name, apt, city, state, zipcode, start_date, term_length, rent_amount from (person_on_lease join lease on person_on_lease.lease_id = lease.id) join property on prop_id = property.id where person_id = ?"
);
PreparedStatement getPropAmenities = conn.prepareStatement(
"select amenity, cost from prop_amenity where prop_id = ?"
);
PreparedStatement getAptAmenities = conn.prepareStatement(
"select amenity, cost from apt_amenity where prop_id = ? and apt = ?"
);
) {

}
}
getApts.setInt(1, resId);
ResultSet leased_apts = getApts.executeQuery();
ArrayList<Lease> leased = new ArrayList<Lease>();

while (leased_apts.next()) {
int prop_id = leased_apts.getInt("prop_id");
String street_name = leased_apts.getString("street_name");
String apt = leased_apts.getString("apt");
String city = leased_apts.getString("city");
String state = leased_apts.getString("state");
String zip = leased_apts.getString("zipcode");
Timestamp start_date = leased_apts.getTimestamp("start_date");
int term_length = leased_apts.getInt("term_length");
int rent_amount = leased_apts.getInt("rent_amount");


Lease newLease = new Lease(prop_id, street_name, apt, city, state, zip, start_date, term_length, rent_amount);
leased.add(newLease);
}

for (Lease lease : leased) {
ArrayList<Amenity> amenities = new ArrayList<Amenity>();

// Get property amenities
getPropAmenities.setInt(1, lease.prop_id);
ResultSet propAmen = getPropAmenities.executeQuery();

// Get apartment amenities
getAptAmenities.setInt(1, lease.prop_id);
getAptAmenities.setString(2, lease.apt);
ResultSet aptAmen = getAptAmenities.executeQuery();

/** Actions to add/remove person/pet and extend lease */
public void modifyLease() {
while (propAmen.next()) {
String name = propAmen.getString("amenity");
int cost = propAmen.getInt("cost");
amenities.add(new Amenity(name, cost));
}

while (aptAmen.next()) {
String name = aptAmen.getString("amenity");
int cost = aptAmen.getInt("cost");
amenities.add(new Amenity(name, cost));
}

System.out.println(lease.toString(amenities));
}
}
}
}

0 comments on commit 674de5e

Please sign in to comment.