Initial Commit
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The customer class holds the name and car and methods relating to costs and last time visited
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
|
||||
public class Customer {
|
||||
/**
|
||||
* (String) customer name
|
||||
*/
|
||||
private final String customer;
|
||||
/**
|
||||
* (String) car name
|
||||
*/
|
||||
private final String car;
|
||||
/**
|
||||
* (long) The time in months since the last time the customer has visited
|
||||
*/
|
||||
private long monthsSinceVisit = 0;
|
||||
|
||||
/**
|
||||
* Currency formatter
|
||||
*/
|
||||
NumberFormat cf = NumberFormat.getCurrencyInstance(Locale.CANADA);
|
||||
|
||||
/**
|
||||
* The constructor for the customer class, stores the customers name and car model
|
||||
* @param customer The customers name
|
||||
* @param car The customers car model
|
||||
*/
|
||||
Customer(String customer, String car) {
|
||||
this.customer = customer;
|
||||
this.car = car;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the months since the last time the customer has visited
|
||||
*/
|
||||
void incMonthsSinceVisit() {
|
||||
monthsSinceVisit++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the months since the last time the customers has visited
|
||||
* @return The months since the last time the customer has visited
|
||||
*/
|
||||
long getMonthsSinceVisit() {
|
||||
return monthsSinceVisit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The cost of the next visit
|
||||
* @return The cost of the next visit in double format
|
||||
*/
|
||||
double getNextVisitCost() {
|
||||
return (20.00 + (monthsSinceVisit*12.00));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an invoice containing the customers name, car model, last time the visited and the cost of the visit
|
||||
* @return A string containing the customers name, car model, last time the visited and the cost of the visit
|
||||
*/
|
||||
String createVisitInvoice() {
|
||||
double cost = getNextVisitCost();
|
||||
long lastVisit = getMonthsSinceVisit();
|
||||
monthsSinceVisit = 0;
|
||||
return (
|
||||
"INVOICE\tfor: " + customer + "\n" +
|
||||
"\t\tmodel: " + car + "\n" +
|
||||
"\t\tlast visit: " + lastVisit + "\n" +
|
||||
"\t\tnext visit cost: " + cf.format(cost));
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/**
|
||||
A driver class demonstrating the classes available in
|
||||
for HarrisonFord customer management.
|
||||
|
||||
@author Scott Bateman
|
||||
*/
|
||||
|
||||
public class HarrisonFord{
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
//creating test customers John, Harold and Beth
|
||||
|
||||
//create one customer
|
||||
Customer john = new Customer("John Smith","Escape");
|
||||
|
||||
//create two warranty customers
|
||||
WarrantyCustomer harold = new WarrantyCustomer("Harold Lee", "Fiesta");
|
||||
WarrantyCustomer beth = new WarrantyCustomer("Beth Blart", "Focus");
|
||||
|
||||
//Displaying pretty text banner
|
||||
System.out.println();
|
||||
System.out.println("*********************************");
|
||||
System.out.println("* HARRISON FORD CUSTOMER SYSTEM *");
|
||||
System.out.println("*********************************");
|
||||
|
||||
//increment months since visit for each customer
|
||||
|
||||
//it's been 1 month since john bought his car
|
||||
john.incMonthsSinceVisit();
|
||||
|
||||
//it's been 3 months since harold bought his car
|
||||
harold.incMonthsSinceVisit();
|
||||
harold.incMonthsSinceVisit();
|
||||
harold.incMonthsSinceVisit();
|
||||
|
||||
//it's been 4 months since beth bought her car
|
||||
beth.incMonthsSinceVisit();
|
||||
beth.incMonthsSinceVisit();
|
||||
beth.incMonthsSinceVisit();
|
||||
beth.incMonthsSinceVisit();
|
||||
|
||||
//display report for Nov 1, 2019
|
||||
System.out.println("November 1, 2019\n----------------");
|
||||
System.out.println(john.createVisitInvoice());
|
||||
System.out.println();
|
||||
System.out.println(harold.createVisitInvoice());
|
||||
System.out.println();
|
||||
System.out.println(beth.createVisitInvoice());
|
||||
System.out.println();
|
||||
|
||||
//using a loop to simulate the passage of a year
|
||||
int i = 0;
|
||||
while (i < 12)
|
||||
{
|
||||
//john and beth to not visit in the year
|
||||
john.incMonthsSinceVisit();
|
||||
beth.incMonthsSinceVisit();
|
||||
|
||||
//harold really wants to keep his car in
|
||||
//good shape - he visits every month
|
||||
harold.incMonthsSinceVisit();
|
||||
|
||||
//creating a visit for monthly visits
|
||||
//for Harold, but not displaying them
|
||||
harold.createVisitInvoice();
|
||||
i++;
|
||||
}
|
||||
|
||||
//creating invoices for all customers
|
||||
System.out.println("November 1, 2020\n----------------");
|
||||
System.out.println(john.createVisitInvoice());
|
||||
System.out.println();
|
||||
System.out.println(harold.createVisitInvoice());
|
||||
System.out.println();
|
||||
System.out.println(beth.createVisitInvoice());
|
||||
System.out.println();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
|
||||
*********************************
|
||||
* HARRISON FORD CUSTOMER SYSTEM *
|
||||
*********************************
|
||||
November 1, 2019
|
||||
----------------
|
||||
INVOICE for: John Smith
|
||||
model: Escape
|
||||
last visit: 1
|
||||
next visit cost: $32.00
|
||||
|
||||
INVOICE for: Harold Lee
|
||||
model: Fiesta
|
||||
last visit: 3
|
||||
next visit cost: $56.00
|
||||
months since discount: 3 (has warranty)
|
||||
|
||||
INVOICE for: Beth Blart
|
||||
model: Focus
|
||||
last visit: 4
|
||||
next visit cost: $68.00
|
||||
months since discount: 4 (has warranty)
|
||||
|
||||
November 1, 2020
|
||||
----------------
|
||||
INVOICE for: John Smith
|
||||
model: Escape
|
||||
last visit: 12
|
||||
next visit cost: $164.00
|
||||
|
||||
INVOICE for: Harold Lee
|
||||
model: Fiesta
|
||||
last visit: 0
|
||||
next visit cost: $20.00
|
||||
months since discount: 3 (has warranty)
|
||||
|
||||
INVOICE for: Beth Blart
|
||||
model: Focus
|
||||
last visit: 12
|
||||
next visit cost: $131.20
|
||||
months since discount: 16 (has warranty)
|
||||
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* This class contains a customer that has a warranty. It contains the customers name, car model and overridden methods pertaining to that the customer is a warranty owner
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
|
||||
public class WarrantyCustomer extends Customer {
|
||||
/**
|
||||
* (long) The time since the last discount for being a warrenty owned was applied
|
||||
*/
|
||||
private long monthsSinceLastDiscount = 0;
|
||||
|
||||
/**
|
||||
* Warranty customer constructor, it stores the customers name and car model
|
||||
* @param customer The customers name
|
||||
* @param car The customers car model
|
||||
*/
|
||||
WarrantyCustomer(String customer, String car) {
|
||||
super(customer, car);
|
||||
}
|
||||
|
||||
/**
|
||||
* The overridden method that applies a discount if the user has not used their discount in 12 months
|
||||
* @return The cost of the visit
|
||||
*/
|
||||
@Override
|
||||
double getNextVisitCost() {
|
||||
if (monthsSinceLastDiscount >= 12) {
|
||||
monthsSinceLastDiscount = 0;
|
||||
return (0.8 * super.getNextVisitCost());
|
||||
}
|
||||
return super.getNextVisitCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method specific to the warranty owners, increases the months since last discount as well as months since last visit
|
||||
*/
|
||||
@Override
|
||||
void incMonthsSinceVisit() {
|
||||
super.incMonthsSinceVisit();
|
||||
monthsSinceLastDiscount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an invoice for warranty owners, includes the months since the last time the discount was applies
|
||||
* @return The customers invoice, includes the last time the warranty discount was applied
|
||||
*/
|
||||
@Override
|
||||
String createVisitInvoice() {
|
||||
long tempMonthsSinceLastDiscount = monthsSinceLastDiscount;
|
||||
return(
|
||||
super.createVisitInvoice() +
|
||||
"\n\t\tmonths since discount: " + tempMonthsSinceLastDiscount + "\t(has warranty)"
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user