Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3722656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:59:02+00:00 2026-05-19T05:59:02+00:00

In the following block of code, I am trying to print the properties whose

  • 0

In the following block of code, I am trying to print the properties whose location, monthlyRent, numberOfBedrooms defined in the Property class being equal to this method’s parameters in LettingAgent class. When I compiled, the error is occured in the if line where it says non-static method like getlocation() can’t be referenced from static context.

/**
 * Java coursework on class property which present detail information about the property

public class Property
{
    // instance variables of class property.
    private String address;
    private char location;
    private double monthlyRent;
    private int numberOfBedrooms;
    private boolean occupied;
    private String tenantName;

    /** 
     * Constructor for object of class Property with required parameters. 
     */
    public Property( String addressinput, char locationinput, double Rentinput, int Bedsinput )
    { 
        //initialise the instance variables or fields of property class.
        address = addressinput;
        location = locationinput;
        monthlyRent = Rentinput;
        numberOfBedrooms = Bedsinput;
        occupied = false;
        tenantName = "";
    }

    /**
     * Return the address of the property
     */
    public String getAdress( )
    {
        return address;
    }

     /**
     * Return the location of the property
     */

    public char getLocation( )
    {
        return location;
    }

     /**
     * Return the monthlyRent of the property
     */
     public double getmonthlyRent( )
    {
        return monthlyRent;
    }

     /**
     * Return the numberOfBedrooms of the property
     */
     public int getnumberOfBedrooms( )
    {
        return numberOfBedrooms;
    }

     /**
     * Return the occupied value of the property
     */
     public boolean isoccupied( )
    {
        return occupied;
    }

     /**
     * Return the tenant's name of the property
     */
     public String gettenantName( )
    {
        return tenantName;
    }

     /**
     * Set the monthly rent to a new value
     */
     public void setmonthlyRent( double newRent )
    {
       monthlyRent = newRent;
    }

     /**
     * Adding tenant's name to the property
     */
     public void addtenantName(String newTenant)
    {
        if(occupied == false) {
            tenantName = newTenant;
            occupied = true; 
        }
        else {
            System.out.println(" The property is already occupied");
        }

    }

     /**
     * Removing tenant's name of the property
     */
     public void removetenantName( )
    {
        if( occupied == true) {
            tenantName = "";
            occupied = false;
        }
        else {
            System.out.println(" The property is new and not occupied");
        }

    }

     /**
     * Print all the property attributes
     */
     public void printProperty( )
    {
        //simulate the printing of the property attributes.
       System.out.println( "The details of the property are as follow" );
       System.out.println("Address:" + address );
       switch(location){
           case 'n': case 'N': System.out.println("Location: North london" );break;
           case 's': case 'S': System.out.println("Location: South london" );break;
           case 'e': case 'E': System.out.println("Location: East london" );break;
           case 'w': case 'W': System.out.println("Location: West london" );
        } 

       System.out.println("Monthly-Rent:" + monthlyRent );
       System.out.println("Number of Bedrooms:" + numberOfBedrooms );
       System.out.println("Status of property:" + occupied );
       if(occupied == true) {
       System.out.println("Tenant Name:" + tenantName );
       }
       else {
           System.out.println("Property is empty at moment" );
        }

    }

}

LettingAgent Class (calling class)

import java.util.ArrayList;

/**
 * Write a description of class LettingAgent here.
 */

public class LettingAgent
{
    // instance variables of LettingAgent Class.
    private ArrayList<Property>agproperty;
    private int Propnumber;

    /**
     * Constructor for objects of class LettingAgent
     */
    public LettingAgent()
    {
        // initialise instance variables
        agproperty = new ArrayList<Property>();
        Propnumber = 0;
    }

    /**
     * Return the property number of the Class LettingAgent. 
     */
    public int getPropnumber(){
        return Propnumber;
    }    

    /**
     *Method to add new property to the class LettingAgent via class Property.
     */
    public void addNewProperty(String addressinput, char locationinput, double Rentinput, int Bedsinput)
    {
        // put your code here
        Property newProperty = new Property(addressinput,locationinput,Rentinput,Bedsinput);
        agproperty.add(newProperty);

    }

    /**
     * @Description Method for removing the propety from the class LettingAgent.
     * @param int propnumber
     */
    public void removalOfProperty(int Propnumber)
    {
        // initialise instance variables
        if( Propnumber<agproperty.size()){
            agproperty.remove(Propnumber);
            System.out.println("The property has been removed");
        }
        else{
            System.out.println("The Property number is not valid");
        }
    }

    /**
     * Method for adding tenant to the property within class LettingAgent via class Property.
     */
    public void addTenant(int Propnumber, String newName, Property newProperty)
    {
        // initialise instance variables
        if( Propnumber<agproperty.size()){
            agproperty.get(Propnumber);
            newProperty.addtenantName(newName);
        }
        else{
            System.out.println("The Property number is not valid");
        }
    }

    /**
     * Method for removing tenant from the class LettingAgent via Property class.
     */
    public void removeTenant(int Propnumber,Property newProperty)
    {
        // initialise instance variables
        if( Propnumber<agproperty.size()){
            agproperty.get(Propnumber);
            newProperty.removetenantName( );

        }
        else{
            System.out.println("The Property number is not valid");
        }
    }

    /**
     *Method for searching property within the LettingAgent class.
     */
    public void searchProperty(String Address)
    {
        // initialise instance variables
        for(Property Property : agproperty){
            if (agproperty.get(Propnumber).equals( Address)){
                System.out.println("The details of the property is as follow"+ Property);
            }
            else{
                System.out.println("The property is not in the Letting agent's Stock");
            }
        }
    }

    /**
     * Method for printing unoccupied property of the class LettingAgent.
     */

    public void printListOfUnoccupiedProperty( char Location, double maxmonthlyRent, int miniNoBeds)
    {
        // initialise instance variables
         for(Property property : agproperty){
        if((Property.getLocation().equals(Location))&&(Property.get(monthlyRent).equals(maxmonthlyRent))&&(agproperty.get(numberOfBedrooms).equals(miniNoBeds))){
            System.out.Println(Propnumber);
            Property.printProperty();
        }
        else{
            System.out.println("The Property number is not valid");
        }
    }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:59:04+00:00Added an answer on May 19, 2026 at 5:59 am

    In the last method you define (formatted below):

    /**
     * Method for printing unoccupied property of the class LettingAgent.
     */
    public void printListOfUnoccupiedProperty(char Location, double maxmonthlyRent, int miniNoBeds) {
        // initialise instance variables
        for (Property Property : agproperty) {
            if ((Property.getLocation().equals(Location))
                    && (Property.get(monthlyRent).equals(maxmonthlyRent))
                    && (agproperty.get(numberOfBedrooms).equals(miniNoBeds))) {
                System.out.Println(Propnumber);
                Property.printProperty();
            } else {
                System.out.println("The Property number is not valid");
            }
        }
    }
    

    on the line:

    && (Property.get(monthlyRent).equals(maxmonthlyRent))
    

    you’re calling the get method of the Property variable. I think that should be Property.getMonthlyRent().

    One other thing, in Java you should name your variables differently than their class names. I would use something like

    for (Property property : agproperty) { ...
    

    I know it’s a small change, but it makes a big difference in the readability of your code. You can read about other Java code conventions in Code Conventions for the Java Programming Language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to debug the following block of Javascript code to see what the
I am trying to update values in a column like the following code block
Consider the following block of code: class CheckStore { private String displayText; private boolean
Hi I have following code block public class Driver { static String x =
I'm trying to understand the following code block and am a bit stumped.. specifically
i have the following block of code: $(#contact_container form, #contact_details form).live( submit, function(event) {
I have the following block of code which works fine; var boughtItemsToday = (from
given i have the following block of code (function(){ var mb = { abc:function(){
I have the following code block, as the content of my AppDelegate.h of an
I have the following code block for validation in PHP and I can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.