[Solved] CS2030 Lab 3 # Cruise Loaders

$25

File Name: CS2030_Lab_3___Cruise_Loaders.zip
File Size: 273.18 KB

SKU: [Solved] CS2030 Lab 3 # –Cruise Loaders Category: Tag:
5/5 - (1 vote)

Task Content

Cruise Loaders Topic CoverageInheritancePolymorphismMethod Overriding CS2030 Java Style GuideProblem DescriptionThe Kent Ridge Cruise Centre has just opened and you are required to design a program to decide how many loaders to buy based on a single-day cruise schedule.CruisesEach cruise has four attributes:a unique string identifier, e.g. S1234a time of arrival in HHMM format, e.g. 2359 denoting the cruise arriving at 11:59PM on that day the time needed to serve the cruise (in minutes), and the number of loaders needed to serve the cruise.Every cruise must be served by loaders immediately upon arrival.There are two types of cruises:SmallCruise:has an identifier that starts with an uppercase character S; takes a fixed 30 minutes for a loader to fully load; requires only one loader for it to be fully served; BigCruise:has an identifier that starts with an uppercase character B;takes one minute to serve every 50 passengers; requires one loader per every 40 meters in length of the cruise (or part thereof) to fully loadLoadersLoaders have to be purchased to serve cruises. Each loader comprises two attributes:a unique integer identifierthe cruise that it is currently serving
class Cruise {private final String identifier; private final int arrivalTime; private final int numOfLoader; private final int serviceTime; }

A loader will serve a cruise as soon as it arrives, and continues to do so until the service time has elapsed (i.e. it cannot serve a cruise while in the midst of serving another one).

For example, if an incoming cruise arrives at 12PM, requires two loaders, and 60 min for it to be fully served, then, at 12PM, there must be two vacant loaders. These two loaders will serve the cruise from 12PM 1PM. They can only serve another cruise from 1PM onwards.

Task

Your task is to determine the loader allocation schedule using the following steps:

For each cruise, check through the inventory of existing loaders, starting from the loader first purchased, and so on;

The first (or first few) loaders available will be used to serve the cruise;

If there are not enough loaders, purchase new one(s) to serve the cruise.

Take note of the following assumptions:

Input cruises are presented chronologically by arrival time.

There are no duplicate cruises.

All cruises will arrive and be completely served within a single day.

Although this problem can be implemented procedurally, you are to model your solution using an object-oriented approach instead.

This task is divided into several levels. You need to complete ALL levels.

Level 1

Represent a Cruise

Design an immutable Cruise class to represent a cruise having a unique identifier string, the time of arrival as an integer, the number of loaders required to load the cruise as an integer, and the service time in minutes as an integer.

Note that the time of arrival is in HHMM format. Specifically, 0 or 0000 refers to 00:00 (12AM), 30 or 0030 refers to 00:30 (12:30AM), and 130 or 0130 refers to 01:30 (1:30AM).

Implement a getServiceCompletionTime method, which returns the time the service completes (in number of minutes) since midnight, and a getArrivalTime method, which returns the arrival time (in number of minutes) since midnight.

For example, if the cruise arrives at 12PM (noon time), the arrival time is (12 * 60) = 720; the service completion time is 12:30PM, which is 750 minutes since midnight, i.e. (12 * 60) + 30 = 750.

In addition, implement a getNumOfLoadersRequired method, which returns the number of loaders required to load the cruise.

Tip: the %0Xd format specifier might be of use to you, where the integer will be represented by an X-digit zero-padded number. For instance,

String.format(%04d, 20);

would return the string 0020.

$ javac your_java_files

$ jshell your_java_files_in_bottom-up_dependency_order

jshell> new Cruise(A1234, 0, 2, 30)

$.. ==> [email protected]

jshell> new Cruise(A2345, 30, 2, 30)

$.. ==> [email protected]

jshell> new Cruise(A3456, 130, 2, 30)

$.. ==> [email protected]

jshell> new Cruise(A3456, 130, 2, 30).getArrivalTime() $.. ==> 90

jshell> new Cruise(A3456, 130, 2, 30).getNumOfLoadersRequired()$.. ==> 2jshell> new Cruise(A3456, 130, 5, 30).getNumOfLoadersRequired()$.. ==> 5jshell> new Cruise(A1234, 0, 2, 30).getServiceCompletionTime()$.. ==> 30jshell> new Cruise(A1234, 0, 2, 45).getServiceCompletionTime()$.. ==> 45jshell> new Cruise(CS2030, 1200, 2, 100).getServiceCompletionTime()$.. ==> 820jshell> new Cruise(D1010, 2329, 2, 30).getServiceCompletionTime()$.. ==> 1439 jshell> /exit
class Loader {private final int identifier; private final Cruise cruise; }
$ javac your_java_files$ jshell your_java_files_in_bottom-up_dependency_order jshell> new Loader(1, new Cruise(A1234, 0, 1, 30))$.. ==> Loader 1 serving [email protected]jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).getIdentifier()$.. ==> 1jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).getNextAvailableTime()$.. ==> 30jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).canServe(new Cruise(A2345, 30, 1, 30))$.. ==> truejshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).serve(new Cruise(A2345, 30, 1, 30))$.. ==> Loader 1 serving [email protected]jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).serve(new Cruise(A2345, 30, 1, 30)).getNex$.. ==> 60jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).canServe(new Cruise(A2345, 10, 1, 30))$.. ==> falsejshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).serve(new Cruise(A2345, 10, 1, 30))$.. ==> Loader 1 serving [email protected]jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).serve(new Cruise(A2345, 10, 1, 30)).getNex$.. ==> 30jshell> new Loader(1, new Cruise(A1234, 0, 1, 30)).serve(new Cruise(A2345, 10, 1, 30)).getIde$.. ==> 1 jshell> /exit

Level 2

Use Loaders to serve Cruises

Design an immutable Loader class to serve a cruise.

Include the following in the Loader class:

a constructor that takes in an integer denoting its unique identifier, as well as the first cruise that it serves. a canServe(Cruise) method that returns true if the loader is available to serve the given cruise, or false otherwise.

a serve(Cruise) method to serve a given cruise. If the loader is available, the method returns the loader serving this cruise; otherwise the existing loader is returned the methods getIdentifier() and getNextAvailableTime() to return the loaders identifier, and the next available time for service.

Level 3

Represent Small Cruises

Design the SmallCruise class. The arguments of the constructor are its identifier, and time of arrival. Note that you should not need to change your Loader class if you have implemented it properly.

$ javac your_java_files

$ javac your_java_files$ jshell your_java_files_in_bottom-up_dependency_order jshell> Cruise b = new BigCruise(B0001, 0, 70, 3000)jshell> b.getArrivalTime()$.. ==> 0jshell> b.getServiceCompletionTime()$.. ==> 60jshell> b.getNumOfLoadersRequired()$.. ==> 2jshell> new Loader(1, b).serve(b) $.. ==> Loader 1 serving [email protected]jshell> new Loader(1, b).serve(b).getNextAvailableTime()$.. ==> 60jshell> new Loader(2, b)$.. ==> Loader 2 serving [email protected] jshell> new Loader(3, b)$.. ==> Loader 3 serving [email protected]jshell> new Loader(4, new BigCruise(B2345, 0, 30, 1450)).serve(new SmallCruise(S0000, 29))$.. ==> Loader 4 serving [email protected]jshell> new Loader(5, new BigCruise(B3456, 0, 75, 1510)).serve(new SmallCruise(S0001, 30))$.. ==> Loader 5 serving [email protected]jshell> /exit
$ javac your_java_files$ jshell your_java_files_in_bottom-up_dependency_orderjshell> List<Cruise> cruises = List.of(new SmallCruise(S1111, 1300))cruises ==> [[email protected]] jshell> serveCruises(cruises)Loader 1 serving [email protected] jshell> cruises = List.of(new BigCruise(B1111, 1300, 80, 3000),> new SmallCruise(S1111, 1359),> new SmallCruise(S1112, 1400), > new SmallCruise(S1113, 1429))cruises ==> [[email protected], [email protected], [email protected], [email protected]] jshell> serveCruises(cruises) Loader 1 serving [email protected]Loader 2 serving [email protected]

