238 lines
6.2 KiB
Java
238 lines
6.2 KiB
Java
|
|
/**
|
|
* This class is an imitation of a house for sale in a real estate business. It allows for the buying, selling and modification of the house.
|
|
*
|
|
* @author George Wilkinson
|
|
* @version 6/10/23
|
|
*/
|
|
public class House
|
|
{
|
|
// instance variables
|
|
private String typeOfHouse;
|
|
private String address;
|
|
private int initialPurchasePrice;
|
|
private int purchasePrice;
|
|
private int homeEnergyRating;
|
|
private char councilTaxBand;
|
|
private String owner;
|
|
private int numberOfOwners;
|
|
private boolean hasGarage;
|
|
|
|
/**
|
|
* Constructor for objects of class House
|
|
*/
|
|
public House( String type, String homeAddress, int initPrice, int energyRating, char taxBand, boolean garage)
|
|
{
|
|
// initialise house attriutes
|
|
typeOfHouse = type;
|
|
address = homeAddress;
|
|
initialPurchasePrice = initPrice;
|
|
homeEnergyRating = energyRating;
|
|
councilTaxBand = taxBand;
|
|
hasGarage = garage;
|
|
|
|
purchasePrice = 0;
|
|
owner = "None";
|
|
numberOfOwners = 0;
|
|
checkHomeEnergyRating();
|
|
}
|
|
|
|
/**
|
|
* Simulates changing home efficiency value.
|
|
* Takes @homeEnergyRating and replaces with a user input value @newHomeEnergyRating, then
|
|
* prints a confirmation message to the output log.
|
|
*/
|
|
|
|
public void goingGreener( int newHomeEnergyRating )
|
|
{
|
|
homeEnergyRating = newHomeEnergyRating; //Update homeEnergyRating variable's value
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @typeOfHouse to the user.
|
|
*/
|
|
|
|
public String getType()
|
|
{
|
|
return typeOfHouse;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @address
|
|
*/
|
|
|
|
public String getAddress()
|
|
{
|
|
return address;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @initalPurchasePrice
|
|
*/
|
|
|
|
public int getInitialPurchasePrice()
|
|
{
|
|
return initialPurchasePrice;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @homeEnergyRating
|
|
*/
|
|
public int getEnergyRating()
|
|
{
|
|
return homeEnergyRating;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @councilTaxBand
|
|
*/
|
|
public char getTaxBand()
|
|
{
|
|
return councilTaxBand;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @hasGarage
|
|
*/
|
|
public boolean getGarage()
|
|
{
|
|
return hasGarage;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @purchasePrice
|
|
*/
|
|
public int getPurchasePrice()
|
|
{
|
|
return purchasePrice;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @owner
|
|
*/
|
|
public String getOwner()
|
|
{
|
|
return owner;
|
|
}
|
|
|
|
/**
|
|
* Returns the value of @numberOfOwners
|
|
*/
|
|
public int getNumberOfOwners()
|
|
{
|
|
return numberOfOwners;
|
|
}
|
|
|
|
/**
|
|
* Set @typeOfHouse to a user-input value
|
|
*/
|
|
|
|
public void setType( String type )
|
|
{
|
|
typeOfHouse = type; //Update the type variable's value
|
|
System.out.println( "Type of this house is now: " + typeOfHouse );
|
|
}
|
|
|
|
/**
|
|
* Set @address to a user-input value
|
|
*/
|
|
|
|
public void setAddress( String newAddress )
|
|
{
|
|
address = newAddress; //Update the address variable's value
|
|
System.out.println( "Address of this house is now: " + address );
|
|
}
|
|
|
|
/**
|
|
* Set @councilTaxBand to a user-input value
|
|
*/
|
|
|
|
public void setCouncilTaxBand( char newBand )
|
|
{
|
|
councilTaxBand = newBand; //Update the Tax Band variable's value
|
|
System.out.println( "Council Tax Band of this house is now: " + councilTaxBand );
|
|
}
|
|
|
|
/**
|
|
* Set @hasGarage to a user-input value
|
|
*/
|
|
|
|
public void setGarage( boolean garage )
|
|
{
|
|
hasGarage = garage; //Update the garage variable's value
|
|
System.out.println( "Garage state of this house is: " + hasGarage );
|
|
}
|
|
|
|
/**
|
|
* Set @owner to a user-input value
|
|
*/
|
|
|
|
public void setOwner( String newOwner )
|
|
{
|
|
owner = newOwner; //Update the owner variable's value
|
|
System.out.println( "Owner of this house is now: " + owner );
|
|
}
|
|
|
|
/**
|
|
* Set @purchasePrice to a user-input value
|
|
*/
|
|
|
|
public void setPurchasePrice( int newPurchasePrice )
|
|
{
|
|
purchasePrice = newPurchasePrice; //Update the purchasePrice variable's value
|
|
System.out.println( "House has been purchased for: £" + purchasePrice );
|
|
}
|
|
|
|
/**
|
|
* Set @numberOfOwners to a user-input value
|
|
*/
|
|
public void setNumberOfOwners( int newNumberOfOwners )
|
|
{
|
|
numberOfOwners = newNumberOfOwners;
|
|
System.out.println( "Number of Owners of this house is now: " + numberOfOwners );
|
|
}
|
|
|
|
/**
|
|
* Print all fields of object for the user.
|
|
*/
|
|
|
|
public void printDetails()
|
|
{
|
|
System.out.println( "House type: " + typeOfHouse );
|
|
System.out.println( "Address: " + address );
|
|
System.out.println( "Original purchase price in pounds: " + initialPurchasePrice );
|
|
System.out.println( "Current price in pounds: " + purchasePrice );
|
|
System.out.println( "Home energy rating: " + homeEnergyRating );
|
|
System.out.println( "Council Tax Band: " + councilTaxBand );
|
|
System.out.println( "Number of owners to date: " + numberOfOwners );
|
|
System.out.println( "Current owner: " + owner );
|
|
}
|
|
|
|
/**
|
|
* Print to log when @homeEnergyRating is above or below a threshold of 3.
|
|
*/
|
|
|
|
public void checkHomeEnergyRating()
|
|
{
|
|
if( homeEnergyRating < 3 )
|
|
{
|
|
System.out.println( "Be aware that extra green taxes may be imposed on this house" );
|
|
}
|
|
else
|
|
{
|
|
System.out.println( "This house will not be subject to extra taxes" );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Simulates selling the house by calling the setOwner() and setPurchasePrice() methods.
|
|
*/
|
|
|
|
public void sell( String newOwner, int newPurchasePrice )
|
|
{
|
|
setOwner( newOwner ); //Call the setOwner method to set the purchaser's name
|
|
setPurchasePrice( newPurchasePrice ); //Call the setPurchasePrice method to set the buy price of the house after it is sold.
|
|
setNumberOfOwners( numberOfOwners + 1 ); //Call the setNumberOfOwners mutator to increment the owner count after selling.
|
|
}
|
|
}
|