Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class for Managing Porperty Objects.
- *
- * @author
- * @version
- */
- public class Company
- {
- // instance variables
- private int numPropertiesForSale;
- private int numPropertiesSold;
- final int MAX_PROPERTIES = 10;
- private Property[] propertiesForSale = new Property[MAX_PROPERTIES];
- private Property[] propertiesSold = new Property[MAX_PROPERTIES];
- public Company()
- {
- //This constructor is not required as the implict constructor
- //is all thats needed where no initalisation is done
- //This is left in for assesment requriement purposes
- }
- /**
- * Add Property for Sale - Adds Property object array of properties for sale
- *
- * @param inProperty Name of Property object to put up for sale
- */
- public void addPropertyForSale(Property inProperty)
- {
- if (numPropertiesForSale < MAX_PROPERTIES) {
- propertiesForSale[numPropertiesForSale] = inProperty;
- numPropertiesForSale ++;
- }
- }
- /**
- * Print all Properties for Sale - Prints all properties that are for sale
- */
- public void printAllPropertiesForSale()
- {
- System.out.println("*** List of all properties for sale");
- for (int i = 0; i < numPropertiesForSale; i++) {
- propertiesForSale[i].printDetails();
- System.out.println(" ");
- }
- }
- /**
- * Print All Properties Sold - Prints all properties that have been sold
- */
- public void printAllPropertiesSold()
- {
- System.out.println("*** List of all properties sold");
- for (int i = 0; i < numPropertiesSold; i++) {
- propertiesSold[i].printDetails();
- System.out.println(" ");
- }
- }
- /**
- * Print Total Sales Figure - Prints the figure of money made from all Sales
- */
- public void printTotalSalesFigure()
- {
- double figure = 0;
- for (int i = 0; i < numPropertiesSold; i++) {
- figure = figure + propertiesSold[i].getPrice();
- }
- System.out.println("*** Total Sales Figure is $" + figure);
- System.out.println(" ");
- }
- /**
- * Sell Property Method - Sells Property that has the given Property ID
- *
- * @param inId ID of Property object thats for sale
- */
- public void sellProperty(int inId)
- {
- if (numPropertiesForSale > 0) {
- int iDel = -1;
- for (int i = 0; i < numPropertiesForSale; i++) {
- if ( inId == propertiesForSale[i].getID() && numPropertiesSold < MAX_PROPERTIES) {
- propertiesSold[numPropertiesSold] = propertiesForSale[i];
- iDel = i;
- }
- }
- if (iDel != -1) {
- for (int i = iDel; i < numPropertiesForSale; i++) {
- propertiesForSale[i] = propertiesForSale[i + 1];
- }
- }
- numPropertiesForSale--;
- numPropertiesSold++;
- }
- }
- /**
- * Print Expesnive Properties - Prints all properties that cost more than the given threshold
- *
- * @param threshold how expesnive is an expensive Property
- */
- public void printExpensivePropertiesForSale(double threshhold)
- {
- System.out.println("*** List of all properties for sale >= $" + threshhold);
- for (int i = 0; i < numPropertiesForSale; i++) {
- if (propertiesForSale[i].getPrice() >= threshhold) {
- propertiesForSale[i].printDetails();
- System.out.println(" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement