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

Use code tags

ok so could you give me some ideas/examples please, am really struggling with this part
Thanks

When you reply to the thread there is this symbol: #
above the area where you write.
Push it and put your code inside it. Use different code tags for each of your classes

ok so could you give me some ideas/examples please, am really struggling with this part
Thanks

Take a look at the following:

>Push it and put your code inside it. Use different code tags for each of your classes
Or just paste your code in the message, select the code and push it (#) :P

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("Please Select the postcode, house number and monthly rent to add a property");
           
         break;
         
         case 2:
           System.out.println("Select the property that you would like to remove from your list");            
         break;
         
         case 3:
           System.out.println("Properties in list"); 
           
           
      for(int i=0 ; i<mypropertyList.getnumberofproperties(); i++)
       
             
         break;
                 
         case 4:
              System.out.println("Goodbye");
         System.exit(0);
        
         break;
                 
         default:
          System.out.println("Error: Should not reach here.");
       }
       
       } while(menu >=1 && menu <= 4); 
     
    }   
    

}
Comments
Yea, that's the spirit !

I understand You have a problem with menu to Your program, where You can choose a number and something happens.

You can use for this task BufferedReader class, which initialization look like that:

BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

For reading a number from user is method read(). So in summary it can look like that (read() throws IOException, so it should be catched (or thrown further)) :

try
{
    BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
    
    char optionChosen = (char)br.read();

    switch( optionChose )
    {
        case '1':
            \\    some action performed
            break;

        case '2':
            \\    some other action performed
            break;
    }
}
catch ( IOException ex ) { \* handling *\ }
This article has been dead for over six months. Start a new discussion instead.