Question

In: Computer Science

Hello guys. Below is a test im struggling with I have to do it in Java...

Hello guys.
Below is a test im struggling with I have to do it in Java and use OOP concepts.


Create.

A House class with instance variables erfNumber, location, noOfRooms,
etc.
Mandatory properties: status(is the asset owned or sold), number of
years owned, selling price, and buying price.
At least two overloaded constructors that can be used to instatiate
House objects.
Getter and setter methods for all properties you have created.
A method checkProfitOrLoss() that returns the profit or loss that can be
made if the property is sold (sellingPrice-buyingPrice).
A custom toString() method to print out all the properties of a House
object.
A static counter to keep track of the number of each object created.
At least 5 more property or vehicle classes such as Farm, Flat, Bakkie,
RentalCar, etc.

A driver class named AssetManager.
An array of five House objects. The same applies to other classes created
in Section B.
Methods to add (remember to keep the sizes of the arrays in mind), sell
assets (sets the status of an asset at a given index of an array to sold), and
print the contents of each of the objects for each array. Each method to
have proper Javadoc comments.
Code to enter from input five of each of the assets into respective arrays
using the add methods just created.
Printing out the contents of all the arrays using the print methods you have
created to provide an initial asset report.
Change the current value of at least 10 objects from the arrays using the
getter and setter methods.
Print out the contents of the assets that can be sold at a profit using the
checkProfitOrLoss method and the methods you have provided an asset
sales report.

Solutions

Expert Solution

/***************************Assest.java***************/


/**
* The Class Vehicle.
*/
public class Vehicle extends Assest {

   /** The make. */
   private String make;

   /** The model. */
   private String model;

   /** The year. */
   private String year;

   /** The price. */
   private double price;

   /** The sellig price. */
   private double selligPrice;

   /** The buying price. */
   private double buyingPrice;

   /**
   * Instantiates a new vehicle.
   *
   * @param make the make
   * @param model the model
   * @param year the year
   * @param ownerName the owner name
   */
   public Vehicle(String make, String model, String year, String ownerName, int assestId) {
       super(ownerName, assestId);
       this.make = make;
       this.model = model;
       this.year = year;
   }

   /**
   * Instantiates a new vehicle.
   *
   * @param make the make
   * @param model the model
   * @param year the year
   * @param price the price
   * @param ownerName the owner name
   */
   public Vehicle(String make, String model, String year, double price, String ownerName, int assestId) {
       super(ownerName, assestId);
       this.make = make;
       this.model = model;
       this.year = year;
       this.price = price;
   }

   /**
   * Gets the make.
   *
   * @return the make
   */
   public String getMake() {
       return make;
   }

   /**
   * Sets the make.
   *
   * @param make the new make
   */
   public void setMake(String make) {
       this.make = make;
   }

   /**
   * Gets the model.
   *
   * @return the model
   */
   public String getModel() {
       return model;
   }

   /**
   * Sets the model.
   *
   * @param model the new model
   */
   public void setModel(String model) {
       this.model = model;
   }

   /**
   * Gets the year.
   *
   * @return the year
   */
   public String getYear() {
       return year;
   }

   /**
   * Sets the year.
   *
   * @param year the new year
   */
   public void setYear(String year) {
       this.year = year;
   }

   /**
   * Gets the price.
   *
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * Sets the price.
   *
   * @param price the new price
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /**
   * Gets the sellig price.
   *
   * @return the sellig price
   */
   public double getSelligPrice() {
       return selligPrice;
   }

   /**
   * Sets the sellig price.
   *
   * @param selligPrice the new sellig price
   */
   public void setSelligPrice(double selligPrice) {
       this.selligPrice = selligPrice;
   }

   /**
   * Gets the buying price.
   *
   * @return the buying price
   */
   public double getBuyingPrice() {
       return buyingPrice;
   }