$ jshell your_java_files_in_bottom-up_dependency_order jshell> new SmallCruise(S0001, 0).getArrivalTime() $.. ==> 0

jshell> new SmallCruise(S0001, 0).getServiceCompletionTime()

$.. ==> 30

jshell> new SmallCruise(S0001, 0).getNumOfLoadersRequired()

$.. ==> 1

jshell> (Cruise) new SmallCruise(S0123, 1220)

$.. ==> [email protected]

jshell> new Loader(1, new SmallCruise(S1245, 2330))

$.. ==> Loader 1 serving [email protected]

jshell> new Loader(1, new SmallCruise(S1245, 2330)).canServe(new SmallCruise(S2345, 2359))

$.. ==> false

jshell> new Loader(1, new SmallCruise(S1245, 2330)).serve(new SmallCruise(S2345, 2359))

$.. ==> Loader 1 serving [email protected]

jshell> new Loader(1, new SmallCruise(S2030, 0))

$.. ==> Loader 1 serving [email protected] jshell> /exit

Level 4

Represent Big Cruises

Design the BigCruise class. The arguments of the constructor are its identifier, time of arrival, the length of the cruise, and number of passengers, in that order.

Level 5

Output the loader allocation schedule

Write a method void serveCruises(List<Cruise> cruises) that takes in a list of cruises, and outputs the allocation schedule of the loaders required to service all the cruises. Save the method in the file level5.jsh.

Loader 3 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected] jshell> cruises = List.of(new SmallCruise(S1111, 900),> new BigCruise(B1112, 901, 100, 1),> new BigCruise(B1113, 902, 20, 4500),> new SmallCruise(S2030, 1031),> new BigCruise(B0001, 1100, 30, 1500),> new SmallCruise(S0001, 1130))cruises ==> [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]] jshell> serveCruises(cruises) Loader 1 serving [email protected]Loader 2 serving [email protected]Loader 3 serving [email protected]Loader 4 serving [email protected]Loader 2 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected]Loader 1 serving [email protected]
Level 6Recycled LoadersThe objective of this level is to determine whether your current implementation can be easily extended with minimal modification to the clientThe Cruise Centre has just introduced a new eco-friendly policy in an effort to go green. Their policy states that every third loader that is purchased must be made of recycled materials (referred to as recycled loaders). These recycled loaders will go through a 60-minute long maintenance after every service. It is unable to serve any cruise during this period.For example, if a recycled loader serves a SmallCruise that arrives at 12:30PM, then the next time the loader can serve another Cruise is 2PM (30min + 60min after 12:30PM).By modifying level5.jsh, incorporate the above with minimal modifications to the file level6.jsh.

$ javac your_java_files$ jshell your_java_files_in_bottom-up_dependency_orderjshell> List<Cruise> cruises = List.of(new BigCruise(B1111, 0, 60, 1500),> new SmallCruise(S1112, 0),> new BigCruise(B1113, 30, 100, 1500),> new BigCruise(B1114, 100, 100, 1500),> new BigCruise(B1115, 130, 100, 1500), > new BigCruise(B1116, 200, 100, 1500))cruises ==> [[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]] jshell> serveCruises(cruises) Loader 1 serving [email protected]Loader 2 serving [email protected]Recycled Loader 3 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected]Loader 4 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected]Loader 4 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected]Recycled Loader 3 serving [email protected]Loader 1 serving [email protected]Loader 2 serving [email protected]Loader 4 serving [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2030 Lab 3 # Cruise Loaders[Solved] CS2030 Lab 3 # Cruise Loaders
$25