I require some help with a program I've got to write, the theory behind it is based around OOP, but I'm having trouble grasping what exactly I should be doing.
I'm not entirely sure how to call the addProperty method from the Property class, or even that I've written out how that method should look, comments, advice?
Regards, Charles.
Main Class.
import java.util.*;
public class A2 {
public static void main (String[] args) {
//Data field.
Property properties[] = new Property[10];
boolean exit;
int count;
String rootmenu;
exit = false;
Scanner input = new Scanner(System.in);
//Program body.
while (exit != true) {
// Menu.
System.out.println("Menu:");
System.out.println("1. Add Properties to the system");
System.out.println("2. Enter Rental Agreement information (provide: propertyID, tenantID, Start Date)");
System.out.println("3. Terminate a Rental agreement (provide: propertyID, tenantID, End Date)");
System.out.println("4. Search for Properties(based on weekly_rental_rate)");
System.out.println("5. List Properties(not visible to clients)");
System.out.println("6. List Properties (currently rented out)");
System.out.println("7. List Properties(available for rent)");
System.out.println("8. Display the details(1 property or all)");
System.out.println("X. Exit");
//Menu handler.
rootmenu = input.nextLine();
if (rootmenu.equalsIgnoreCase ("1") == true) {
System.out.println("\n1 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("2") == true) {
System.out.println("\n2 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("3") == true) {
System.out.println("\n3 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("4") == true) {
System.out.println("\n4 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("5") == true) {
System.out.println("\n5 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("6") == true) {
System.out.println("\n6 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("7") == true) {
System.out.println("\n7 reached.\n");
}
if (rootmenu.equalsIgnoreCase ("8") == true) {
System.out.println("\n8 reached.\n");
}
//Incorrect menu input handler. Couldn't use switch, nested ifchecks quickest option.
if (rootmenu.equalsIgnoreCase ("X") == false) {
if (rootmenu.equalsIgnoreCase ("1") == false) {
if (rootmenu.equalsIgnoreCase ("2") == false) {
if (rootmenu.equalsIgnoreCase ("3") == false) {
if (rootmenu.equalsIgnoreCase ("4") == false) {
if (rootmenu.equalsIgnoreCase ("5") == false) {
if (rootmenu.equalsIgnoreCase ("6") == false) {
if (rootmenu.equalsIgnoreCase ("7") == false) {
if (rootmenu.equalsIgnoreCase ("8") == false) {
System.out.println("\nIncorrect input, please try again.\n");
}
}
}
}
}
}
}
}
}
//Exit statement.
if (rootmenu.equalsIgnoreCase ("X") == true) {
exit = true;
}
}
}
}
Property Class.
import java.util.*;
public class Property {
//Data field
private String propertyID;
private String description;
private String location;
private char avaliability; // A for avaliable, R for rented.
private double weeklyRental;
private boolean visibility;
private String tenantID;
private String startDate;
private String endDate;
Scanner input = new Scanner(System.in);
//Constructors
public Property(String propertyID, String description, String location, double weeklyRental) {
this.propertyID = propertyID;
this.description = description;
this.location = location;
this.weeklyRental = weeklyRental;
avaliability = 'A';
visibility = false;
}
//Method
public void addProperty(String propertyID, String description, String location, double weeklyRental) {
System.out.println("Enter Property ID:");
propertyID = input.nextLine();
System.out.println("Enter Description:");
description = input.nextLine();
System.out.println("Enter Location:");
location = input.nextLine();
System.out.println("Enter weekly rental rate:");
weeklyRental = input.nextDouble();
new Property("propertyID", "description", "location", 0.0);
}
}