   /**
   * Sets the buying price.
   *
   * @param buyingPrice the new buying price
   */
   public void setBuyingPrice(double buyingPrice) {
       this.buyingPrice = buyingPrice;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Vehicle [make=" + make + ", model=" + model + ", year=" + year + ", price=" + price + "]";
   }

   /*
   * (non-Javadoc)
   *
   * @see Assest#checkProfitOrLoss()
   */
   @Override
   public double checkProfitOrLoss() {

       return selligPrice - buyingPrice;
   }


   /*
   * (non-Javadoc)
   *
   * @see Assest#print()
   */
   @Override
   public void print() {

       System.out.println(this.toString());

   }

}
/***********************************House.java*********************/


/**
* The Class House.
*/
public class House extends Assest {

   /** The erf number. */
   private int erfNumber;

   /** The location. */
   private String location;

   /** The no of rooms. */
   private int noOfRooms;

   /** The status. */
   private String status;

   /** The no of years owned. */
   private int noOfYearsOwned;

   /** The selling price. */
   private double sellingPrice;

   /** The buying price. */
   private double buyingPrice;

   /** The number of houses. */
   private static int numberOfHouses;

   /**
   * Instantiates a new house.
   *
   * @param status the status
   * @param noOfYearsOwned the no of years owned
   * @param sellingPrice the selling price
   * @param buyingPrice the buying price
   * @param ownerName the owner name
   */
   public House(String status, int noOfYearsOwned, double sellingPrice, double buyingPrice, String ownerName,
           int assestId) {
       super(ownerName, assestId);
       this.status = status;
       this.noOfYearsOwned = noOfYearsOwned;
       this.sellingPrice = sellingPrice;
       this.buyingPrice = buyingPrice;
       numberOfHouses++;
   }

   /**
   * Instantiates a new house.
   *
   * @param erfNumber the erf number
   * @param location the location
   * @param noOfRooms the no of rooms
   * @param status the status
   * @param noOfYearsOwned the no of years owned
   * @param sellingPrice the selling price
   * @param buyingPrice the buying price
   * @param ownerName the owner name
   */
   public House(int erfNumber, String location, int noOfRooms, String status, int noOfYearsOwned, double sellingPrice,
           double buyingPrice, String ownerName, int assestId) {
       super(ownerName, assestId);
       this.erfNumber = erfNumber;
       this.location = location;
       this.noOfRooms = noOfRooms;
       this.status = status;
       this.noOfYearsOwned = noOfYearsOwned;
       this.sellingPrice = sellingPrice;
       this.buyingPrice = buyingPrice;
       numberOfHouses++;
   }

   /**
   * Gets the erf number.
   *
   * @return the erf number
   */
   public int getErfNumber() {
       return erfNumber;
   }

   /**
   * Sets the erf number.
   *
   * @param erfNumber the new erf number
   */
   public void setErfNumber(int erfNumber) {
       this.erfNumber = erfNumber;
   }

   /**
   * Gets the location.
   *
   * @return the location
   */
   public String getLocation() {
       return location;
   }

   /**
   * Sets the location.
   *
   * @param location the new location
   */
   public void setLocation(String location) {
       this.location = location;
   }

   /**
   * Gets the no of rooms.
   *
   * @return the no of rooms
   */
   public int getNoOfRooms() {
       return noOfRooms;
   }

   /**
   * Sets the no of rooms.
   *
   * @param noOfRooms the new no of rooms
   */
   public void setNoOfRooms(int noOfRooms) {
       this.noOfRooms = noOfRooms;
   }

   /**
   * Gets the status.
   *
   * @return the status
   */
   public String getStatus() {
       return status;
   }

   /**
   * Sets the status.
   *
   * @param status the new status
   */
   public void setStatus(String status) {
       this.status = status;
   }

   /**
   * Gets the no of years owned.
   *
   * @return the no of years owned
   */
   public int getNoOfYearsOwned() {
       return noOfYearsOwned;
   }

