this is my whole code
hi NOrmR1 would you give me a hand mate please

import java.util.*;
class Property 
{
   private String ID;
   private String description;
   private String location;
   private double weeklyRR;
   private char status ;
   private boolean visibility;

   
   public Property (String pID, String pDesc, String pLOc, double weeklyR )
   {   
	  ID = pID;
	  description = pDesc;
	  location = pLOc;
	  weeklyRR = weeklyR;	
	  status = 'A';
	  visibility = false;
   } 
   
   public String setID()            { return ID; }
   public String setDescription()   { return description; }
   public String setLocation()      { return location; }
   public double setWeeklyRR()      { return weeklyRR; }  
   public char setStatus()          { return status; }
   public boolean setVisibility()   { return visibility; } 
   
   
   public String getID()            { return ID; }
   public String getDescription()   { return description; }
   public String getLocation()      { return location; }
   public double getWeeklyRR()      { return weeklyRR; }
   public char getStatus()          { return status; }
   public boolean getVisibility()   { return visibility; } 
   
   
   public void addProperty(String pID, String pDesc, String pLOc, double d)
   {  
	   
	  Scanner scan = new Scanner(System.in);	 	 	 	   
	  System.out.println("Enter ID");
	  String ID = scan.nextLine();
	  System.out.println("Enter Description");
	  String description = scan.nextLine();
	  System.out.println("Enter Location");
	  String location = scan.nextLine();
	  System.out.println("Enter weekly rental rate");
	  double weeklyRR = scan.nextDouble();	 
	
	  new Property("ID", "description", "location", 0.0);
	
   } 
   
   public boolean startRental (String tenantID, GregorianCalendar startDate)
   {
	   
	   return true;
   }
   
   public double terminateRental (GregorianCalendar endDate)
   {
	   double charges = weeklyRR ;
	   return charges;	   
   }  
   
   public void printPropertyDeatils(String pID, String pDesc, String pLOc, double d)
   {
	  
	 
		   
	      
   }  
   
}
import java.util.*;
public class Administration 
{
	 public static void Menu(){	 
		 System.out.println("Menu");
		 System.out.println("1. Add Properties to the system");
	     System.out.println("2. Enter Rental Agreement information (provide: prop ID, tenant ID, start Date)");
		 System.out.println("3. Terminate a Rental agreement (provide: prop ID, tenant ID, 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("9. Exit");	}		
	
	public static int getAnswer()
   {
	  int answer;
	  Scanner scan = new Scanner(System.in);
	  answer = scan.nextInt();
		
	  while ( answer < 1 || answer > 9 )
	  {
		 if ( answer  ==  9 )
			return answer;
		    			
		 System.out.println("Invalid entry Try again") ;
		 answer = scan.nextInt();			
	  }
	 return answer;	
	}
	
	public static void main(String[] args )
   {  
	   Property[] properties= new Property[10];
	   int count = 0;
	   Property properties[count] = new Property("AP001", "2-bedroom apartment with city views", "Docklands", 550);
	 
	  
	  
	   Property properties1 = new Property("AP001", "2-bedroom apartment with city views", "Docklands", 550);  
	   count++;
	   Property properties2 = new Property("UN112", "modern 3-bedroom unit", "Seddon", 465);
	   count++;
	   Property properties3= new Property("AP002", "older style 1-bedroom flat with gas cooking", "South Yarra", 310);
	   count++;
	   Property properties4 = new Property("ED030", "renovated Edwardian with 4 bedrooms", "Camberwell", 650);
	   count++;
	   Property properties5= new Property("ED034", "original Edwardian with large backyard", "Moonee Ponds", 475);         
	   count++;
	   Property properties6= new Property("VT001", "single-fronted Victorian Terrace with 2 bedrooms and small courtyard"
				                        , "Brunswick", 465);	              
	   count++;
	   
	   int num;	
	   Menu();	     
	   num = getAnswer();			
	   while(num != 9)
	   {
		  if (num == 1)			  
			  properties .addProperty("ID", "description", "location", 0.0); 			  
		  else if (num == 2)
			       System.out.println("this is 2");	
		  else if (num == 3)
			       System.out.println("this is 3");
		  else if (num == 4)	
			       System.out.println("this is 4");
		  else if (num == 5)		  
			       System.out.println("this is 5");
		  else if (num == 6)
			      System.out.println("this is 6");
		  else if (num == 7)
			      System.out.println("this is 7");  
		  else if (num == 8)
			  properties .printPropertyDeatils("ID", "description", "location", 0.0) ;   
			  
		  Menu();	   
		  num = getAnswer();		  
	   }
	  System.out.println("Exit");
	 }	
	
}

Dani AI

Generated

Several small, common Java mistakes are preventing the program from working. Key issues observed in the thread: getters and setters are swapped (a setter should accept a value and set the field), array syntax and indexing are incorrect, methods are being invoked on an array variable, local variables shadow fields, and a constructor call uses the literal strings "ID", "description" etc. instead of the variables. correctly pointed out the setter/getter confusion; was right to flag the numbered-variable approach; asked for clearer requirements, which helps when redesigning the API.

Correct patterns (examples kept minimal and different from the original code): implement a proper setter/getter and a readable toString:

public void setID(String id) { this.ID = id; }
public String getID() { return ID; }

@Override
public String toString() {
    return ID + " - " + description + " @ " + location + " ($" + weeklyRR + "/wk)";
}

Manage the collection with a List rather than many numbered variables or fragile array indexing. Provide a small factory method that reads from Scanner and returns a Property, then add it to the list:

private static Property readProperty(Scanner sc) {
    System.out.print("ID: "); String id = sc.nextLine();
    System.out.print("Description: "); String desc = sc.nextLine();
    System.out.print("Location: "); String loc = sc.nextLine();
    System.out.print("Weekly rate: "); double rate = Double.parseDouble(sc.nextLine());
    return new Property(id, desc, loc, rate);
}

// usage:
List<Property> props = new ArrayList<>();
props.add(readProperty(new Scanner(System.in)));

Practical troubleshooting notes: do not declare an array element with syntax like Property props[count] = ... — assign to an already-declared array element (props[count] = ...;). Avoid shadowing field names with local variables. When mixing nextInt/nextDouble and nextLine, consume the leftover newline (or always read lines and parse numbers). Make addProperty either return a new Property or accept the collection to modify; do not try to call domain methods on an array variable. Fix misspellings (e.g., printPropertyDeatils) and iterate the list to print items (use the toString above). These changes address the specific problems called out by , and and will make the add/print methods usable.

Recommended Answers

All 5 Replies

public void addProperty(String pID, String pDesc, String pLOc, double d)

{         // confused here

 

Scanner scan = new Scanner(System.in);

System.out.println("Enter ID");

String ID = scan.nextLine();

System.out.println("Enter Description");

String description = scan.nextLine();

System.out.println("Enter Location");

String location = scan.nextLine();

System.out.println("Enter weekly rental rate");

double weeklyRR = scan.nextDouble();
 

new Property("ID", "description", "location", 0.0); 

}
public static void main(String[] args )

{

Property[] properties= new Property[10];

int count = 0;

Property properties[count] = new Property("AP001", "2-bedroom apartment with city views", "Docklands", 550);

 

 

 

Property properties1 = new Property("AP001", "2-bedroom apartment with city views", "Docklands", 550);

count++;

Property properties2 = new Property("UN112", "modern 3-bedroom unit", "Seddon", 465);

count++;

Property properties3= new Property("AP002", "older style 1-bedroom flat with gas cooking", "South Yarra", 310);

count++;

Property properties4 = new Property("ED030", "renovated Edwardian with 4 bedrooms", "Camberwell", 650);

count++;

Property properties5= new Property("ED034", "original Edwardian with large backyard", "Moonee Ponds", 475);

count++;

Property properties6= new Property("VT001", "single-fronted Victorian Terrace with 2 bedrooms and small courtyard"

, "Brunswick", 465);

count++;

 

int num;

Menu();

num = getAnswer();

while(num != 9)

{

if (num == 1)

properties .addProperty("ID", "description", "location", 0.0);      //very confused 
                                                                     //here
else if (num == 2)

System.out.println("this is 2");

else if (num == 3)

System.out.println("this is 3");

else if (num == 4)

System.out.println("this is 4");

else if (num == 5)

System.out.println("this is 5");

else if (num == 6)

System.out.println("this is 6");

else if (num == 7)

System.out.println("this is 7");

else if (num == 8)

properties .printPropertyDeatils("ID", "description", "location", 0.0) ;

You've left off a description of what the program is to do and what your problem is.

Looking at the immediately preceding posted code, I see that some of it is missing.

First of all i'm not sure what you are expecting, i didn't run your code to see what is wrong, but from the look of it, i found these codes a bit unusual;

public String setID()            { return ID; }

and

public String getID()            { return ID; }

Both have the same functionality, and i presume setID() should look some thing like this

public String setID(String ID)            { this.ID= ID; }

Love to help, but I'm not reading through all that. I see you started to get the array in order, then you switched to individual variables distinguished by numbers (property 2, property3, etc). That's a little weird.

Have you got a question in there?

i want to thank everyone for helping,this is a great site..
I'm giving up this subject
I'll just fail it for now,, i will fight though another day
thanks friends..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.