Assignment Overview You are the database administrator for a small airline. You have the task of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Assignment Overview You are the database administrator for a small airline. You have the task of handling bookings for the airline's planes, both commercially and industrially. You will have to build a program that reads and processes instructions from a text file, making changes to the system as necessary and printing out error messages when problems occur. You will implement a set of related classes of objects, as seen in the hierarchy below: COMP 1020 Winter 2022 Main Airline Person Employee Payload Item Cargo Commercial Exception InvalidInputException Flight InvalidBooking Exception Industrial Main will contain a main method and reads in data files. It will create an instance of the Airline class. Airline is your central class that has Items that are managed to run an airline. Item, Payload, and Flight are abstract classes. Exception is already defined, so you will only implement its children. Download the provided .java files for Airline, Item, Payload, Person, Employee, Cargo, Invalid InputException, and InvalidBookingException. These are starting points to help you on your way. You may write your files entirely on your own, or use these files. More code will be added to these files later, but you just need them to successfully compile Phase 1 and 2. For Industrial planes, a Payload is valid if it passes the previously defined validation, and it is Cargo or an Employee (but not a non-Employee Person). These additional validations should be handled in the book methods of Commercial and Industrial. You are welcome to add helper methods if you prefer. Phase 3: Item Items are used in the system as a superclass for both Flight and Payloads. All Items are issued a unique identifier within the system, for tracking. The rules for IDs are as follows: All ID numbers are 9 digits long The first digit changes based on the type of item Commercial Flights start with 1 o • Industrial Flights start with 2 • Persons start with 3 o Cargo starts with 4 The last 8 digits begin at 0 and increase by one for each item created ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 。 That is, the first Item created will end in 0, the next will end in 1, and so on. Example: creating a Commercial flight would be issued id 100000000, then a Person would be issued 300000001 respectively. Consider where to add code in the hierarchy (Item, and its subclasses) to generate and store these IDs. Class Item should also have the following: Add method public static int getTotalNumberOfItems(), which returns the number of Items that have been created. Add public int getID() which returns the ID that has been generated for this object. Phase 4: Airline Next, implement the start of Airline so we can keep track of our Flights and Payloads. An Airline tracks all Flights and all Payloads in lists. For lists, you can use partially-filled arrays, ArrayLists or any other collection type you deem fit. Airlines will then use the following methods to track the data: Method public String addFlight(char type) which adds a new Flight. This method takes in a char which should be either 'C' (for Commercial Flights) or 'l' (for Industrial Flights). It should then create the appropriate Object and store it in the flights array. If the char received is neither 'C' nor 'I', addFlight should throw an Invalid InputException If a Flight is successfully added, this method should return a String saying so (as seen below), which the calling method (in Main) should print. Add a method public Flight getFlight(int id) which accepts an ID number and returns the Flight from flights which has that ID number, or null if no such Flight exists. Now, edit Main to take advantage of your new class • Your main method from Phase 1 creates a new Airline, and reads in a list of commands via readInputFile and parseCommand. • Update your parseCommand to handle the following commands, following the guidelines in Phase 1. • CREATE-FLIGHT typeCode ⚫ This creates a new Flight. The second token (typeCode) will be "C" for Commercial Flights and "I" for Industrial Flights. Any other token should throw an Invalid InputException. GET-FLIGHT id This finds the Flight with the specified ID and prints its data by calling the toString on the flight. If no such Flight exists, it prints an error message instead. You can test your program by running it with the TestPhase4.txt file provided. You should get the output seen here: Commercial Flight 100000000 has a payload size of 0 Commercial Flight 100000001 has a payload size of 0 Industrial Flight 200000002 has a payload size of 0 InvalidInputException: Flight Creation Command Incorrect Commercial Flight 100000001 has a payload size of 0 Phase 5: Payload and subclasses It is time to more fully implement Payload and its various subclasses. Modify the provided files, changing the constructors (including updating the constructor signature), adding methods variables where appropriate, to make the implementation work. ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 • • • • All Payload items have a weight, which should be stored as a double. A Payload's weight will be passed in when the constructor is called (this is already done in the Payload skeleton). Persons (including Employees) should have a firstName and a lastName. Employees have (in addition to their ID number), an empID number. This should be generated in the same way as ID numbers, except the first digit should be 5. However, the count of Employees should be independent of the number of Items created. ° That is, the first employee will always have an empID of 500000000 regardless of how many other Persons or Cargo has been created Employees also have a job, which is passed into their constructor along with their name. Create a method public boolean hasJob(String isltThisJob) in Employee. This method accepts a String as input. If the String matches the Employee's job, return True. Otherwise, return False. Create a toString method in Payload to print out a Payload's ID and weight, as seen here. Note that the weights must line up as shown. You may assume nothing will be more than 9999 kg. ID: 400000002, Weight: ID: 400000003, Weight: • 50 kg 150 kg Create a toString method in Person to add the Person's first name to its output, as seen here ID: 300000004, Weight: 60 kg, Name: Mike • Create a toString method in Employee to add the Employee's empID and job to its output, as seen here ID: 300000005, Weight: 75 kg, Name: Mike, EMP: 500000000, Job: Pilot In the Payload skeleton file, there is a parameter-less constructor. Now that Payload has been fully implemented, delete it, as it is not needed. Phase 6: Payloads Create a factory method in Payload to create Payloads from given data - public static Payload payload Factory(String payloadType, String weight, String firstname, String lastname, String job) throws Invalid InputException. Instantiate appropriate objects given the following rules: payloadType will be 'P' for Person, 'E' for Employee, and 'C' for Cargo. weight will be expressed as an integer (see TestPhase 7.txt for examples) Persons have a weight, a first and last name, but no job. Employees have a weight, a first and last name, and a job. Cargo has a weight, but no first name, last name, or job. You may assume the input is good and reliable. If the number provided for weight cannot be made into a Double, throw the exception. In parseCommand, pass null for the input that has not been provided if there is none provided on the line that you are processing. For instance, cargo would have null for job. Create methods addPayload and getPayload to class Airline to manage Payloads that are to be sent. • Method public void addPayload (Payload the Payload) which adds a new Payload to the list of Payloads stored in Airline. Add a method public Payload getPayload(int id) which accepts an ID number and returns the Payload from the list of Payloads which has that ID number, or null if no such Payload exists. Phase 7: Expanding Functionality Now it is time to add some more commands for the system to process. Update your program to be able to process the following commands. Add instance variables and methods as required. Any variation from the template shown below should throw an InvalidInputException. • • CREATE-PAYLOAD payloadType weight firstName lastName job 。 Use your factory method to create a payload with this data. The parameters are the same. Keep track of this payload in your Airline object. GET-PAYLOAD id This command should produce the same result as GET-FLIGHT but for Payloads о Use accessor methods you have defined in previous phases ASSIGN-PAYLOAD flightID payloadID 。 This should call book to add the payload with the given ID to the flight with the given ID. If either the flight or the payload does not exist, it should throw an Invalid InputException with an appropriate message. Output of TestPhase7.txt: Commercial Flight 100000000 has a payload size of 0 ID: 300000001, Weight: ID: 300000002, Weight: ID: 400000003, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot 200 kg ID: 300000001, Weight: 50 kg Name: John ID: 300000002, Weight: 75 kg Name: Jane EMP: 500000000, Job: Pilot InvalidInputException: Payload 200000001 does not exist InvalidInputException: Can only book Persons for Commercial flights Commercial Flight 100000000 has a payload size of 1 Phase 8: Taking Flight Finally, implement the ability to make planes take off. Do the following: • • Add a new variable to Flight to track if the flight has taken off. A flight can only take off once. Add public boolean canTakeoff() in Flight to check if a Flight can take off. A Flight can take off only if all the following are true. • It has not already taken off • This flight contains at least 2 items It has at least one Employee in its payload Add a public String doTakeoff() in Flight that will be called to make a plane take off 。 The method should call canTakeoff() to check if the Flight can take off. • If it can, this method should make the flight take off • It should return a String describing whether the Flight took off (as seen in the test phase) Edit Main and Airline as necessary to implement the command: TAKEOFF flightID If the flightID does not exist, throw an Invalid InputException 。 Otherwise, print the message resulting from the call to the doTakeoff method. Sample result of running with TestPhase8.txt: Commercial Flight 100000000 has a payload size of 0 Commercial Flight 100000001 has a payload size of 0 Industrial Flight 200000002 has a payload size of 0 ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 ID: 300000003, Weight: ID: 300000004, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot ID: 300000003, Weight: ID: 300000004, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot ID: 400000005, Weight: 200 kg Flight 100000001 takes off at the speed of light! InvalidInputException: Flight 100000002 does not exist Bonus (5%): 1. Do not allow the same payload to be booked on multiple flights. 2. Do not allow the same payload to be booked twice on the same flight Make a note in your submission that you accomplished this task. Include a test phase as proof. Final note Be sure to use Object Orientation. The only methods that should use “instance of” are book in Commercial and Industiral, and canTake Off in Flight. If you are using instanceof in other places, you can rewrite it by using polymorphism! Assignment Guidelines Unless specified otherwise, all instance variables must be private or protected, and all methods should be public. Also, unless specified otherwise, there should be no println statements in your classes. Objects usually do not print anything; they only return String values from toString methods. Your code should be DRY - don't repeat yourself. If you have a method that already accomplishes a task, or has some logic, that logic should be used. You may add any private methods you see fit. Only use instanceof where it is absolutely necessary - most problems can be solved with polymorphism instead of instanceof. The description of the assignment has methods that are required. There may be suggested names for the parameters, which you may change. Unless specifically noted, provided method signatures are suggestions and you may change them if you wish. This assignment is more open-ended than the previous two. The parameters you need for methods are not always specified, nor are the types of instance variables. In addition, you will not be told specifically which methods should catch which errors. This is by design; the goal of this assignment is to get you to think carefully about how to design a program given only the abstract specifications. Assignment Overview You are the database administrator for a small airline. You have the task of handling bookings for the airline's planes, both commercially and industrially. You will have to build a program that reads and processes instructions from a text file, making changes to the system as necessary and printing out error messages when problems occur. You will implement a set of related classes of objects, as seen in the hierarchy below: COMP 1020 Winter 2022 Main Airline Person Employee Payload Item Cargo Commercial Exception InvalidInputException Flight InvalidBooking Exception Industrial Main will contain a main method and reads in data files. It will create an instance of the Airline class. Airline is your central class that has Items that are managed to run an airline. Item, Payload, and Flight are abstract classes. Exception is already defined, so you will only implement its children. Download the provided .java files for Airline, Item, Payload, Person, Employee, Cargo, Invalid InputException, and InvalidBookingException. These are starting points to help you on your way. You may write your files entirely on your own, or use these files. More code will be added to these files later, but you just need them to successfully compile Phase 1 and 2. For Industrial planes, a Payload is valid if it passes the previously defined validation, and it is Cargo or an Employee (but not a non-Employee Person). These additional validations should be handled in the book methods of Commercial and Industrial. You are welcome to add helper methods if you prefer. Phase 3: Item Items are used in the system as a superclass for both Flight and Payloads. All Items are issued a unique identifier within the system, for tracking. The rules for IDs are as follows: All ID numbers are 9 digits long The first digit changes based on the type of item Commercial Flights start with 1 o • Industrial Flights start with 2 • Persons start with 3 o Cargo starts with 4 The last 8 digits begin at 0 and increase by one for each item created ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 。 That is, the first Item created will end in 0, the next will end in 1, and so on. Example: creating a Commercial flight would be issued id 100000000, then a Person would be issued 300000001 respectively. Consider where to add code in the hierarchy (Item, and its subclasses) to generate and store these IDs. Class Item should also have the following: Add method public static int getTotalNumberOfItems(), which returns the number of Items that have been created. Add public int getID() which returns the ID that has been generated for this object. Phase 4: Airline Next, implement the start of Airline so we can keep track of our Flights and Payloads. An Airline tracks all Flights and all Payloads in lists. For lists, you can use partially-filled arrays, ArrayLists or any other collection type you deem fit. Airlines will then use the following methods to track the data: Method public String addFlight(char type) which adds a new Flight. This method takes in a char which should be either 'C' (for Commercial Flights) or 'l' (for Industrial Flights). It should then create the appropriate Object and store it in the flights array. If the char received is neither 'C' nor 'I', addFlight should throw an Invalid InputException If a Flight is successfully added, this method should return a String saying so (as seen below), which the calling method (in Main) should print. Add a method public Flight getFlight(int id) which accepts an ID number and returns the Flight from flights which has that ID number, or null if no such Flight exists. Now, edit Main to take advantage of your new class • Your main method from Phase 1 creates a new Airline, and reads in a list of commands via readInputFile and parseCommand. • Update your parseCommand to handle the following commands, following the guidelines in Phase 1. • CREATE-FLIGHT typeCode ⚫ This creates a new Flight. The second token (typeCode) will be "C" for Commercial Flights and "I" for Industrial Flights. Any other token should throw an Invalid InputException. GET-FLIGHT id This finds the Flight with the specified ID and prints its data by calling the toString on the flight. If no such Flight exists, it prints an error message instead. You can test your program by running it with the TestPhase4.txt file provided. You should get the output seen here: Commercial Flight 100000000 has a payload size of 0 Commercial Flight 100000001 has a payload size of 0 Industrial Flight 200000002 has a payload size of 0 InvalidInputException: Flight Creation Command Incorrect Commercial Flight 100000001 has a payload size of 0 Phase 5: Payload and subclasses It is time to more fully implement Payload and its various subclasses. Modify the provided files, changing the constructors (including updating the constructor signature), adding methods variables where appropriate, to make the implementation work. ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 • • • • All Payload items have a weight, which should be stored as a double. A Payload's weight will be passed in when the constructor is called (this is already done in the Payload skeleton). Persons (including Employees) should have a firstName and a lastName. Employees have (in addition to their ID number), an empID number. This should be generated in the same way as ID numbers, except the first digit should be 5. However, the count of Employees should be independent of the number of Items created. ° That is, the first employee will always have an empID of 500000000 regardless of how many other Persons or Cargo has been created Employees also have a job, which is passed into their constructor along with their name. Create a method public boolean hasJob(String isltThisJob) in Employee. This method accepts a String as input. If the String matches the Employee's job, return True. Otherwise, return False. Create a toString method in Payload to print out a Payload's ID and weight, as seen here. Note that the weights must line up as shown. You may assume nothing will be more than 9999 kg. ID: 400000002, Weight: ID: 400000003, Weight: • 50 kg 150 kg Create a toString method in Person to add the Person's first name to its output, as seen here ID: 300000004, Weight: 60 kg, Name: Mike • Create a toString method in Employee to add the Employee's empID and job to its output, as seen here ID: 300000005, Weight: 75 kg, Name: Mike, EMP: 500000000, Job: Pilot In the Payload skeleton file, there is a parameter-less constructor. Now that Payload has been fully implemented, delete it, as it is not needed. Phase 6: Payloads Create a factory method in Payload to create Payloads from given data - public static Payload payload Factory(String payloadType, String weight, String firstname, String lastname, String job) throws Invalid InputException. Instantiate appropriate objects given the following rules: payloadType will be 'P' for Person, 'E' for Employee, and 'C' for Cargo. weight will be expressed as an integer (see TestPhase 7.txt for examples) Persons have a weight, a first and last name, but no job. Employees have a weight, a first and last name, and a job. Cargo has a weight, but no first name, last name, or job. You may assume the input is good and reliable. If the number provided for weight cannot be made into a Double, throw the exception. In parseCommand, pass null for the input that has not been provided if there is none provided on the line that you are processing. For instance, cargo would have null for job. Create methods addPayload and getPayload to class Airline to manage Payloads that are to be sent. • Method public void addPayload (Payload the Payload) which adds a new Payload to the list of Payloads stored in Airline. Add a method public Payload getPayload(int id) which accepts an ID number and returns the Payload from the list of Payloads which has that ID number, or null if no such Payload exists. Phase 7: Expanding Functionality Now it is time to add some more commands for the system to process. Update your program to be able to process the following commands. Add instance variables and methods as required. Any variation from the template shown below should throw an InvalidInputException. • • CREATE-PAYLOAD payloadType weight firstName lastName job 。 Use your factory method to create a payload with this data. The parameters are the same. Keep track of this payload in your Airline object. GET-PAYLOAD id This command should produce the same result as GET-FLIGHT but for Payloads о Use accessor methods you have defined in previous phases ASSIGN-PAYLOAD flightID payloadID 。 This should call book to add the payload with the given ID to the flight with the given ID. If either the flight or the payload does not exist, it should throw an Invalid InputException with an appropriate message. Output of TestPhase7.txt: Commercial Flight 100000000 has a payload size of 0 ID: 300000001, Weight: ID: 300000002, Weight: ID: 400000003, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot 200 kg ID: 300000001, Weight: 50 kg Name: John ID: 300000002, Weight: 75 kg Name: Jane EMP: 500000000, Job: Pilot InvalidInputException: Payload 200000001 does not exist InvalidInputException: Can only book Persons for Commercial flights Commercial Flight 100000000 has a payload size of 1 Phase 8: Taking Flight Finally, implement the ability to make planes take off. Do the following: • • Add a new variable to Flight to track if the flight has taken off. A flight can only take off once. Add public boolean canTakeoff() in Flight to check if a Flight can take off. A Flight can take off only if all the following are true. • It has not already taken off • This flight contains at least 2 items It has at least one Employee in its payload Add a public String doTakeoff() in Flight that will be called to make a plane take off 。 The method should call canTakeoff() to check if the Flight can take off. • If it can, this method should make the flight take off • It should return a String describing whether the Flight took off (as seen in the test phase) Edit Main and Airline as necessary to implement the command: TAKEOFF flightID If the flightID does not exist, throw an Invalid InputException 。 Otherwise, print the message resulting from the call to the doTakeoff method. Sample result of running with TestPhase8.txt: Commercial Flight 100000000 has a payload size of 0 Commercial Flight 100000001 has a payload size of 0 Industrial Flight 200000002 has a payload size of 0 ASSIGNMENT 3: Polymorphism COMP 1020 Winter 2022 ID: 300000003, Weight: ID: 300000004, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot ID: 300000003, Weight: ID: 300000004, Weight: 50 kg Name: John 75 kg Name: Jane EMP: 500000000, Job: Pilot ID: 400000005, Weight: 200 kg Flight 100000001 takes off at the speed of light! InvalidInputException: Flight 100000002 does not exist Bonus (5%): 1. Do not allow the same payload to be booked on multiple flights. 2. Do not allow the same payload to be booked twice on the same flight Make a note in your submission that you accomplished this task. Include a test phase as proof. Final note Be sure to use Object Orientation. The only methods that should use “instance of” are book in Commercial and Industiral, and canTake Off in Flight. If you are using instanceof in other places, you can rewrite it by using polymorphism! Assignment Guidelines Unless specified otherwise, all instance variables must be private or protected, and all methods should be public. Also, unless specified otherwise, there should be no println statements in your classes. Objects usually do not print anything; they only return String values from toString methods. Your code should be DRY - don't repeat yourself. If you have a method that already accomplishes a task, or has some logic, that logic should be used. You may add any private methods you see fit. Only use instanceof where it is absolutely necessary - most problems can be solved with polymorphism instead of instanceof. The description of the assignment has methods that are required. There may be suggested names for the parameters, which you may change. Unless specifically noted, provided method signatures are suggestions and you may change them if you wish. This assignment is more open-ended than the previous two. The parameters you need for methods are not always specified, nor are the types of instance variables. In addition, you will not be told specifically which methods should catch which errors. This is by design; the goal of this assignment is to get you to think carefully about how to design a program given only the abstract specifications.
Expert Answer:
Answer rating: 100% (QA)
Phase 1 Main package flightsystem import javaioBufferedReader import javaioFile import javaioFileNotFoundException import javaioFileReader import javaioIOException public class Main SuppressWarningsse... View the full answer
Related Book For
Principles of Information Systems
ISBN: 978-1305971776
13th edition
Authors: Ralph Stair, George Reynolds
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Why might a supervisor be motivated to perceive a subordinate's performance as being poor when it really is not?
-
Bottles of aspirin tablets typically have labels indicating that each tablet contains 325 mg of aspirin, but the actual amounts can vary between 315 mg and 335 mg. A tablet is defective if it has...
-
A Newsweek article titled America the Ignorant (www.newsweek.com) described a Gallup poll that asked adult Americans if they believe that there are real witches and warlocks. Suppose that the poll...
-
Three identical resistors have an equivalent resistance of \(30 \Omega\) when connected in parallel. What is their equivalent resistance when connected in series?
-
Fillmore Industries is a vertically integrated ï¬rm with several divisions that operate as decentralized proï¬t centers. Fillmores Systems Division manufactures scientiï¬c...
-
Firm DEF is currently worth $9,033,860 and its shares are trading at $60 each. DEF is considering offering a 35% stock dividend. If it goes ahead with the stock dividend, what would be the stock...
-
void levell (){ System.out.print("1"); try level2(); } catch (AccessControlException woe) { } System.out.print("4"); System.out.print("1"); void level2 (){ 1274351 System.out.print("2"); try...
-
E-portfolios are considered the authentic work-products of students and well-suited for self-assessment and peer-review (as a means of improving student learning). Why is this so, in your opinion?...
-
A student walks 45 m south, turns, and walks 67 m 23 0 W of N. What is the total displacement of the student?
-
You have a neutral conductor A and wish to give it a negative charge. You have with you a positively charged conductor (P) and nearby is a large metal filing cabinet. What approach would work to give...
-
Today, you borrow a sum of 10 000 euros. You will repay as follows 3,000 in 6 months 4 000 euros in 2 years ' 2,000 in 2 years and 3 months The balance in 3 years Knowing that the annual effective...
-
The Rayleigh PDF is defined by the following equation p(u) p(u) = e C for u 0.0 p(u) = 0.0 for u <0.0 a) Find U, , S, and K u b) Sketch a process u (t) qualitatively that might have a Rayleigh PDF.
-
Bexter Labs produces three products: A, B, and C. Bexter can sell up to 3000 units of product A, up to 2000 units of product B, and up to 2000 units of product C. Each unit of product C uses two...
-
What are the typical record-at-a-time operations for accessing a file? Which of these depend on the current file record?
-
Examine the possibility of a career in computer hardware sales. Which area of sales do you believe holds the brightest prospects for young college graduatesservers, mainframe computers,...
-
For you, what would be the most positive aspects of a career in information systems? What would be the least positive aspects of such a career?
-
What is meant by reasonable expectation of privacy? How does this impact the application of the Fourth Amendment?
-
A function \(f(x, y, z)\) of \(x, y\), and \(z\) is defined as a. Multiply the matrices and express \(f\) as a polynomial in \(x, y\), and \(z\). b. Write down the three equations necessary to find...
-
Solve the matrix equation \([\mathbf{K}]\{\mathbf{Q}\}=\{\mathbf{F}\}\) using forward reduction and backward substitution, where, 5-10 [K] = -13-1 0-1 1 {F}= 0
-
Volunteer work can improve your skills and enhance your rsum. With a partner, seek volunteer opportunities on your campus or in your city. Make a list of volunteer groups that may need help. Here are...
Study smarter with the SolutionInn App