   /**
   * Sets the no of years owned.
   *
   * @param noOfYearsOwned the new no of years owned
   */
   public void setNoOfYearsOwned(int noOfYearsOwned) {
       this.noOfYearsOwned = noOfYearsOwned;
   }

   /**
   * Gets the selling price.
   *
   * @return the selling price
   */
   public double getSellingPrice() {
       return sellingPrice;
   }

   /**
   * Sets the selling price.
   *
   * @param sellingPrice the new selling price
   */
   public void setSellingPrice(double sellingPrice) {
       this.sellingPrice = sellingPrice;
   }

   /**
   * Gets the buying price.
   *
   * @return the buying price
   */
   public double getBuyingPrice() {
       return buyingPrice;
   }

   /**
   * Sets the buying price.
   *
   * @param buyingPrice the new buying price
   */
   public void setBuyingPrice(double buyingPrice) {
       this.buyingPrice = buyingPrice;
   }

   /**
   * Gets the number of houses.
   *
   * @return the number of houses
   */
   public static int getNumberOfHouses() {
       return numberOfHouses;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "House [erfNumber=" + erfNumber + ", location=" + location + ", noOfRooms=" + noOfRooms + ", status="
               + status + ", noOfYearsOwned=" + noOfYearsOwned + ", sellingPrice=" + sellingPrice + ", buyingPrice="
               + buyingPrice + "]";
   }

   /*
   * (non-Javadoc)
   *
   * @see Assest#checkProfitOrLoss()
   */
   public double checkProfitOrLoss() {

       return sellingPrice - buyingPrice;
   }

   /*
   * (non-Javadoc)
   *
   * @see Assest#print()
   */
   @Override
   public void print() {

       System.out.println(this.toString());

   }

}
/**************************************Vehicle.java*****************/


/**
* The Class Vehicle.
*/
public class Vehicle extends Assest {

   /** The make. */
   private String make;

   /** The model. */
   private String model;

   /** The year. */
   private String year;

   /** The price. */
   private double price;

   /** The sellig price. */
   private double selligPrice;

   /** The buying price. */
   private double buyingPrice;

   /**
   * Instantiates a new vehicle.
   *
   * @param make the make
   * @param model the model
   * @param year the year
   * @param ownerName the owner name
   */
   public Vehicle(String make, String model, String year, String ownerName, int assestId) {
       super(ownerName, assestId);
       this.make = make;
       this.model = model;
       this.year = year;
   }

   /**
   * Instantiates a new vehicle.
   *
   * @param make the make
   * @param model the model
   * @param year the year
   * @param price the price
   * @param ownerName the owner name
   */
   public Vehicle(String make, String model, String year, double price, String ownerName, int assestId) {
       super(ownerName, assestId);
       this.make = make;
       this.model = model;
       this.year = year;
       this.price = price;
   }

   /**
   * Gets the make.
   *
   * @return the make
   */
   public String getMake() {
       return make;
   }

   /**
   * Sets the make.
   *
   * @param make the new make
   */
   public void setMake(String make) {
       this.make = make;
   }

   /**
   * Gets the model.
   *
   * @return the model
   */
   public String getModel() {
       return model;
   }

   /**
   * Sets the model.
   *
   * @param model the new model
   */
   public void setModel(String model) {
       this.model = model;
   }

   /**
   * Gets the year.
   *
   * @return the year
   */
   public String getYear() {
       return year;
   }

   /**
   * Sets the year.
   *
   * @param year the new year
   */
   public void setYear(String year) {
       this.year = year;
   }

   /**
   * Gets the price.
   *
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * Sets the price.
   *
   * @param price the new price
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /**
   * Gets the sellig price.
   *
   * @return the sellig price
   */
   public double getSelligPrice() {
       return selligPrice;
   }

   /**
   * Sets the sellig price.
   *
   * @param selligPrice the new sellig price
   */
   public void setSelligPrice(double selligPrice) {
       this.selligPrice = selligPrice;
   }

