Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SWEN30006-project1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Isobel Byars
SWEN30006-project1
Commits
e579d06b
Commit
e579d06b
authored
Apr 19, 2021
by
Isobel
Browse files
Options
Downloads
Patches
Plain Diff
eleen's changes
parent
5ae20ac5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ChargeCalculator.java
+59
-3
59 additions, 3 deletions
ChargeCalculator.java
MailItem.java
+41
-38
41 additions, 38 deletions
MailItem.java
Robot.java
+4
-1
4 additions, 1 deletion
Robot.java
Simulation.java
+11
-22
11 additions, 22 deletions
Simulation.java
with
115 additions
and
64 deletions
ChargeCalculator.java
+
59
−
3
View file @
e579d06b
...
@@ -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
* */
* */
p
rivate
double
calculateActivityCost
(
MailItem
item
)
{
p
ublic
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
()
{
}
}
}
}
This diff is collapsed.
Click to expand it.
MailItem.java
+
41
−
38
View file @
e579d06b
...
@@ -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
_f
ee
;
private
double
service
F
ee
;
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
_f
ee
=
0
;
this
.
service
F
ee
=
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
get
Cost
()
{
public
double
get
ServiceFee
()
{
return
service
_fee
+
activity_cost
;
return
service
Fee
;
}
}
// 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
>();
...
...
This diff is collapsed.
Click to expand it.
Robot.java
+
4
−
1
View file @
e579d06b
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Simulation.java
+
11
−
22
View file @
e579d06b
...
@@ -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]"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment