Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 3 years ago

I need help desperately with Java problem?

The SingleFamily class represents a single family home that is either owner-occupied, or not (rented out). The main method of the SingleFamilyTester class creates a SingleFamily object and prints out some information about it.

public class SingleFamilyTester {

public static void main(String[] args) {

System.out.println("I own a single-family dwelling.");

SingleFamily house = new SingleFamily(true);

System.out.print("The house is ");

if (!house.getOwnerOcc()) {

System.out.print("not ");

}

System.out.println("owner-occupied.");

System.out.println("I have just moved.");

house.setOwnerOcc(false);

System.out.print("Now the house is ");

if (!house.getOwnerOcc()) {

System.out.print("not ");

}

System.out.println("owner-occupied.");

}

}

This is one example of how to use the SingleFamily class. Running the main method as written above gives the following output.

I own a single-family dwelling.

The house is owner-occupied.

I have just moved.

Now the house is not owner-occupied.

Here is an incomplete version of the SingleFamily class. Complete the definition so that the SingleFamilyTester driver will work properly with your enhanced definition for SingleFamily.

public class SingleFamily {

private boolean ownerOccupied;

public SingleFamily(boolean yesNo) {

ownerOccupied = yesNo;

}

public void setOwnerOcc(boolean yesNo) {

ownerOccupied = yesNo;

}

1

} // end class SingleFamily

2 Answers

Relevance
  • 2 years ago

    Probably pretty late but it s this:

    public boolean getOwnerOcc(){

    return ownerOccupied;

    }

    I hope I saved at least one of you iJava kids.

  • 3 years ago

    Cool

Still have questions? Get your answers by asking now.