   /**
   * Gets the buying price.
   *
   * @return the buying price
   */
   public double getBuyingPrice() {
       return buyingPrice;
   }

   /**
   * Sets the buying price.
   *
   * @param buyingPrice the new buying price
   */
   public void setBuyingPrice(double buyingPrice) {
       this.buyingPrice = buyingPrice;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Vehicle [make=" + make + ", model=" + model + ", year=" + year + ", price=" + price + "]";
   }

   /*
   * (non-Javadoc)
   *
   * @see Assest#checkProfitOrLoss()
   */
   @Override
   public double checkProfitOrLoss() {

       return selligPrice - buyingPrice;
   }


   /*
   * (non-Javadoc)
   *
   * @see Assest#print()
   */
   @Override
   public void print() {

       System.out.println(this.toString());

   }

}
/*******************************AssestManager.java*******************/

public class AssetManager {

   private Assest[] assests;
   private int capacity;
   private int index;

   public AssetManager() {
       this.index = 0;
       this.capacity = 5;
       assests = new Assest[capacity];
   }

   public void addAssest(Assest asset) {

       if (index == capacity) {
           capacity = 2 * capacity;
           resize(2 * capacity);
       }

       assests[index] = asset;
       index++;

   }

   private void resize(int i) {

       Assest[] assestsCopy = new Assest[i];
       for (int j = 0; j < assests.length; j++) {

           assestsCopy[j] = assests[j];
       }
       assests = assestsCopy;
   }

   public void sellAssest(Assest assest) {

       int loc = 0, flag = 0;
       try {
           for (int i = 0; i < assests.length; i++) {

               if (assests[i].equals(assest)) {

                   loc = i;
                   flag = 1;
               }
           }
       } catch (Exception e) {

       }

       if (flag == 1) {

           System.arraycopy(assests, loc + 1, assests, loc, assests.length - 1 - loc);

       } else {

           System.out.println("Assest not found!");
       }
   }

   public void printArray() {

       try {
           for (Assest assest : assests) {

               assest.print();
           }
       } catch (Exception e) {

       }
   }
}
/****************************TestAssest.java*****************/


// TODO: Auto-generated Javadoc
/**
* The Class TestAsset.
*/
public class TestAsset {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {

       AssetManager mngr = new AssetManager();
       House house = new House("owned", 5, 5000, 4000, "JKS", 101);
       mngr.addAssest(house);
       mngr.addAssest(new House("owned", 5, 5000, 4000, "MS", 102));
       mngr.addAssest(new House("owned", 5, 5000, 4000, "Virat", 103));
       mngr.addAssest(new House("sold", 5, 5000, 4000, "JKS", 104));
       mngr.addAssest(new House("owned", 5, 5000, 4000, "JKS", 105));
       mngr.addAssest(new Vehicle("Hero", "top model", "2019", "MS", 106));
       mngr.addAssest(new Vehicle("Bajaj", "top model", "2018", "JKS", 107));
       mngr.addAssest(new Vehicle("Hero", "top model", "2017", "MS", 108));
       mngr.addAssest(new Vehicle("Hero", "top model", "2018", "Virat", 109));
       mngr.addAssest(new Vehicle("Hero", "top model", "2019", "JKS", 110));

       mngr.printArray();

       System.out.println("\nAfter selling\n");
       mngr.sellAssest(house);
       mngr.printArray();
   }
}
/*****************output******************/

House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=sold, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
Vehicle [make=Hero, model=top model, year=2019, price=0.0]
Vehicle [make=Bajaj, model=top model, year=2018, price=0.0]
Vehicle [make=Hero, model=top model, year=2017, price=0.0]
Vehicle [make=Hero, model=top model, year=2018, price=0.0]
Vehicle [make=Hero, model=top model, year=2019, price=0.0]

After selling

