Skip to content
Snippets Groups Projects
Commit e579d06b authored by Isobel's avatar Isobel
Browse files

eleen's changes

parent 5ae20ac5
Branches
No related tags found
No related merge requests found
...@@ -7,10 +7,28 @@ public class ChargeCalculator { ...@@ -7,10 +7,28 @@ public class ChargeCalculator {
private double markup; private double markup;
private double unitPrice; private double unitPrice;
private int totalItems;
private double billableActivity;
private double totalServiceCost;
private int[] numLookups;
// constant variables for numLookups to increment successes at index 0 and failures at index 1
private final int success_index = 0;
private final int failure_index = 1;
public ChargeCalculator(int numFloors, double markup, double unitPrice) { public ChargeCalculator(int numFloors, double markup, double unitPrice) {
this.markup = markup; this.markup = markup;
this.unitPrice = unitPrice; this.unitPrice = unitPrice;
// initialise statistics to 0
this.totalItems = 0;
this.billableActivity = 0.0;
this.totalServiceCost = 0;
this.numLookups = new int[2];
this.numLookups[success_index] = 0;
this.numLookups[failure_index] = 0;
// initialise service fees to 0 for all floors // initialise service fees to 0 for all floors
for(int i = 1; i < numFloors + 1; i++) { for(int i = 1; i < numFloors + 1; i++) {
lastServiceFee.put(i, 0.0); lastServiceFee.put(i, 0.0);
...@@ -23,7 +41,7 @@ public class ChargeCalculator { ...@@ -23,7 +41,7 @@ public class ChargeCalculator {
* May be altered to factor in weight or delays in the future * May be altered to factor in weight or delays in the future
* @param item the mail item whos activity cost is calculated * @param item the mail item whos activity cost is calculated
* */ * */
private double calculateActivityCost(MailItem item) { public double calculateActivityCost(MailItem item) {
return item.getActivityUnits() * unitPrice; return item.getActivityUnits() * unitPrice;
} }
...@@ -38,9 +56,47 @@ public class ChargeCalculator { ...@@ -38,9 +56,47 @@ public class ChargeCalculator {
} }
/** /**
* TODO * Returns the cost for an item
* @param item The item whos cost is calculated
* */ * */
public double calculateCost(MailItem item) { public double calculateCost(MailItem item) {
return 0.0; return calculateActivityCost(item) + item.getServiceFee();
}
public double getCharge(MailItem item) {
return calculateCost(item) * (1 + markup);
}
/**
* Update the last calculated service fee
* @param floor the floor for which a new service fee has been looked up
* @param fee the new service fee
* */
public void updateServiceFee(int floor, double fee) {
if (fee > 0) {
lastServiceFee.replace(floor, fee);
}
}
/**
* Update numLookups with an additional successful or failed lookup
* @param success True if the lookup was successful, False if failed
* */
public void incrementLookup(Boolean success) {
if (success) {
numLookups[success_index] += 1;
}
else {
numLookups[failure_index] += 1;
}
}
/**
* TODO
* */
public void updateStatistics() {
} }
} }
...@@ -22,19 +22,17 @@ public class MailItem { ...@@ -22,19 +22,17 @@ public class MailItem {
/*Mail item now tracks several variables associated with charge*/ /*Mail item now tracks several variables associated with charge*/
/** The number of activity units associated with delivering this mail item*/ /** The number of activity units associated with delivering this mail item*/
private double activity_units; private double activity_units;
private double cost;
/** The service fee looked up at time of delivery*/ /** The service fee looked up at time of delivery*/
private double service_fee; private double serviceFee;
private Boolean lookupSuccessful; private Boolean lookupSuccessful;
/** The portion of cost associated with activity units*/
private double activity_cost;
/** The total charge for delivering the item*/
private double charge;
// TODO - review /** MailItem tracks its mailPool to output charge info*/
private MailPool mailPool; private MailPool mailPool;
// private static ChargeCalculator chargeCalculator = new ChargeCalculator(); /** Charge calculator helper class to calculate the charge of each item at delivery */
public static ChargeCalculator chargeCalculator;
/** /**
...@@ -53,41 +51,25 @@ public class MailItem { ...@@ -53,41 +51,25 @@ public class MailItem {
/*Initialise activity units and costs to zero*/ /*Initialise activity units and costs to zero*/
this.activity_units = 0; this.activity_units = 0;
this.service_fee = 0; this.serviceFee = 0;
this.lookupSuccessful = false; this.lookupSuccessful = false;
this.activity_cost = 0;
this.charge = 0;
this.mailPool = mailPool; this.mailPool = mailPool;
} }
// TODO - configure charge calculator
public static void setUnitPrice() {
return;
}
/** /**
* Return a string representation of MailItem. Print charge information if charge threshold is set, otherwise preserve * Configure charge calculator class with data from simulation
* original output. * @param numFloors the number of floors in the building
* @param markup the markup percentage
* @param unitPrice the price per activity unit
* */ * */
@Override public static void configureChargeCalculator(int numFloors, double markup, double unitPrice) {
public String toString(){ chargeCalculator = new ChargeCalculator(numFloors, markup, unitPrice);
double charge_threshold = mailPool.getChargeThreshold();
if (charge_threshold == 0) {
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d", id, arrival_time,
destination_floor, weight);
}
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d | Charge: %.2f | Cost: %.2f | Fee: %.2f | Activity: %.2f",
id, arrival_time, destination_floor, weight, charge, getCost(), service_fee, activity_cost);
} }
/** @Override
* Modified version of the toString() method that includes information related to the charge public String toString(){
* THIS METHOD SHOULD NOT BE CALLED IN THE FINAL VERSION return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d", id, arrival_time, destination_floor, weight);
*/
public String toStringWithCharge(){
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d | Charge: %.2f | Cost: %.2f | Fee: %.2f | Activity: %.2f",
id, arrival_time, destination_floor, weight, charge, getCost(), service_fee, activity_cost);
} }
/** /**
...@@ -138,13 +120,23 @@ public class MailItem { ...@@ -138,13 +120,23 @@ public class MailItem {
return activity_units; return activity_units;
} }
public double getCost() { public double getServiceFee() {
return service_fee + activity_cost; return serviceFee;
} }
// TODO - validate fee and update success
// Validate fee and update success
public void setServiceFee(double fee) { public void setServiceFee(double fee) {
this.service_fee = fee; if (fee > 0) {
serviceFee = fee;
lookupSuccessful = true;
MailItem.chargeCalculator.incrementLookup(true);
MailItem.chargeCalculator.updateServiceFee(destination_floor, fee);
}
else {
lookupSuccessful = false;
MailItem.chargeCalculator.incrementLookup(false);
}
} }
// TODO - update statistics // TODO - update statistics
...@@ -152,6 +144,17 @@ public class MailItem { ...@@ -152,6 +144,17 @@ public class MailItem {
} }
/**
* TODO - Modified version of the toString() method that includes information related to the charge
*
*/
public String toStringWithCharge(){
return String.format("Mail Item:: ID: %6s | Arrival: %4d | Destination: %2d | Weight: %4d | Charge: %.2f | Cost: %.2f | Fee: %.2f | Activity: %.2f",
id, arrival_time, destination_floor, weight, MailItem.chargeCalculator.calculateActivityCost(this),
MailItem.chargeCalculator.calculateCost(this), serviceFee, activity_units);
}
static private int count = 0; static private int count = 0;
static private Map<Integer, Integer> hashMap = new TreeMap<Integer, Integer>(); static private Map<Integer, Integer> hashMap = new TreeMap<Integer, Integer>();
......
...@@ -101,8 +101,11 @@ public class Robot { ...@@ -101,8 +101,11 @@ public class Robot {
/* set item service fee */ /* set item service fee */
deliveryItem.setServiceFee(delivery.getServiceFee(current_floor)); deliveryItem.setServiceFee(delivery.getServiceFee(current_floor));
// TODO - deliveryItem calls charge calculator // deliveryItem calls charge calculator
MailItem.chargeCalculator.getCharge(deliveryItem);
// TODO - deliveryItem increment stats in charge calculator deliveryItem.updateStats() // TODO - deliveryItem increment stats in charge calculator deliveryItem.updateStats()
MailItem.chargeCalculator.updateStatistics();
/** Delivery complete, report this to the simulator! */ /** Delivery complete, report this to the simulator! */
delivery.deliver(deliveryItem); delivery.deliver(deliveryItem);
......
...@@ -23,6 +23,8 @@ public class Simulation { ...@@ -23,6 +23,8 @@ public class Simulation {
private static int NUM_ROBOTS; private static int NUM_ROBOTS;
private static double CHARGE_THRESHOLD; private static double CHARGE_THRESHOLD;
private static boolean CHARGE_DISPLAY; private static boolean CHARGE_DISPLAY;
private static double UNIT_PRICE;
private static double MARKUP_PERCENTAGE;
/** Constant for the mail generator */ /** Constant for the mail generator */
private static int MAIL_TO_CREATE; private static int MAIL_TO_CREATE;
...@@ -77,8 +79,8 @@ public class Simulation { ...@@ -77,8 +79,8 @@ public class Simulation {
Automail automail = new Automail(mailPool, new ReportDelivery(), NUM_ROBOTS); Automail automail = new Automail(mailPool, new ReportDelivery(), NUM_ROBOTS);
MailGenerator mailGenerator = new MailGenerator(MAIL_TO_CREATE, MAIL_MAX_WEIGHT, mailPool, seedMap); MailGenerator mailGenerator = new MailGenerator(MAIL_TO_CREATE, MAIL_MAX_WEIGHT, mailPool, seedMap);
// TODO - something /* Configure MailItem's static charge calculator object */
MailItem.setUnitPrice(); MailItem.configureChargeCalculator(Building.FLOORS, MARKUP_PERCENTAGE, UNIT_PRICE);
/** Generate all the mails */ /** Generate all the mails */
mailGenerator.generateAllMail(); mailGenerator.generateAllMail();
...@@ -110,6 +112,8 @@ public class Simulation { ...@@ -110,6 +112,8 @@ public class Simulation {
automailProperties.setProperty("Mail_to_Create", "80"); automailProperties.setProperty("Mail_to_Create", "80");
automailProperties.setProperty("ChargeThreshold", "0"); automailProperties.setProperty("ChargeThreshold", "0");
automailProperties.setProperty("ChargeDisplay", "false"); automailProperties.setProperty("ChargeDisplay", "false");
automailProperties.setProperty("UnitPrice", "5.0");
automailProperties.setProperty("MarkupPercentage", "0.059");
// Read properties // Read properties
FileReader inStream = null; FileReader inStream = null;
...@@ -144,7 +148,11 @@ public class Simulation { ...@@ -144,7 +148,11 @@ public class Simulation {
// Charge Display // Charge Display
CHARGE_DISPLAY = Boolean.parseBoolean(automailProperties.getProperty("ChargeDisplay")); CHARGE_DISPLAY = Boolean.parseBoolean(automailProperties.getProperty("ChargeDisplay"));
System.out.println("#Charge Display: " + CHARGE_DISPLAY); System.out.println("#Charge Display: " + CHARGE_DISPLAY);
// TODO - add unit price UNIT_PRICE = Double.parseDouble(automailProperties.getProperty("UnitPrice"));
System.out.println("#Unit Price: " + UNIT_PRICE);
MARKUP_PERCENTAGE = Double.parseDouble(automailProperties.getProperty("MarkupPercentage"));
System.out.println("#Markup Percentage: " + MARKUP_PERCENTAGE);
return automailProperties; return automailProperties;
} }
...@@ -154,10 +162,6 @@ public class Simulation { ...@@ -154,10 +162,6 @@ public class Simulation {
/** Confirm the delivery and calculate the total score */ /** Confirm the delivery and calculate the total score */
public void deliver(MailItem deliveryItem){ public void deliver(MailItem deliveryItem){
if(!MAIL_DELIVERED.contains(deliveryItem)){ if(!MAIL_DELIVERED.contains(deliveryItem)){
// mail item calls charge calculator deliveryItem.getCost()
// getCost () { mailPool.
MAIL_DELIVERED.add(deliveryItem); MAIL_DELIVERED.add(deliveryItem);
System.out.printf("T: %3d > Delivered(%4d) [%s]%n", Clock.Time(), MAIL_DELIVERED.size(), deliveryItem.toString()); System.out.printf("T: %3d > Delivered(%4d) [%s]%n", Clock.Time(), MAIL_DELIVERED.size(), deliveryItem.toString());
...@@ -201,20 +205,5 @@ public class Simulation { ...@@ -201,20 +205,5 @@ public class Simulation {
System.out.println("T: "+Clock.Time()+" | Simulation complete!"); System.out.println("T: "+Clock.Time()+" | Simulation complete!");
System.out.println("Final Delivery time: "+Clock.Time()); System.out.println("Final Delivery time: "+Clock.Time());
System.out.printf("Delay: %.2f%n", total_delay); System.out.printf("Delay: %.2f%n", total_delay);
// Print statistics if chargeDisplay is toggled on
if (CHARGE_DISPLAY) {
printStatistics();
}
}
/**
* Print statistics - to be called at the end of the mail run if chargeDisplay is toggled on.
*/
public static void printStatistics() {
System.out.println("Number of items delivered: ");
System.out.println("Total billable activity: ");
System.out.println("Total activity cost: ");
System.out.println("Total service cost: ");
System.out.println("Number of lookups: XXX [XXX failed, XXX successful]" );
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment