Created
May 26, 2019 12:21
-
-
Save GrunclePug/35211bd035c2a016892a9c7563d06375 to your computer and use it in GitHub Desktop.
COMP 1409 | Assignment01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class to model a Vehicle | |
* | |
* Assignment 1 | |
* | |
* @author Chad | |
* @version 1.0 | |
*/ | |
public class Vehicle | |
{ | |
//Constants | |
public static final int MIN_YEAR = 1970; | |
public static final int MAX_YEAR = 2016; | |
public static final double MIN_PROFIT_MARGIN = 0.25; | |
//Instance Variables | |
private String stockCode = "2005Nissan350z"; | |
private String make = "Nissan"; | |
private String model = "350z"; | |
private int year = 2005; | |
private double dealerCost = 7500.00; | |
private double sellingPrice = 10000.00; | |
private double profitMargin = 0.25; | |
/** | |
* Default constructor. | |
*/ | |
public Vehicle() | |
{ | |
} | |
/** | |
* Constructor for creating a Vehicle instance. | |
* | |
* @param _stockCode The stock code for the vehicle | |
* @param _make The make for the vehicle | |
* @param _model The model for the vehicle | |
* @param _year The year for the vehicle | |
*/ | |
public Vehicle(String _stockCode, String _make, String _model, int _year) | |
{ | |
setStockCode(_stockCode); | |
setMake(_make); | |
setModel(_model); | |
setYear(_year); | |
} | |
/** | |
* Sets the stock code of vehicle. | |
* | |
* @param _stockCode The new stock code. | |
*/ | |
public void setStockCode(String _stockCode) | |
{ | |
stockCode = _stockCode; | |
} | |
/** | |
* Sets the make of the vehicle. | |
* | |
* @param _make The new make. | |
*/ | |
public void setMake(String _make) | |
{ | |
make = _make; | |
} | |
/** | |
* Sets the model of the vehicle. | |
* | |
* @param _model The new model. | |
*/ | |
public void setModel(String _model) | |
{ | |
model = _model; | |
} | |
/** | |
* Sets the year of the vehicle. | |
* | |
* Must be between MIN_YEAR (default: 1970) and MAX_YEAR (default: 2016) | |
* | |
* @param _year The new year. | |
*/ | |
public void setYear(int _year) | |
{ | |
if(_year >= MIN_YEAR && _year <= MAX_YEAR) | |
{ | |
year = _year; | |
} | |
else | |
{ | |
System.out.println("Error: year must be between 1970 and 2016"); | |
} | |
} | |
/** | |
* Sets the dealer cost of the vehicle. | |
* | |
* Must be a positive number | |
* | |
* @param _dealerCost The dealer cost. | |
*/ | |
public void setDealerCost(double _dealerCost) | |
{ | |
if(_dealerCost >= 0) | |
{ | |
dealerCost = _dealerCost; | |
} | |
else | |
{ | |
System.out.println("Error: Dealer cost must be a positive number"); | |
} | |
} | |
/** | |
* Sets the selling price if allowed. | |
* | |
* Must be at least 25% greater than dealer cost | |
* | |
* @param _sellingPrice The selling price. | |
*/ | |
public void checkStandardSellingPrice(double _sellingPrice) | |
{ | |
if((_sellingPrice - dealerCost) / _sellingPrice >= MIN_PROFIT_MARGIN) | |
{ | |
sellingPrice = _sellingPrice; | |
} | |
else | |
{ | |
System.out.println("Error: New Selling Price ($" + _sellingPrice + ") is not allowed." + | |
"\nSelling price must be 25% higher than dealer cost" + | |
"\nDealer Cost: $" + dealerCost + | |
"\nCurrent Selling Price: $" + sellingPrice); | |
} | |
} | |
/** | |
* Override for setting selling price. | |
* | |
* Must be a positive number | |
* | |
* @param _sellingPrice The selling price. | |
*/ | |
public void setSellingPrice(double _sellingPrice) | |
{ | |
if(_sellingPrice >= 0) | |
{ | |
sellingPrice = _sellingPrice; | |
} | |
else | |
{ | |
System.out.println("Error: Selling price must be a positive number."); | |
} | |
} | |
/** | |
* Gets the stock code of the vehicle. | |
* | |
* @return The stock code. | |
*/ | |
public String getStockCode() | |
{ | |
return stockCode; | |
} | |
/** | |
* Gets the make of the vehicle. | |
* | |
* @return The make. | |
*/ | |
public String getMake() | |
{ | |
return make; | |
} | |
/** | |
* Gets the model of the vehicle. | |
* | |
* @return The model. | |
*/ | |
public String getModel() | |
{ | |
return model; | |
} | |
/** | |
* Gets the year of the vehicle. | |
* | |
* @return The year. | |
*/ | |
public int getYear() | |
{ | |
return year; | |
} | |
/** | |
* Gets the dealer cost of the vehicle. | |
* | |
* @return The dealer cost. | |
*/ | |
public double getDealerCost() | |
{ | |
return dealerCost; | |
} | |
/** | |
* Gets the selling price of the vehicle. | |
* | |
* @return The selling price. | |
*/ | |
public double getSellingPrice() | |
{ | |
return sellingPrice; | |
} | |
/** | |
* Gets the profit margin of the vehicle. | |
* | |
* @return The profit margin. | |
*/ | |
public double getProfitMargin() | |
{ | |
return profitMargin; | |
} | |
/** | |
* Calculates the percent profit for the sale of the vehicle. | |
* | |
* @return The profit, percentage. | |
*/ | |
public double calculateProfitMargin() | |
{ | |
profitMargin = (sellingPrice - dealerCost) / sellingPrice; | |
return profitMargin; | |
} | |
/** | |
* Calculates the dollar value profit for the sale of the vehicle. | |
* | |
* @return The profit, in dollars. | |
*/ | |
public double calculateProfit() | |
{ | |
double profit = sellingPrice - dealerCost; | |
return profit; | |
} | |
/** | |
* Prints full list of details on vehicle. | |
*/ | |
public void printDetails() | |
{ | |
String details = "Jalopies Are Us Vehicle Summary:" + | |
"\nVehicle: " + year + " " + make + " " + model + | |
"\nStock Code: " + stockCode + | |
"\nDealer Cost: $" + dealerCost + | |
"\nSelling Price: $" + sellingPrice + | |
"\nProfit Margin: " + (calculateProfitMargin() * 100) + "%" + | |
"\nDollar Profit: $" + calculateProfit(); | |
System.out.println(details); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment