Section 0
Problem Background A local entrepreneur has investments in property and vehicles. Recently business has boomed and she needs object-oriented software to keep track of her current and past assets. As an OOP expert, you are tasked to write a program that keeps track of these assets. You are recommended to read through the requirements of all sections before attempting any coding.
Section 1: Basic Classes
• 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.
Section 2: Driver Class
• A driver class named AssetManager. • An array of five House objects. The same applies to other classes created in Section 1.
• 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.
Section 3: Advanced Requirements
Writing to a file is better that using volatile memory. Inheritance allows code reuse, thus saving time.
Exceptions are handy when dealing with issues that may disrrupt normal program. Your creativity is expected to demonstrate deep understanding of OOP concepts you learned this semester. This can be achieved by redesigning Sections 1 and 2 to solve the problem in Section 0. Note that Section 1 and 2 were given you to have a general understanding of what your program solution should do.
Your final solution should have at least a 3 level hierarchy of inheritance, an abstract class, two interfaces, polymorphism, aggregation, and composition, apart from writing to files and using exception handling. A UML class diagram denoting your design will be required as well.
/****************************Asset.java*******************/
/**
* The Class Assest.
*/
public abstract class Assest {
/** The owner name. */
private String ownerName;
/** The assest id. */
private int assestId;
/** The number of assest. */
private static int numberOfAssest = 0;
/**
* Instantiates a new assest.
*
* @param ownerName the owner name
* @param assestId the assest id
*/
public Assest(String ownerName, int assestId) {
super();
this.ownerName = ownerName;
this.assestId = assestId;
numberOfAssest++;
}
/**
* Gets the owner name.
*
* @return the owner name
*/
public String getOwnerName() {
return ownerName;
}
/**
* Sets the owner name.
*
* @param ownerName the new owner name
*/
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
/**
* Gets the assest id.
*
* @return the assest id
*/
public int getAssestId() {
return assestId;
}
/**
* Sets the assest id.
*
* @param assestId the new assest id
*/
public void setAssestId(int assestId) {
this.assestId = assestId;
}
/**
* Gets the number of assest.
*
* @return the number of assest
*/
public static int getNumberOfAssest() {
return numberOfAssest;
}
/**
* Check profit or loss.
*
* @return the double
*/
public abstract double checkProfitOrLoss();
/**
* Prints the.
*/
public abstract void print();
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this.ownerName.equalsIgnoreCase(((Assest) obj).ownerName) && this.assestId == ((Assest) obj).assestId) {
return
true;
} else {
return
false;
}
}
}
/************************************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*********************/
/**
* The Class AssetManager.
*/
public class AssetManager {
/** The assests. */
private Assest[] assests;
/** The capacity. */
private int capacity;
/** The index. */
private int index;
/**
* Instantiates a new asset manager.
*/
public AssetManager() {
this.index = 0;
this.capacity = 5;
assests = new
Assest[capacity];
}
/**
* Adds the assest.
*
* @param asset the asset
*/
public void addAssest(Assest asset) {
if (index == capacity) {
capacity = 2 *
capacity;
resize(2 *
capacity);
}
assests[index] = asset;
index++;
}
/**
* Resize.
*
* @param i the i
*/
private void resize(int i) {
Assest[] assestsCopy = new
Assest[i];
for (int j = 0; j <
assests.length; j++) {
assestsCopy[j] = assests[j];
}
assests = assestsCopy;
}
/**
* Sell assest.
*
* @param assest the assest
*/
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!");
}
}
/**
* Prints the array.
*/
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 :)
Section 0 Problem Background A local entrepreneur has investments in property and vehicles. Recently business has...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...
c++
driver and car are independed classes
1. Create a class Car, which has a color, engine, horsepower, fuel, FuelLevel, year of manufacturing and driver which can be defined by name, age, licenseNumber. Create the corresponding OOP in For each class (Driver, Car) write a header file and the class implementation -In the main function do the following: from that class in main function. L.1 Write a function that will print the total number of objects created 12 Define an...
You are given a specification for some Java classes as follows. A building has a number of floors, and a number of windows. A house is a building. A garage is a building. (This isn’t Florida-like … it’s a detached garage.) A room has a length, width, a floor covering, and a number of closets. You can never create an instance of a building, but every object that is a building must have a method that calculates the floor space,...
If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry store and some of the Inventory (rings/necklaces/earrings) purchased there (The Jewelry store can be real or not) using Object-Oriented Programming (OOP). The important aspect of object-oriented programming is modular development and testing of reusable software modules. You love selling rings, necklaces, and earrings as well as programming and have decided to open a Jewelry store. To save...
I Need Help with this using Java Programming
:
Class name
fname
lname
Class variable
total Number
Constructor (no arguments)
Constructor (takes two arguments, fname and lname)
One getter method to return the fname and lname
One setter method for fname and lname
Inside Main:
Create three objects with the following
names
Jill Doe
John James
Jack Smith
When creating the first object (Should
not be an anonymous object)
use the argument-less constructor
Then use the setter method to assign...
JAVA Problem: Coffee Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title. Create a use a menu that contains the following items, and calls corresponding methods that do the tasks the menu describes. Use classes when they're appropriate. Keep the driver class as simple as possible. Give each class, method and property simple, descriptive names using Hungarian notation. Square a number Simply pass a decimal-type number to the object that does this task. Process its...