Supply spaceships of different designs and capabilities have been developed to support a human colony on the moon. The ships embark continually from a spaceport in low earth orbit to the moon. On arrival the ships undock, unload their cargo and undergo refuelling and maintenance in 'The RF Centre' (RF) before embarking on the return journey. The bulk of the time at spaceport is spent in RF but only a single spaceship can be accommodated in RF at any one time.

Five competing companies have manufactured distinct ships to service the colony - each ship travels at different speeds, has a different payload capacity and requires differing periods in RF (relative to the fastest ship):

  • Ship 1, capacity 3000Kg, is the fastest ship spending 1 (minimum) to 2 days (maximum) in a one way trip with 2 to 4 days in maintenance (RF centre) per return trip.
  • Ship 2, capacity 6000Kg, spends twice as long travelling but spends the same amount of time in RF.
  • Ship 3, capacity 14000Kg, takes three times as long travelling as the fastest ship and spends two times the amount of time in RF.
  • Ship 4, capacity 20000Kg, takes four times as long travelling as the fastest ship and spends three times the amount of time in maintenance.
  • Ship 5, capacity 40000Kg, takes five times as long travelling as the fastest ship and spends four times the amount of time in maintenance.

Follow the subsections below (together with your own model) to write a multithreaded Java application to simulate the performance of the ships in competition with each other over 3 years. Include screenshots of the output of your program in your answer and paste the Java code of your final solution in an appendix to the document.

(a)Create a Ship class. The constructor for the ship class should accept a reference to the RF centre object, an identifier string for the ship's name ("ShipType 1", for example) and three numbers identifying the unique characteristics of each of the ships; the maximum payload in KG, the maximum days of a single journey to travel to the colony and the maximum days in the RF centre.

The ship should have members that store a count of the total number of trips, total time spent travelling and in maintenance [RF center].

(b)Each ship must have a run() method which advances the time elapsed "travelling" by 1 day of simulation time for each 10ms of actual time. A random number generator should be used to calculate the duration of each trip within the limits specified by the ship type. When the end of the competition has been reached (3 years), a toString method should display the total number of trips, count of days spent travelling and days spent in the RF centre. The total cargo weight delivered should also be displayed

(c)Display messages in the terminal stating that the simulation has started, notifying the user if an RF session is taking place and display each agent's toString method at the end of the simulation. Calculate and display the total payload transported.

(d)Create an RF_Centre class. It should have a method to "refuel and maintain" a space ship and return the actual RF duration in days. Ensure only one ship can access the RF Centre at any one time.

(e)Create a SpaceshipCompetition class that has a main method that creates and starts the threads.

(f)You want to ensure that all space ships depart at the same time when the competition starts. Write a new class called "Competition" that has methods to:

  • Get Ready for Competition Start - makes all spaceships wait for the Competition to start.
  • Start the Competition - notifies all ships to start their journey.

Modify the CompetitionMain and Ship classes accordingly.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.