Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Question 15

A train consists of a number of cars and Cindy puts the cars of a train in decreasing order of weightUnfortunately, ordering train cars is difficult. A person cannot easily lift a car and place it in the correct position. It is impractical, if not impossible, to insert a car into an existing train. So, a car may only be added to the beginning or the end of a train. The cars (with known weights) of a train arrive at a station in a specific order. When a car arrives, Cindy can add it to the beginning or the end of the train, or simply not adding it. She likes to make the train as long as possible, but the cars of it must be sorted by weight, with the heaviest one at the front of the train. You can assume all the weights are different and we would like 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 the trains. The weight of car k is stored in weight[k-1]. The order of arrival is car 1, car 2, ..., car n, where n = weight.length. Also write the constructor with a single parameter weight which is assigned to the attribute.
  1. Write a method findLongest() with the attribute weight as the parameter and returns an integer representing the longest train Cindy can make. You may write some other methods which are called by findLongest().

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago