Advertisement
JMZ10

Untitled

Sep 21st, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.63 KB | None | 0 0
  1. /**
  2.  * Class for Managing Porperty Objects.
  3.  *
  4.  * @author
  5.  * @version
  6.  */
  7. public class Company
  8. {
  9.     // instance variables
  10.     private int numPropertiesForSale;
  11.     private int numPropertiesSold;
  12.     final int MAX_PROPERTIES = 10;
  13.     private Property[] propertiesForSale = new Property[MAX_PROPERTIES];
  14.     private Property[] propertiesSold = new Property[MAX_PROPERTIES];
  15.  
  16.     public Company()
  17.     {
  18.         //This constructor is not required as the implict constructor
  19.         //is all thats needed where no initalisation is done
  20.         //This is left in for assesment requriement purposes
  21.     }
  22.  
  23.     /**
  24.      * Add Property for Sale - Adds Property object array of properties for sale
  25.      *
  26.      * @param  inProperty   Name of Property object to put up for sale
  27.      */
  28.     public void addPropertyForSale(Property inProperty)
  29.     {
  30.         if (numPropertiesForSale < MAX_PROPERTIES) {
  31.             propertiesForSale[numPropertiesForSale] = inProperty;
  32.             numPropertiesForSale ++;
  33.         }
  34.     }
  35.  
  36.     /**
  37.      * Print all Properties for Sale - Prints all properties that are for sale
  38.      */
  39.     public void printAllPropertiesForSale()
  40.     {
  41.         System.out.println("*** List of all properties for sale");
  42.         for (int i = 0; i < numPropertiesForSale; i++) {
  43.             propertiesForSale[i].printDetails();
  44.             System.out.println(" ");
  45.         }
  46.     }
  47.  
  48.     /**
  49.      * Print All Properties Sold - Prints all properties that have been sold
  50.      */
  51.     public void printAllPropertiesSold()
  52.     {
  53.         System.out.println("*** List of all properties sold");
  54.         for (int i = 0; i < numPropertiesSold; i++) {
  55.             propertiesSold[i].printDetails();
  56.             System.out.println(" ");
  57.         }
  58.     }
  59.  
  60.     /**
  61.      * Print Total Sales Figure - Prints the figure of money made from all Sales
  62.      */
  63.     public void printTotalSalesFigure()
  64.     {
  65.         double figure = 0;
  66.         for (int i = 0; i < numPropertiesSold; i++) {
  67.             figure = figure + propertiesSold[i].getPrice();
  68.         }
  69.         System.out.println("*** Total Sales Figure is $" + figure);
  70.         System.out.println(" ");
  71.     }
  72.  
  73.     /**
  74.      * Sell Property Method - Sells Property that has the given Property ID
  75.      *
  76.      * @param  inId   ID of Property object thats for sale
  77.      */
  78.     public void sellProperty(int inId)
  79.     {
  80.  
  81.         if (numPropertiesForSale > 0) {
  82.             int iDel = -1;
  83.             for (int i = 0; i < numPropertiesForSale; i++) {
  84.                 if ( inId == propertiesForSale[i].getID() && numPropertiesSold < MAX_PROPERTIES) {
  85.                     propertiesSold[numPropertiesSold] = propertiesForSale[i];
  86.                     iDel = i;
  87.                 }
  88.             }
  89.  
  90.             if (iDel != -1) {
  91.                 for (int i = iDel; i < numPropertiesForSale; i++) {
  92.                     propertiesForSale[i] = propertiesForSale[i + 1];
  93.                 }
  94.             }
  95.             numPropertiesForSale--;
  96.             numPropertiesSold++;
  97.         }
  98.  
  99.     }
  100.  
  101.     /**
  102.      * Print Expesnive Properties - Prints all properties that cost more than the given threshold
  103.      *
  104.      * @param  threshold   how expesnive is an expensive Property
  105.      */
  106.     public void printExpensivePropertiesForSale(double threshhold)
  107.     {
  108.         System.out.println("*** List of all properties for sale >= $" + threshhold);
  109.         for (int i = 0; i < numPropertiesForSale; i++) {
  110.             if (propertiesForSale[i].getPrice() >= threshhold) {
  111.                 propertiesForSale[i].printDetails();
  112.                 System.out.println(" ");
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement