Hello everyone, i have been trying to complete this program on a letting agency where a user gets a choice of options
1. Add a property
2. Remove a property
3. Display all properties
4. Exit the system
I have no idea what syntax to use within each case option to allow each of the following to run correctly. I am very new to java so any help with the syntax would be greatly appreciated!!
package assignment;
import java.io.*;
class propertyToLet
{
private String postcode;
private String houseNo;
private String monthlyRent;
//Constructors
public propertyToLet()
{
postcode="xxx";
houseNo="xxxx";
monthlyRent="xxx";
}
public propertyToLet(String postcode, String houseNo, String monthlyRent)
{
this.postcode=postcode;
this.houseNo=houseNo;
this.monthlyRent=monthlyRent;
}
//accessors
public String getPostCode()
{
return postcode;
}
public String getHouseNo()
{
return houseNo;
}
public String getMonthlyRent()
{
return monthlyRent;
}
//mutators
public void setpostcode(String newpostcode)
{
postcode = newpostcode;
}
public void sethouseNo (String newhouseNo)
{
houseNo = newhouseNo;
}
public void setmonthlyRent (String newmonthlyRent)
{
monthlyRent = newmonthlyRent;
}
}
class propertyList
{
private String filename;
private propertyToLet[] property;
int numberofproperties=0;
public propertyList() throws IOException
{
property = new propertyToLet[200];
filename = "properties.txt";
final FileReader f = new FileReader (filename);
final BufferedReader tInputHandle = new BufferedReader(f);
for(int i=0 ; i<200 ; i++)
{
property[i] = new propertyToLet();
}
while(tInputHandle.ready())
{
String tLine = tInputHandle.readLine();
System.out.println();
property[numberofproperties].sethouseNo(tLine);
tLine = tInputHandle.readLine();
property[numberofproperties].setpostcode(tLine);
tLine = tInputHandle.readLine();
property[numberofproperties].setmonthlyRent(tLine);
numberofproperties++;
}
}
public String getPostCode(int propertyID)
{
return property[propertyID].getPostCode();
}
public String getHouseNo(int propertyID)
{
return property[propertyID].getHouseNo();
}
public String getMonthlyRent(int propertyID)
{
return property[propertyID].getMonthlyRent();
}
public int getnumberofproperties()
{
return numberofproperties;
}
}
public class Main {
public static void main(String[] args) throws IOException
{
propertyList mypropertyList = new propertyList();
int menu=0;
do
{
final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in));
System.out.println("1, Add property");
System.out.println("2, Remove properties from list");
System.out.println("3, Load list of properties");
System.out.println("4, Exit the system");
System.out.print("\n Enter your choice: ");
String tLine = tKeyboard.readLine();
switch(menu)
{
case 1:
System.out.println("\n Add property, Please Select the postcode, house number and monthly rent to add a property");
break;
case 2:
System.out.println("\n Remove Properties from list, Select the property that you would like to remove from your list");
break;
case 3:
System.out.println("\n load list of propertiesProperties in list");
for(int i=0 ; i<mypropertyList.getnumberofproperties(); i++)
System.out.print(mypropertyList.getPostCode(menu));
System.out.print(mypropertyList.getHouseNo(menu));
System.out.print(mypropertyList.getMonthlyRent(menu));
break;
case 4:
System.exit(0);
break;
default:
System.out.println("Error: Should not reach here.");
}
} while(menu >=1 && menu <= 4);
}
Many thanks
Kim