House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=sold, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
House [erfNumber=0, location=null, noOfRooms=0, status=owned, noOfYearsOwned=5, sellingPrice=5000.0, buyingPrice=4000.0]
Vehicle [make=Hero, model=top model, year=2019, price=0.0]
Vehicle [make=Bajaj, model=top model, year=2018, price=0.0]
Vehicle [make=Hero, model=top model, year=2017, price=0.0]
Vehicle [make=Hero, model=top model, year=2018, price=0.0]
Vehicle [make=Hero, model=top model, year=2019, price=0.0]

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM WITH THE DIFFERNT CLASSES LISTED BELOW. I WILL...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM WITH THE DIFFERNT CLASSES LISTED BELOW. I WILL LEAVE AWESOME RATING. THANK YOU IN ADVANCE. The code needed for this assignment has to somehow implement a stack interface (including a vector stack, array stack, and a linked stack). The classes needed are the Game class, the disk class, the driver, and the stack interface (including arraystack, linkedstack, and vectorstack) QUESTION Suppose you are designing a game called King of the Stacks. The...
Hello , I'm struggling in the following questions and I need an explanation if it is...
Hello , I'm struggling in the following questions and I need an explanation if it is possible question 1) :A 51.0 mL aliquot of HCl(aq) of unknown concentration was titrated with 0.226 M NaOH(aq). It took 102.4 mL of the base to reach the endpoint of the titration. what the concentration (M) of the acid was ? question 2) :How many moles of BaCl2 are formed in the neutralization of 196.5 mL of 0.095 M Ba(OH)2 with aqueous Hal? question...
Hello, I have been struggling with the problem for a while now. Can someone please assist?...
Hello, I have been struggling with the problem for a while now. Can someone please assist? I cannot find the data online much less calculate the standard deviation. 1. Go to finance.yahoo.com and find them monthly rates of return over a 2 year period for five companies of your choice. Now assume you form each month an equally weighted portfolio of five firms (a portfolio with equal investments in each firm). What is the rate of return each month on...
Hello, I'm really struggling with this problem. So far I have calculated 48,000 for preferred and...
Hello, I'm really struggling with this problem. So far I have calculated 48,000 for preferred and 38,000 for common, which I know to be incorrect per my professor.  I also calculated 64,703 as the preferred and 41,697 as the common but I know these to be incorrect as well. I'm just not sure how to calculate this. Please see the below. The outstanding capital stock of Skysong Corporation consists of 2,000 shares of $100 par value, 8% preferred, and 5,100 shares...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I cannot find the solution for. It involves expressions with Infix I'll need a Java Program to convert an expression, eg. 3+6*(x-y)+x^2 to ((3 + (6 * (x-y))) + (x ^ 2)) Kindly assist. Thanks
Hello guys i would to build a buck converter and use arduino PWM to control the...
Hello guys i would to build a buck converter and use arduino PWM to control the output voltage 12V to 8.4V any ideas ? thanks
hello everyone, i have this assignment to do and i dunno how to structure it as...
hello everyone, i have this assignment to do and i dunno how to structure it as i didnt have enough informations about the layout and the structure. please provide me with the structure starting from the introduction, excutive summary,...,.....,......,.......,conclusion and references. i need to fill up the paragraphs but i dunno what to layout. Assume your group comprises the Sydney City Council. In an effort to reduce inner city congestion, there is already a project to establish light rail. But...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
Hello. I have a statement that I´m having difficulties to answer. Do you have any input...
Hello. I have a statement that I´m having difficulties to answer. Do you have any input on this? "The only objective companies need to follow to achieve stakeholder goals is shareholder wealth maximisation." Thank you
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM I WILL LEAVE AWESOME RATING. THANK YOU IN...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM I WILL LEAVE AWESOME RATING. THANK YOU IN ADVANCE. QUESTION Suppose you are designing a game called King of the Stacks. The rules of the game are as follows:  The game is played with two (2) players.  There are three (3) different Stacks in the game.  Each turn, a player pushes a disk on top of exactly one of the three Stacks. Players alternate turns throughout the game. Each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT