Created
July 5, 2019 01:35
-
-
Save GrunclePug/7dcb04db46d00dbe0a2b10e5b9460c6d to your computer and use it in GitHub Desktop.
COMP 1409 | Assignment 3
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
/** | |
* Information for customers renting a musical instrument. | |
* | |
* @author Chad | |
* @version 1.0 | |
*/ | |
public class Customer | |
{ | |
private String firstName; | |
private String lastName; | |
private String driversLicense; | |
private String address; | |
private String phoneNumber; | |
/** | |
* defualt constructor for Customer class | |
*/ | |
public Customer() | |
{ | |
} | |
/** | |
* @param firstName to set the firstName field | |
* @param lastName to set the lastName field | |
* @param driversLicense to set the driversLicense field | |
* @param address to set the address field | |
* @param phoneNumber to set the phoneNumber field | |
*/ | |
public Customer(String firstName, String lastName, String driversLicense, String address, String phoneNumber) | |
{ | |
setFirstName(firstName); | |
setLastName(lastName); | |
setDriversLicense(driversLicense); | |
setAddress(address); | |
setPhoneNumber(phoneNumber); | |
} | |
/** | |
* @return the firstName | |
*/ | |
public String getFirstName() | |
{ | |
return firstName; | |
} | |
/** | |
* @param name The firstName to set | |
*/ | |
public void setFirstName(String name) | |
{ | |
if(name != null && name.trim().length() > 0) | |
{ | |
String fName = name.toLowerCase(); | |
firstName = fName.replace(fName.charAt(0), Character.toUpperCase(fName.charAt(0))); | |
} | |
else | |
{ | |
System.out.println("ERROR: invalid first name"); | |
} | |
} | |
/** | |
* @return the lastName | |
*/ | |
public String getLastName() | |
{ | |
return lastName; | |
} | |
/** | |
* @param name The lastName to set | |
*/ | |
public void setLastName(String name) | |
{ | |
if(name != null && name.trim().length() > 0) | |
{ | |
String lName = name.toLowerCase(); | |
lastName = lName.replace(lName.charAt(0), Character.toUpperCase(lName.charAt(0))); | |
} | |
else | |
{ | |
System.out.println("ERROR: invalid last name"); | |
} | |
} | |
/** | |
* @return the driversLicense | |
*/ | |
public String getDriversLicense() | |
{ | |
return driversLicense; | |
} | |
/** | |
* @param driversLicense the driver's license to set | |
*/ | |
public void setDriversLicense(String driversLicense) | |
{ | |
if(driversLicense != null && driversLicense.trim().length() > 0) | |
{ | |
this.driversLicense = driversLicense; | |
} | |
else | |
{ | |
System.out.println("ERROR: invalid drivers license"); | |
} | |
} | |
/** | |
* @return the address | |
*/ | |
public String getAddress() | |
{ | |
return address; | |
} | |
/** | |
* @param address the address to set | |
*/ | |
public void setAddress(String address) | |
{ | |
if(address != null && address.trim().length() > 0) | |
{ | |
this.address = address; | |
} | |
else | |
{ | |
System.out.println("ERROR: invalid address"); | |
} | |
} | |
/** | |
* @return the phoneNumber | |
*/ | |
public String getPhoneNumber() | |
{ | |
return phoneNumber; | |
} | |
/** | |
* @param phoneNumber the phoneNumber to set | |
*/ | |
public void setPhoneNumber(String phoneNumber) | |
{ | |
this.phoneNumber = phoneNumber; | |
} | |
/** | |
* @return the Customer first and last names. | |
*/ | |
public String getFullName() | |
{ | |
return firstName + " " + lastName; | |
} | |
} |
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 for the inventory of vehicles | |
* | |
* Assignment 3 | |
* | |
* @author Chad | |
* @version 1.0 | |
*/ | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
public class Inventory | |
{ | |
//Instance Variables | |
private static ArrayList<Vehicle> vehicles; | |
/** | |
* Default Constructor, initializes vehicles ArrayList | |
*/ | |
public Inventory() | |
{ | |
vehicles = new ArrayList<>(); | |
} | |
/** | |
* Accessor to get vehicles ArrayList | |
* | |
* @return vehicles vehicles ArrayList | |
*/ | |
public static ArrayList<Vehicle> getVehicles() | |
{ | |
return vehicles; | |
} | |
//Why did you ask for a mutator for an ArrayList????? | |
/** | |
* Mutator to set vehicles ArrayList | |
* | |
* @param _vehicles ArrayList for Vehicle type | |
*/ | |
public static void setVehicles(ArrayList<Vehicle> _vehicles) | |
{ | |
vehicles = _vehicles; | |
} | |
/** | |
* Method to add Vehicle to the Inventory ArrayList. | |
* | |
* @param vehicle Vehicle to add to inventory | |
*/ | |
public void addVehicle(Vehicle vehicle) | |
{ | |
if(vehicle != null) | |
{ | |
getVehicles().add(vehicle); | |
} | |
} | |
/** | |
* Method to search for vehicles in inventory by model | |
* | |
* @param model Model of vehicle | |
*/ | |
public void searchByModel(String model) | |
{ | |
Iterator<Vehicle> it = vehicles.iterator(); | |
ArrayList<Vehicle> results = new ArrayList<>(); | |
while(it.hasNext()) | |
{ | |
Vehicle v = it.next(); | |
if(v.getModel().equals(model)) | |
{ | |
results.add(v); | |
} | |
} | |
if(results.size() > 0) | |
{ | |
displaySearchResults(results); | |
} | |
else | |
{ | |
System.out.println("No vehicles match this criteria"); | |
} | |
} | |
/** | |
* Method to search for Vehicles in inventory by year | |
* | |
* @param year year of vehicle | |
*/ | |
public void searchByYear(int year) | |
{ | |
Iterator<Vehicle> it = vehicles.iterator(); | |
ArrayList<Vehicle> results = new ArrayList<>(); | |
while(it.hasNext()) | |
{ | |
Vehicle v = it.next(); | |
if(v.getYear() == year) | |
{ | |
results.add(v); | |
} | |
} | |
if(results.size() > 0) | |
{ | |
displaySearchResults(results); | |
} | |
else | |
{ | |
System.out.println("No vehicles match this criteria"); | |
} | |
} | |
/** | |
* Method to search for Vehicles in inventory by price | |
* | |
* @param minPrice Minimum price for vehicle | |
* @param maxPrice Maximum price for vehicle | |
*/ | |
public void searchByPrice(double minPrice, double maxPrice) | |
{ | |
Iterator<Vehicle> it = vehicles.iterator(); | |
ArrayList<Vehicle> results = new ArrayList<>(); | |
while(it.hasNext()) | |
{ | |
Vehicle v = it.next(); | |
if(v.getSellingPrice() >= minPrice && v.getSellingPrice() <= maxPrice) | |
{ | |
results.add(v); | |
} | |
} | |
if(results.size() > 0) | |
{ | |
displaySearchResults(results); | |
} | |
else | |
{ | |
System.out.println("No vehicles match this criteria"); | |
} | |
} | |
/** | |
* Method to display search results from one of the search methods | |
* | |
* @param results the results from the search method, all in an ArrayList | |
*/ | |
public void displaySearchResults(ArrayList<Vehicle> results) | |
{ | |
System.out.println("Search Results: \n"); | |
for(Vehicle v : results) | |
{ | |
v.printDetails(); | |
} | |
} | |
/** | |
* Method to remove Vehicle from inventory | |
* | |
* @param stockCode stock code for the vehicle you want to remove | |
*/ | |
public static void removeVehicle(String stockCode) | |
{ | |
Iterator<Vehicle> it = vehicles.iterator(); | |
while(it.hasNext()) | |
{ | |
Vehicle v = it.next(); | |
if(v.getStockCode().equals(stockCode)) | |
{ | |
it.remove(); | |
} | |
} | |
} | |
/** | |
* Accessor to return current inventory count | |
* | |
* @return inventory count for how many vehicles there currently are | |
*/ | |
public String inventoryCount() | |
{ | |
return "Current Vehicles in Inventory: " + getVehicles().size(); | |
} | |
/** | |
* Accessor to return current inventory value | |
* | |
* @return inventory value for how much the sum of the vehicles in inventory are worth | |
*/ | |
public String inventoryValue() | |
{ | |
int sum = 0; | |
for(Vehicle v : vehicles) | |
{ | |
sum += v.getSellingPrice(); | |
} | |
return "Total Vehicle Inventory Value: " + sum; | |
} | |
/** | |
* Method to display all vehicles currently in inventory | |
*/ | |
public void displayInventory() | |
{ | |
System.out.println("Inventory Details: \n"); | |
for(Vehicle v : vehicles) | |
{ | |
v.printDetails(); | |
} | |
} | |
} |
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
/** | |
* PurchaseDate class. A date has a year, month and day, all numbers. | |
* A date cannot be invalid, meaning that the year cannot be | |
* later than the current year and the day and month must fall | |
* within valid ranges. This class does not take into account | |
* months with varying numbers of days. | |
* | |
* @author Chad | |
* @version 1.0 | |
*/ | |
public class PurchaseDate | |
{ | |
// constants | |
public static final int CURRENT_YEAR = 2019; | |
public static final int JANUARY = 1; | |
public static final int DECEMBER = 12; | |
public static final int FIRST_DAY = 1; | |
public static final int LAST_DAY = 31; // possible problems here! | |
public static final int DOUBLE_DIGIT = 10; | |
// instance variables | |
private int year = CURRENT_YEAR; | |
private int month = JANUARY; | |
private int day = FIRST_DAY; | |
/** | |
* Constructor for objects of class Date. The constructor | |
* expects three integer parameters: year, month and day. | |
* If the year is not valid it defaults to the current year. | |
* If the month or the day is not valid it defaults to the first | |
* possible value for that field. | |
* | |
* @param theYear The year of the full date | |
* @param theMonth The month of the full date | |
* @param theDay the day of the full date | |
*/ | |
public PurchaseDate(int theYear, int theMonth, int theDay) | |
{ | |
setYear(theYear); | |
setMonth(theMonth); | |
setDay(theDay); | |
} | |
/** | |
* Get the day. | |
* | |
* @return the day as an int | |
*/ | |
public int getDay() | |
{ | |
return day; | |
} | |
/** | |
* Get the month. | |
* | |
* @return the month as an int | |
*/ | |
public int getMonth() | |
{ | |
return month; | |
} | |
/** | |
* Get the year. | |
* | |
* @return the year as an int | |
*/ | |
public int getYear() | |
{ | |
return year; | |
} | |
/** | |
* Sets the day to the value of the parameter if it is valid. | |
* | |
* @param newDay The new day as an int | |
*/ | |
public void setDay(int newDay) | |
{ | |
// day must be between FIRST_DAY and LAST_DAY inclusive | |
if(newDay >= FIRST_DAY && newDay <= LAST_DAY) | |
{ | |
day = newDay; | |
} | |
else | |
{ | |
System.out.println("Invalid day data entered"); | |
} | |
} | |
/** | |
* Sets the month to the value of the parameter if it is valid. | |
* | |
* @param newMonth the new month as an int | |
*/ | |
public void setMonth(int newMonth) | |
{ | |
// month must be between JANUARY and DECEMBER inclusive | |
if((newMonth >= JANUARY) && (newMonth <= DECEMBER)) | |
{ | |
month = newMonth; | |
} | |
else | |
{ | |
System.out.println("Invalid month data entered"); | |
} | |
} | |
/** | |
* Sets the year to the value of the parameter if it is valid. | |
* | |
* @param newYear the new year as an int | |
*/ | |
public void setYear(int newYear) | |
{ | |
if(newYear <= CURRENT_YEAR) | |
{ | |
year = newYear; | |
} | |
else | |
{ | |
System.out.println("Invalid year data entered"); | |
} | |
} | |
/** | |
* Tests one of the date numbers and returns it as a String, | |
* with leading zero padded if appropriate. | |
* | |
* @param date The digit to be padded | |
* @return a String for a month or day padded | |
*/ | |
private String getDateString(int date) | |
{ | |
// date is a number with a single digit so pad with zero | |
if(date < DOUBLE_DIGIT) | |
{ | |
return "0" + date; | |
} | |
else | |
{ | |
// no padding necessary | |
return "" + date; | |
} | |
} | |
/** | |
* Returns a date string | |
* | |
* @return the full date as a String in the format YYYY-MM-DD | |
*/ | |
public String getFullDate() | |
{ | |
// passes the month and day to helper method for formatting | |
return year + "-" + getDateString(month) + "-" + getDateString(day); | |
} | |
} |
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
/** | |
* @author Chad | |
* @version 1.0 | |
*/ | |
import java.text.DecimalFormat; | |
public class Vehicle | |
{ | |
private static final int CURRENT_YEAR = 2016; | |
private static final int OLDEST_YEAR = 1970; | |
private String stockCode = "SC"; | |
private String make = "MAKE"; | |
private String model = "MODEL"; | |
private int year = OLDEST_YEAR; | |
private double dealerCost; | |
private double sellingPrice; | |
private double profitMargin; | |
/** | |
* Default Constructor for Objects of class Vehicle. | |
*/ | |
public Vehicle() | |
{ | |
} | |
/** | |
* Constructor for Objects of class Vehicle. | |
* | |
* @param _stockCode to initialize stockCode field | |
* @param _make to initialize make field | |
* @param _model to initialize model field | |
* @param _year to initialize year field | |
*/ | |
public Vehicle(String _stockCode, String _make, String _model, int _year) | |
{ | |
setStockCode(_stockCode); | |
setMake(_make); | |
setModel(_model); | |
setYear(_year); | |
} | |
/** | |
* @return the vehicle stockCode as String | |
*/ | |
public String getStockCode() | |
{ | |
return stockCode; | |
} | |
/** | |
* @return the make as String | |
*/ | |
public String getMake() | |
{ | |
return make; | |
} | |
/** | |
* @return the model as String | |
*/ | |
public String getModel() | |
{ | |
return model; | |
} | |
/** | |
* @return the year as int | |
*/ | |
public int getYear() | |
{ | |
return year; | |
} | |
/** | |
* @return the dealerCost as double | |
*/ | |
public double getDealerCost() | |
{ | |
return dealerCost; | |
} | |
/** | |
* @return the sellingPrice as double | |
*/ | |
public double getSellingPrice() | |
{ | |
return sellingPrice; | |
} | |
/** | |
* @return the profit margin on the vehicle if sold, as double | |
*/ | |
public double getProfitMargin() | |
{ | |
return profitMargin; | |
} | |
/** | |
* @param _stockCode sets the value for the stockCode field. | |
*/ | |
public void setStockCode(String _stockCode) | |
{ | |
stockCode = _stockCode; | |
} | |
/** | |
* @param _make sets the value for the make field. | |
*/ | |
public void setMake(String _make) | |
{ | |
make = _make; | |
} | |
/** | |
* @param _model sets the value for the model field. | |
*/ | |
public void setModel(String _model) | |
{ | |
model = _model; | |
} | |
/** | |
* @param _year sets the value for the year field | |
*/ | |
public void setYear(int _year) | |
{ | |
if(_year >= OLDEST_YEAR && _year <= CURRENT_YEAR) | |
{ | |
year = _year; | |
} | |
else | |
{ | |
System.out.println("Invalid year input."); | |
} | |
} | |
/** | |
* @param _dealerCost sets the value for the dealerCost field | |
*/ | |
public void setDealerCost(double _dealerCost) | |
{ | |
if(_dealerCost >= 0) | |
{ | |
dealerCost = _dealerCost; | |
} | |
else | |
{ | |
System.out.println("Invalid dealer cost input."); | |
} | |
} | |
/** | |
* @param _sellingPrice sets the sellingPrice only if it is at least 25% than dealerCost | |
*/ | |
public void checkStandardSellingPrice(double _sellingPrice) | |
{ | |
if(_sellingPrice >= (dealerCost * 1.25)) | |
{ | |
sellingPrice = _sellingPrice; | |
} | |
else | |
{ | |
System.out.println("The dealer cost is: $" + dealerCost + ". Sale price $" + _sellingPrice + " is not high enough."); | |
} | |
} | |
/** | |
* @param _sellingPrice sets the value for the sellingPrice field | |
*/ | |
public void setSellingPrice(double _sellingPrice) | |
{ | |
if(_sellingPrice >= 0) | |
{ | |
sellingPrice = _sellingPrice; | |
} | |
else | |
{ | |
System.out.println("Invalid selling price input."); | |
} | |
} | |
/** | |
* Calculates the profit margin for selling a vehicle | |
*/ | |
public void calculateProfitMargin() | |
{ | |
profitMargin = (sellingPrice - dealerCost) / sellingPrice; | |
} | |
/** | |
* @return the profit on selling a vehicle as a dollar value. | |
*/ | |
public double calculateProfit() | |
{ | |
return sellingPrice - dealerCost; | |
} | |
/** | |
* Formats and displays all vehicle information. | |
*/ | |
public void printDetails() | |
{ | |
DecimalFormat formatter = new DecimalFormat("$0.00"); | |
DecimalFormat percentFormatter = new DecimalFormat("0%"); | |
System.out.println("Jalopies Are Us Vehicle Summary: "); | |
System.out.println("Vehicle: " + year + " " + make + " " + model); | |
System.out.println("Stock Code:" + stockCode); | |
System.out.println("Dealer Cost: " + formatter.format(dealerCost)); | |
System.out.println("Selling Price: " + formatter.format(sellingPrice)); | |
System.out.println("Profit Margin: " + percentFormatter.format(profitMargin)); | |
System.out.println("Dollar Profit: " + formatter.format(calculateProfit())); | |
} | |
} |
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
/** | |
* Information Object for a musical instrument rental. | |
* | |
* @author Chad | |
* @version this one | |
*/ | |
public class VehiclePurchase | |
{ | |
public static final double SERVICE_FEE = 500.00; | |
private Customer customer; | |
private PurchaseDate purchaseDate; | |
private Vehicle vehiclePurchased; | |
private boolean servicePackage; | |
/** | |
* @param renter The customer who purchased the vehicle | |
* @param purchaseDate The date the Vehicle was purchased | |
* @param vehiclePurchased The Vehicle that was purchased | |
* @param servicePackage Whether or not the customer opted for the service package. | |
*/ | |
public VehiclePurchase(Customer renter, PurchaseDate purchaseDate, Vehicle vehiclePurchased, boolean servicePackage) | |
{ | |
this.customer = renter; | |
this.purchaseDate = purchaseDate; | |
this.vehiclePurchased = vehiclePurchased; | |
this.servicePackage = servicePackage; | |
} | |
/** | |
* @return the customer | |
*/ | |
public Customer getCustomer() | |
{ | |
return customer; | |
} | |
/** | |
* @return the purchaseDate | |
*/ | |
public PurchaseDate getPurchaseDate() | |
{ | |
return purchaseDate; | |
} | |
/** | |
* @return the vehiclePurchased | |
*/ | |
public Vehicle getVehiclePurchased() | |
{ | |
return vehiclePurchased; | |
} | |
/** | |
* @return the servicePackage | |
*/ | |
public boolean isServicePackage() | |
{ | |
return servicePackage; | |
} | |
/** | |
* @param servicePackage the servicePackage to set | |
*/ | |
public void setServicePackage(boolean servicePackage) | |
{ | |
this.servicePackage = servicePackage; | |
} | |
/** | |
* @param purchasePrice the purchasePrice to set | |
*/ | |
public void calculatePurchasePrice(double purchasePrice) | |
{ | |
vehiclePurchased.checkStandardSellingPrice(purchasePrice); | |
if(servicePackage) | |
{ | |
vehiclePurchased.setSellingPrice(vehiclePurchased.getSellingPrice() + SERVICE_FEE); | |
} | |
} | |
/** | |
* Display the purchase agreement information | |
* | |
* assumes the vehicle sale has become final, removes vehicle from inventory. | |
*/ | |
public void displayDetails() | |
{ | |
System.out.println("Customer: " + customer.getFullName()); | |
System.out.println("Purchase Date: " + purchaseDate.getFullDate()); | |
System.out.print("Vehicle Description: "); | |
vehiclePurchased.printDetails(); | |
if(servicePackage) | |
{ | |
System.out.println("SERVICE PACKAGE INCLUDED"); | |
} | |
Inventory.removeVehicle(vehiclePurchased.getStockCode()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment