A)Start with a Code Refactoring (code improvement) Assignment: Before beginning work on the main part of your assignment, implement the following 3 improvements to your code:

  • First, change the name of your solutions Entry Point (your Module, which is currently named Module1) to TrainsCUI (Note: This is a not a File Name!).
  • Next, encapsulate your code for the RemoveTrain functionality in a new Method of TrainsCLI called RemoveTrain(). There should be no change in program function.
  • Finally, you should re-work your JTrain.GetStatus() and JFreightTrain.GetStatus() methods to properly support code reuse. This requires two main changes:
    • To support flexible reporting of Train type (programmatically, instead of manually typing JTrain and JFreightTrain, you need run-time Type discovery. For this, you should use the GetType() operator to get the type of the current JTrain instance, so that you can display it as a String. You should do this using the current object (Me), in this manner: Me.GetType().Name.ToString()
    • To support code reuse, you should call the GetStatus() Method of the Base Class (JTrain) in the GetStatus() Method of any Derived Classes (e.g., JFreightTrain), instead of retyping the same code in two places.

B)Next, add a new Class Library to your Solution, called Final_Spring2017. (**) Note: you should make sure to add appropriate references, and import statements, as necessary (as usual when adding a class library to a solution).

C)Next, add a new Class to the new Final_Spring2017 Class Library called JWaterTrain, which allows users also make trains to transport Water (in liters), in addition to JTrains and JFreightTrains. This new Class should: see image.

  • Inherit from JTrain (NOT JFreightTrain)
  • Import TrainsLib.HighPerformance
  • Allow users to make new instances of JWaterTrain, and:
    • Load an amount of Water (Double liter value) onto each JWaterTrain, as requested by the user, to the maximum Water capacity of the train.
    • Unload a Water amount from each JWaterTrain, as requested by the user, down to zero liters (but not beyond).

Your JWaterTrain Class should have:

1.Two Public Shared Members (both of type Double):

  • waterCapacity
    • Sets the maximum loaded amount for any single train
    • Should be set to a default value of 1000.0 (liters) here (not specified by the user).
  • totalWaterDelivered
    • keeps track of the total Water amount delivered at any time, by ALL JWaterTrains during a program run.

2.A Private Double Member called _water

  • That keeps track of how much Water, in liters, is currently on a JWaterTrain instance.

3.A 4 parameter New() Constructor that uses the 3-parameter Constructor of the Base Class (JTrain), to create a New JWaterTrain with user-specified values for:

  • Name,
  • Color,
  • CarNumber,
  • Starting Water Load (sets the value of _water using the Water Property)

4.A Public Property called Water

  • Which Gets and Sets the value of _water

5.Two Public Functions:

  • LoadWater(ByVal Double amount) As String
    • Used to allow the user to request to load the train with an amount of Water (liters) up to its WaterCapacity, using the Water Property.
    • This Function should refuse:
      1.to load water beyond the trains set Water capacity;
      2.to load negative amounts.
    • This Function should return a String which can be used to advise the user of:
      1. How much water is on the train after loading (the total), and…
      2. How much of the requested water amount (if any) could not be loaded onto the train.
  • UnloadWater(ByVal Double Amount) As String
    • Used to unload a user-requested Amount of water from the train, down to 0 liters, using the Water Property to set _water.
    • This Function should refuse:
      1.to offload more water than the train is currently carrying;
      2.to offload negative amounts of water.
    • This Function should return a String which can be used to advise the user of
      1. How much water was successfully offloaded from the train;
      2. How much of the requested water (if any) could NOT be offloaded.
  • You should Override JTrain.GetStatus(), so that each JWaterTrain reports not only its Name, State, and Number of Cars, but also:
    • Asks the Water Property to report the current amount of water loaded on the JWaterTrain (and includes that information in the status output string).

You should also update your Module to allow users to make and command new JWaterTrains:

1.Update AddTrain() to allow users to add a new JWaterTrain, using the new constructor you created, above.

2.Update Main() by adding the commands:

  • CheckTotalWaterDelivered - allows a user to check the total amount of water delivered together, BY ALL TRAINS.
  • DisplayStudentID allows a user to display the name and student ID of the programs author (display your Name and ID Number on the Console).

3.Update CommandTrain() by adding the commands:

  • LoadWater requests a water amount to load from the user, and uses LoadWater() to check the validity of the request, and load the water, as much as possible.
  • UnloadWater - requests an amount of water to load from the user, and then uses JWaterTrain.UnloadWater() to check the validity of the request, and offload the water, as much as possible
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.