Menu

Use Java Programming Following Questions Solutions Ready Within Today Jan 3 2020 7 00pm Gm Q43785294

Use java programming for the following questions to have thesolutions ready within today Jan 3 2020 at or before 7:00PM GMT+8time zone:

Question 15

A train consists of a number of carsand Cindy puts the cars of a train in decreasing order ofweightUnfortunately, ordering train cars is difficult. A personcannot easily lift a car and place it in the correct position. Itis impractical, if not impossible, to insert a car into an existingtrain. So, a car may only be added to the beginning or the end of atrain. The cars (with known weights) of a train arrive at a stationin a specific order. When a car arrives, Cindy can add it to thebeginning or the end of the train, or simply not adding it. Shelikes to make the train as long as possible, but the cars of itmust be sorted by weight, with the heaviest one at the front of thetrain. You can assume all the weights are different and we wouldlike to find the longest train Cindy can make.

  1. Write a class LongestTrain with a private attribute weight,which is an array of integers representing the weights of thetrains. The weight of car k is stored in weight[k-1]. The order ofarrival is car 1, car 2, …, car n, where n = weight.length. Alsowrite the constructor with a single parameter weight which isassigned to the attribute.
  1. Write a method findLongest() with the attribute weight as theparameter and returns an integer representing the longest trainCindy can make. You may write some other methods which are calledby findLongest().

Expert Answer


Answer to Use java programming for the following questions to have the solutions ready within today Jan 3 2020 at or before 7:00PM…

OR