Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please program this question in java since it is given in java please and thank you. Below here is the code for the Sorter.java file

Please program this question in java since it is given in java please and thank you.

image text in transcribed

Below here is the code for the Sorter.java file which is given to you to be used.

/** Sorter class provides methods for sorting lists. Adapted from Java Software Solutions 9th Ed, Lewis & Loftus */

public class Sorter>{ /** Sorts the specified array using selection sort algorithm. @param list The array of objects to sort. */ public void selectionSort(T[] list){ int min; T temp; for(int index = 0; index

Here is the TrainCar.java file which just needs to be completed and done in java

public abstract class TrainCar implements Comparable { private String code; private int inspectionYr;

public TrainCar(String code, int inspectionYr) { this.code = code; this.inspectionYr = inspectionYr; }

public String getCode() { reutn code; }

public int getInspectionYr() { return inspectionYr; }

/** Sorts train car alphbetically by type ina lphabetical order F,P,T, and each type is then sorted by the calculated income in asscending order (lowest to highest income). */ public int compareTo(TrainCar other) { //To do complete method //Returns the result of the comparison } /** Calculates the income of the train car */ public abstract double calculateIncome() { //To do complete method //Retruns the calulated income of the traincar. }

public String toString() { //Returns the textual string containing the code, inspection year, and income of the train car. } }

Below here is the first test case which was used to see if the program runs right.

CN Railway 5 P714 2012 85 true F019 2018 75000 F221 2016 105000 T102 2017 35000 true P904 2018 78 false T102 F220 P714

Now here is the rest of the questions which will use both of the above java files.

image text in transcribed

image text in transcribed

image text in transcribed

Please program all of this in java thank you and have any questions or need anything please leave a comment thank you.

Part 1 You will design and implement a hierarchy of categories of train cars that can be coupled together to form a train. The train cars that can be part of the train include passenger cars, freight cars, and tank cars. The train car code, which consists of letters and numbers, and the year the train car was last inspected are recorded for each train car in the train. The train car code starts with P for passenger cars, F for freight cars, and I for tank cars. For passenger cars, the number of tickets sold for the car and if the car has food service (true) or not (false) is recorded. The income a passenger car generates is based on a ticket price of $120 if there is no food service on the car and $150 if there is. For freight cars, the weight of the freight it is hauling is recorded and the income the car generates is based on a hauling fee of $11,500 for loads of under 100,000lbs and $25,000 for loads of 100,000lbs or more. For tank cars, the volume of materials the tank contains in litres and if the materials are hazardous (true) or not (false) are both recorded. The income a tank car can generate is based on a hauling rate of $17/L for hazardous materials and $9.50/L for all other materials. Include a TrainCar class in your design. The TrainCar class must comply with the Javadoc specifications given in TrainCar.pdf (posted in D2L). Your design must follow oo design principles illustrated in Chapter 10. Construct a UML class diagram. There are several examples of UML class diagrams in your textbook (ie: Figure 10.1). In your diagram there should be a box for each class (divided into 3 sections: name, attributes, methods) and appropriate connecting lines to indicate relationships between classes. All instance variables and methods should be shown including private data/methods and constructors. Remember, private items have a minus sign in front of them, public items have a plus sign in front of them, and abstract class and method names are italicized. You can make your UML diagrams using a drawing application, or if you prefer you can instead draw it by hand on paper and take a photo to include in your report document. However, please make sure that your diagram is neat and easy to read when you take a photo of it. Pencil probably won't show up that well, so you may need to make a good copy using pen. Part 2 Design a Train class for keeping track of the company that owns the train and the train cars that make up the train. You must use arrays and not ArrayList to store the train cars in the Train class. The following operations must be supported by separate methods in the Train class: 1. Returns a copy of the list of train cars in the train (note: this will be the train car array you will sort in the driver). 2. Search for a given train car using the train car code passed in as a parameter. This method returns the target train car if found, null otherwise. 3. toString() that returns all the information about the train including the list of train cars and the income of each car (see example in the sample output) Add the Train class to your UML diagram and include the appropriate connections. Part 3 Implement the classes described in Parts 1 and 2. . For testing these classes, create a driver program that creates a Train object representing a train owned by some company that has some train cars that form the train of each type (passenger, freight, tank). The name of the company and the list of train cars are passed in as parameters to the constructor. Print the Train object (using the toString() method); this will print the name of the company and the list of train cars in the original order (with the code, year of last inspection, and calculated income). See sample output provided at the end of the assignment document. Then, print the list of vehicles in sorted order (train cars are sorted alphabetically by type F, P, T and if they have the same type then sorted by income in ascending order (smallest income to greatest income)) using the selectionSort method provided in the Sorter class. Remember to sort a copy of the train car list. Include in the printout only the code and the income of the train. See sample output provided at the end of the assignment document. Then, search for a few specific vehicles' codes among the vehicles in the inventory; print an appropriate message for these searches. See sample output provided at the end of the assignment document. Part 4 Test your program with the test file (test 1.txt) that is posted in D2L and shown on the next page. Also, create two additional test files of your own. Each test file will have the same structure and contents of the test file provided: train company's name (on a separate line), number of train cars (on a separate line), followed by lines with the code and inspection year, and then the information specific to each train car type. Include at the end some codes that you will search the inventory for. Note the code for passenger cars starts with 'P', the code for freight cars starts with 'F' and the code for tank cars starts with 'T'. Sample Input: CN Railway 5 P714 2012 85 true F019 2018 75000 F221 2016 105000 T102 2017 35000 true P904 2018 78 false T102 F220 P714 Sample Output: CN Railway P714 Inspection Year: 2012 Income: $12,750.00 F019 Inspection Year: 2018 Income: $11,500.00 F221 Inspection Year: 2016 Income: $25,000.00 T102 Inspection Year: 2017 Income: $595,000.00 P904 Inspection Year: 2018 Income: $9,360.00 Sorted Data: F019 F221 P 904 P714 T102 $11,500.00 $25,000.00 $9,360.00 $12,750.00 $595,000.00 Search results: Train Car T102 Train Car F220 Train Car P714 found NOT found found Part 1 You will design and implement a hierarchy of categories of train cars that can be coupled together to form a train. The train cars that can be part of the train include passenger cars, freight cars, and tank cars. The train car code, which consists of letters and numbers, and the year the train car was last inspected are recorded for each train car in the train. The train car code starts with P for passenger cars, F for freight cars, and I for tank cars. For passenger cars, the number of tickets sold for the car and if the car has food service (true) or not (false) is recorded. The income a passenger car generates is based on a ticket price of $120 if there is no food service on the car and $150 if there is. For freight cars, the weight of the freight it is hauling is recorded and the income the car generates is based on a hauling fee of $11,500 for loads of under 100,000lbs and $25,000 for loads of 100,000lbs or more. For tank cars, the volume of materials the tank contains in litres and if the materials are hazardous (true) or not (false) are both recorded. The income a tank car can generate is based on a hauling rate of $17/L for hazardous materials and $9.50/L for all other materials. Include a TrainCar class in your design. The TrainCar class must comply with the Javadoc specifications given in TrainCar.pdf (posted in D2L). Your design must follow oo design principles illustrated in Chapter 10. Construct a UML class diagram. There are several examples of UML class diagrams in your textbook (ie: Figure 10.1). In your diagram there should be a box for each class (divided into 3 sections: name, attributes, methods) and appropriate connecting lines to indicate relationships between classes. All instance variables and methods should be shown including private data/methods and constructors. Remember, private items have a minus sign in front of them, public items have a plus sign in front of them, and abstract class and method names are italicized. You can make your UML diagrams using a drawing application, or if you prefer you can instead draw it by hand on paper and take a photo to include in your report document. However, please make sure that your diagram is neat and easy to read when you take a photo of it. Pencil probably won't show up that well, so you may need to make a good copy using pen. Part 2 Design a Train class for keeping track of the company that owns the train and the train cars that make up the train. You must use arrays and not ArrayList to store the train cars in the Train class. The following operations must be supported by separate methods in the Train class: 1. Returns a copy of the list of train cars in the train (note: this will be the train car array you will sort in the driver). 2. Search for a given train car using the train car code passed in as a parameter. This method returns the target train car if found, null otherwise. 3. toString() that returns all the information about the train including the list of train cars and the income of each car (see example in the sample output) Add the Train class to your UML diagram and include the appropriate connections. Part 3 Implement the classes described in Parts 1 and 2. . For testing these classes, create a driver program that creates a Train object representing a train owned by some company that has some train cars that form the train of each type (passenger, freight, tank). The name of the company and the list of train cars are passed in as parameters to the constructor. Print the Train object (using the toString() method); this will print the name of the company and the list of train cars in the original order (with the code, year of last inspection, and calculated income). See sample output provided at the end of the assignment document. Then, print the list of vehicles in sorted order (train cars are sorted alphabetically by type F, P, T and if they have the same type then sorted by income in ascending order (smallest income to greatest income)) using the selectionSort method provided in the Sorter class. Remember to sort a copy of the train car list. Include in the printout only the code and the income of the train. See sample output provided at the end of the assignment document. Then, search for a few specific vehicles' codes among the vehicles in the inventory; print an appropriate message for these searches. See sample output provided at the end of the assignment document. Part 4 Test your program with the test file (test 1.txt) that is posted in D2L and shown on the next page. Also, create two additional test files of your own. Each test file will have the same structure and contents of the test file provided: train company's name (on a separate line), number of train cars (on a separate line), followed by lines with the code and inspection year, and then the information specific to each train car type. Include at the end some codes that you will search the inventory for. Note the code for passenger cars starts with 'P', the code for freight cars starts with 'F' and the code for tank cars starts with 'T'. Sample Input: CN Railway 5 P714 2012 85 true F019 2018 75000 F221 2016 105000 T102 2017 35000 true P904 2018 78 false T102 F220 P714 Sample Output: CN Railway P714 Inspection Year: 2012 Income: $12,750.00 F019 Inspection Year: 2018 Income: $11,500.00 F221 Inspection Year: 2016 Income: $25,000.00 T102 Inspection Year: 2017 Income: $595,000.00 P904 Inspection Year: 2018 Income: $9,360.00 Sorted Data: F019 F221 P 904 P714 T102 $11,500.00 $25,000.00 $9,360.00 $12,750.00 $595,000.00 Search results: Train Car T102 Train Car F220 Train Car P714 found NOT found found

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions