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

original code

parent e579d06b
No related branches found
No related tags found
No related merge requests found
Showing
with 57 additions and 102 deletions
package automail;
import java.util.Map;
public class ChargeCalculator {
private static Map<Integer, Double> lastServiceFee;
private double markup;
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) {
this.markup = markup;
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
for(int i = 1; i < numFloors + 1; i++) {
lastServiceFee.put(i, 0.0);
}
}
/**
* Calculates the activity cost for the parameter item
* Activity cost = activity units * unit price
* May be altered to factor in weight or delays in the future
* @param item the mail item whos activity cost is calculated
* */
public double calculateActivityCost(MailItem item) {
return item.getActivityUnits() * unitPrice;
}
/**
* Returns the expected cost for an item using the last calculated service fee
* @param item The item whos expected cost is calculated
* */
public double calculateExpectedCost(MailItem item) {
double cost = calculateActivityCost(item) + lastServiceFee.get(item.getDestFloor());
return cost * (1 + markup);
}
/**
* Returns the cost for an item
* @param item The item whos cost is calculated
* */
public double calculateCost(MailItem item) {
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() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="WifiModem.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Automail</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
File added
# Seed
#Seed=2020
Seed=30006
# Floors
Floors=12
# Mail_To_Create
Mail_to_Create=200
# Mail_Max_Weight
Mail_Max_Weight=2000
# The duration of receiving new mails
Mail_Receving_Length=120
# Robots
Robots=3
ChargeThreshold=0
CommercialDisplay=false
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment