A passenger train is made up of one or more business-class cars and economy-class cars. Each...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A passenger train is made up of one or more business-class cars and economy-class cars. Each car contains several seats. When you purchase a ticket for a train trip, a specific seat is booked for you. Purchasing a ticket to ride in a business-class car costs more than a ticket for a seat in an economy-class car. The train-v2 project contains an incomplete implementation of a class that models a train. Train has a private field, cars, the list of cars in the train. The list is implemented as an ArrayList of Car objects. (A summary of some of the ArrayList methods is provided at the end of this lab.) Your job is to complete the implementation of Train. You cannot define additional constructors or methods in Seat, Car, or Train, or change the specification of any of the constructors and methods. All fields must be private; i.e., it is not permitted for objects of one class to directly access the fields of objects of another class. You can test your Train class interactively, using BlueJ's object bench. You can use the BlueJ debugger (which you learned how to use in Lab 3) to locate any bugs in your code. In addition, you have been provided with a test class called TrainTest. To use this class, you must enable BlueJ's testing tools (see Lab 2 if you've forgotten how to do this). After you write each method (and it compiles without errors), click the Run Tests button. The test results will tell you if your methods are working. Write the methods in the order listed below, and make sure you finish each step before moving on to the next step. At this point in the course, you are not expected to understand all of the code in TrainTest (in particular, the use of methods assertEquals(), assert Same (), assertTrue () and assert False ()), but you are welcome to try to figure out what each of the test methods do. Part 1 - Developing Class Train Section A 1. Add Javadoc comments at the top of the class. See class Seat for an example. 2. Class Train has one constructor, which has no parameters. Write this constructor so that it initializes the cars field with the reference to a new ArrayList object that can store references to Car objects. This constructor does not initialize the ArrayList with Car objects. If your constructor works, testCreateEmptyTrain () should pass. 3. Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 2 - Developing Class Train Section B 1. Method addCar () has a single parameter of type Car and returns nothing. This method adds the specified Car object to the list of cars in this train. Write this method. If your method works, testAddCar () should pass. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 3 - Developing Class Train Section C 1. Method issueTicket () has a single boolean parameter and returns a boolean. If the parameter is true, the method attempts to issue a ticket for a seat in a business-class car; if false, it attempts to issue a ticket for a seat in an economy-class car. This method will attempt to book a seat in the first car of the appropriate type, but if a seat is not available it will attempt to book a seat in the second car of the appropriate type, and so on. This method must ensure that a request to issue a ticket in a business-class car will never result in a seat being booked in an economy-class car, and vice-versa. If a ticket is successfully issued, the method returns true; otherwise, it returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called bookNextSeat (). Write this method. Before testing this method, from the BlueJ menu select View > Show Terminal. If your method works, testIssueTicket () should pass, and the tickets will be "printed" in the Terminal Window. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 4 - Developing Class Train Section D 1. Method cancelTicket () has two parameters, an integer car id and an integer seat number, and returns a boolean. If the car id and seat number are valid, and if the specified seat in the specified car has been booked, this method cancels the booking for that seat and returns true. If the car id or seat number are not valid, or if the specified seat has not been booked, the method returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called cancelSeat (). Write this method. If your method works, testCancelTicket () should pass. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good the entire Train class. 3. You will build on Lab 5 in Lab 7, so be sure to save your work. Submission Submit Train.java. API Summary - Class ArrayList<E> // Appends object o (of type E) to the end of this list. Returns true if // successful, otherwise returns false. boolean add (E o); A passenger train is made up of one or more business-class cars and economy-class cars. Each car contains several seats. When you purchase a ticket for a train trip, a specific seat is booked for you. Purchasing a ticket to ride in a business-class car costs more than a ticket for a seat in an economy-class car. The train-v2 project contains an incomplete implementation of a class that models a train. Train has a private field, cars, the list of cars in the train. The list is implemented as an ArrayList of Car objects. (A summary of some of the ArrayList methods is provided at the end of this lab.) Your job is to complete the implementation of Train. You cannot define additional constructors or methods in Seat, Car, or Train, or change the specification of any of the constructors and methods. All fields must be private; i.e., it is not permitted for objects of one class to directly access the fields of objects of another class. You can test your Train class interactively, using BlueJ's object bench. You can use the BlueJ debugger (which you learned how to use in Lab 3) to locate any bugs in your code. In addition, you have been provided with a test class called TrainTest. To use this class, you must enable BlueJ's testing tools (see Lab 2 if you've forgotten how to do this). After you write each method (and it compiles without errors), click the Run Tests button. The test results will tell you if your methods are working. Write the methods in the order listed below, and make sure you finish each step before moving on to the next step. At this point in the course, you are not expected to understand all of the code in TrainTest (in particular, the use of methods assertEquals(), assert Same (), assertTrue () and assert False ()), but you are welcome to try to figure out what each of the test methods do. Part 1 - Developing Class Train Section A 1. Add Javadoc comments at the top of the class. See class Seat for an example. 2. Class Train has one constructor, which has no parameters. Write this constructor so that it initializes the cars field with the reference to a new ArrayList object that can store references to Car objects. This constructor does not initialize the ArrayList with Car objects. If your constructor works, testCreateEmptyTrain () should pass. 3. Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 2 - Developing Class Train Section B 1. Method addCar () has a single parameter of type Car and returns nothing. This method adds the specified Car object to the list of cars in this train. Write this method. If your method works, testAddCar () should pass. A passenger train is made up of one or more business-class cars and economy-class cars. Each car contains several seats. When you purchase a ticket for a train trip, a specific seat is booked for you. Purchasing a ticket to ride in a business-class car costs more than a ticket for a seat in an economy-class car. The train-v2 project contains an incomplete implementation of a class that models a train. Train has a private field, cars, the list of cars in the train. The list is implemented as an ArrayList of Car objects. (A summary of some of the ArrayList methods is provided at the end of this lab.) Your job is to complete the implementation of Train. You cannot define additional constructors or methods in Seat, Car, or Train, or change the specification of any of the constructors and methods. All fields must be private; i.e., it is not permitted for objects of one class to directly access the fields of objects of another class. You can test your Train class interactively, using BlueJ's object bench. You can use the BlueJ debugger (which you learned how to use in Lab 3) to locate any bugs in your code. In addition, you have been provided with a test class called TrainTest. To use this class, you must enable BlueJ's testing tools (see Lab 2 if you've forgotten how to do this). After you write each method (and it compiles without errors), click the Run Tests button. The test results will tell you if your methods are working. Write the methods in the order listed below, and make sure you finish each step before moving on to the next step. At this point in the course, you are not expected to understand all of the code in TrainTest (in particular, the use of methods assertEquals(), assert Same (), assertTrue () and assert False ()), but you are welcome to try to figure out what each of the test methods do. Part 1 - Developing Class Train Section A 1. Add Javadoc comments at the top of the class. See class Seat for an example. 2. Class Train has one constructor, which has no parameters. Write this constructor so that it initializes the cars field with the reference to a new ArrayList object that can store references to Car objects. This constructor does not initialize the ArrayList with Car objects. If your constructor works, testCreateEmptyTrain () should pass. 3. Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 2 - Developing Class Train Section B 1. Method addCar () has a single parameter of type Car and returns nothing. This method adds the specified Car object to the list of cars in this train. Write this method. If your method works, testAddCar () should pass. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 3 - Developing Class Train Section C 1. Method issueTicket () has a single boolean parameter and returns a boolean. If the parameter is true, the method attempts to issue a ticket for a seat in a business-class car; if false, it attempts to issue a ticket for a seat in an economy-class car. This method will attempt to book a seat in the first car of the appropriate type, but if a seat is not available it will attempt to book a seat in the second car of the appropriate type, and so on. This method must ensure that a request to issue a ticket in a business-class car will never result in a seat being booked in an economy-class car, and vice-versa. If a ticket is successfully issued, the method returns true; otherwise, it returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called bookNextSeat (). Write this method. Before testing this method, from the BlueJ menu select View > Show Terminal. If your method works, testIssueTicket () should pass, and the tickets will be "printed" in the Terminal Window. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 4 - Developing Class Train Section D 1. Method cancelTicket () has two parameters, an integer car id and an integer seat number, and returns a boolean. If the car id and seat number are valid, and if the specified seat in the specified car has been booked, this method cancels the booking for that seat and returns true. If the car id or seat number are not valid, or if the specified seat has not been booked, the method returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called cancelSeat (). Write this method. If your method works, testCancelTicket () should pass. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good the entire Train class. 3. You will build on Lab 5 in Lab 7, so be sure to save your work. Submission Submit Train.java. API Summary - Class ArrayList<E> // Appends object o (of type E) to the end of this list. Returns true if // successful, otherwise returns false. boolean add (E o); 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 3 - Developing Class Train Section C 1. Method issueTicket () has a single boolean parameter and returns a boolean. If the parameter is true, the method attempts to issue a ticket for a seat in a business-class car; if false, it attempts to issue a ticket for a seat in an economy-class car. This method will attempt to book a seat in the first car of the appropriate type, but if a seat is not available it will attempt to book a seat in the second car of the appropriate type, and so on. This method must ensure that a request to issue a ticket in a business-class car will never result in a seat being booked in an economy-class car, and vice-versa. If a ticket is successfully issued, the method returns true; otherwise, it returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called bookNextSeat (). Write this method. Before testing this method, from the BlueJ menu select View > Show Terminal. If your method works, testIssueTicket () should pass, and the tickets will be "printed" in the Terminal Window. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good for the portions of class Train completed. Part 4 - Developing Class Train Section D 1. Method cancelTicket () has two parameters, an integer car id and an integer seat number, and returns a boolean. If the car id and seat number are valid, and if the specified seat in the specified car has been booked, this method cancels the booking for that seat and returns true. If the car id or seat number are not valid, or if the specified seat has not been booked, the method returns false. This method must NOT call the seats () method in class Car (that method is reserved for use by test cases). Hint: recall that class Car has a method called cancelSeat (). Write this method. If your method works, testCancelTicket () should pass. 2. Did you remember to add Javadoc comments? Generate the Javadoc and check that it looks good the entire Train class. 3. You will build on Lab 5 in Lab 7, so be sure to save your work. Submission Submit Train.java. API Summary - Class ArrayList<E> // Appends object o (of type E) to the end of this list. Returns true if // successful, otherwise returns false. boolean add (E o);
Expert Answer:
Answer rating: 100% (QA)
Based on the provided instructions heres a structured approach to completing the Train class java im... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Hussein Hage has just approached a venture capitalist for financing for his new restaurant, Bistro Sally. The lender is willing to loan Bistro Sally Inc. $240,000 at a high-risk interest rate of 9%....
-
What are the expected returns for stocks X and Y? Bear Market .2 -20% -15% Normal Market .5 1896 2096 Bull Market .3 50% 1096 Stock X Stock Y
-
A fraction in its simplest form and its equivalent decimal are shown below. However, most of the numbers are covered. The hidden digits, in no particular order, are as follows: a. Explain why the...
-
Awesome Adventures Travel, Inc., recorded revenues of \($2,400\) earned on account by providing travel service for clients. Requirements 1. How much are the businesss cash and total assets after the...
-
Berger Company manufactures products Delta, Kappa, and Omega from a joint process. Production, sales, and cost data for July follow. Required: 1. Assuming that joint costs are allocated using the...
-
A brainstorming session is a fantastic way to get ideas down on paper. In this kind of creative thinking, no answer is wrong. It is just a possibility. Brainstorming with peers is a fun way to get...
-
The isotope technetium-99m is used by doctors to image the skeleton and heart muscles. Fol- lowing injection, the concentration of this isotope decays exponentially in the body. a. Let N(t) represent...
-
Construct the Du Pont Equations for Prospec. What does it tell us? 20X7 20X8 20X8 Sales $1,578 $2,106 $3,265 COGS 631 906 1,502 Gross Margin $ 947 $1,200 $1,763 Expenses Marketing $316 $495 $882 R...
-
Your state is considering passage of a statute that exempts possession and use of marijuana from prosecution if it is used for medical purposes. One of the cases that has been used to support the...
-
A fugitive is trying to catch a train that passes by chuggi along at a constant speed of 5 m/s. The fugitive begins running from rest at an acceleration of 1.4 m/s^2 until he reaches a speed of 6...
-
George's, Fred's, and Sue's employer was a chain pizza parlor located in a shopping mall near their university, the State University of New York at Albany. The local manager decided that rumors of...
-
1. 1(a). Suppose you are evaluating a project that involves manufacturing solar-powered electric hand tools for the Asian market. You have decided to use the comparison firm method to try to come up...
-
What are the implications of transformational leadership theory on organizational change initiatives, and how can leaders leverage its principles to foster innovation and adaptability within their...
-
Manufacturing work sent to other countries iscalled: A. downsized B. outsourced C. internationalization D. vertical integration E. entrepreneurial ship
-
Define a traverse in Surveying?
-
Zeton Ltd is an engineering company based in Kuala Lumpur, Malaysia. It has been established for nearly 60 years. The company originally began by supplying components for small machines and war...
-
Explain what you see as the main attributes for organisational success and give examples from your own or some other organisation. Discuss the importance of innovation as a key factor in...
-
For each of the following ten pairs of statements, divide five points between the two according to your beliefs, perceptions of yourself, or according to which of the two statements characterises you...
-
What is an account? What is a ledger?
-
Why are accounting systems called double entry?
-
Does debit always mean increase and credit always mean decrease?
Study smarter with the SolutionInn App