No citation neededJust follow the instruction and don't use any language other than java. Don't use fancy programing language that is not required because this is a java fundamental course. The Attached Example is the file I uploaded earlier this semester. Use simple comments and following my heading. Thank you very much.
import java.util.Scanner; /** * Tests functionality provided in the Flight class, including constructors, * setter and getter methods, hasMeal method, and toString method. You will be * adding functionality to test the connect and longer methods after the TO DO * comments provided below. */ public class TestFlight { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); Flight flight1 = new Flight(); // instantiate (create) Flight object /* Use setter methods to assign user inputs to instance vars */ System.out.print("Enter the flight code: "); flight1.setFlightCode(keyboard.next()); keyboard.nextLine(); // ignore linefeed char System.out.print("Enter the departure city: "); flight1.setDeparture(keyboard.nextLine()); System.out.print("Enter the destination city: "); flight1.setDestination(keyboard.nextLine()); System.out.print("Enter the flight duration in minutes: "); flight1.setDuration(keyboard.nextInt()); keyboard.close(); System.out.println("\nOutput using get methods and hasMeal:"); System.out.println("Flight1: " + flight1.getFlightCode() + " " + flight1.getDeparture() + " " + flight1.getDestination() + " " + flight1.getDuration() + " " + flight1.hasMeal()); // use the 4-arg constructor to create a second flight Flight flight2 = new Flight("JVA234", "Boston", "St. Louis", -5); /* print both Flight objects, which automatically calls the toString method */ System.out.println("\nDescriptions generated by toString:"); System.out.println(flight1); // calls flight1.toString() System.out.println(flight2); // calls flight2-toString() // reset the duration of Flight2 and print again flight2.setDuration(300); System.out.println("\nAfter resetting duration of second flight:\n" + flight2); System.out.println("\nOutput from additional testing code:"); /** * 1. TO DO Testing code for connects method */ /** * 2. TO DO Testing code for longer method */ } } CS180 Assignment 6 Spring 2020 CS180 Spring 2020 Hw 6 1 CS603 Programming Assignment 6 Due by end-of-day, 4/16/20 1. Getting Started This assignment focuses on material on defining classes covered in weeks 9 to 11 and in chapter 4 of the textbook. In this assignment, the names of your files must exactly match those specified here, namely Flight.java and TestFlight.java. In addition, method signatures, i.e., their names and the type and order of parameters, as well as the method’s return type, must also exactly match their specification. Download TestFlight.java, which has been started for you, and add your Flight class to the same folder. When completed, submit both files via Blackboard. 2. Programming Assignment (35 points total) The Flight class (27 points) You will be defining a class called Flight.java for representing an airline flight. Define the following four private instance variables in that class: 1. flightCode – a string representing the flight designator 2. departure – a string representing the departure city 3. destination – a string representing the arrival city 4. duration – an integer representing the duration of the flight in minutes Do not define any other instance variables. Next, define the following public instance methods. In addition, be sure to include a main method in this class for testing purposes. Each time you add a method, add testing code. The main method will not be graded but should be included in your submission. 1. setFlightCode: instance method with one parameter of type String. No value is returned. A valid value for the flight code parameter begins with the airline’s identifier, which is “JVA” - in any combination of uppercase and lowercase letters - followed by three or more characters. Assign the uppercase value of the parameter to the flightCode instance variable if it meets this criteria. Otherwise, assign “JVA000” as the flight code. Examples of valid parameter values: “Jva234”, “JVAabc3” Examples of invalid parameter values: “Ajva5555” (wrong start), “jva23” (too short) 2. setDeparture: mutator method with one parameter of type String. No value is returned. Assign the uppercase value of the parameter to the departure instance variable. 3. setDestination: mutator method with one parameter of type String. No value is returned. Assign the uppercase value of the parameter to the destination instance variable. 4. setDuration: mutator method with one parameter of type int. No value is returned. Assign the value of the parameter to the duration instance variable if it is greater than 0. Otherwise, leave the value of the instance variable unchanged. 5. getFlightCode, getDeparture, getDestionation, getDuration: accessor methods with no parameters that return the value of the corresponding instance variable. 6. hasMeal: instance method with no parameters that returns a boolean value of true if a meal is served or false otherwise. Meals are only served on flights lasting at least five hours. CS180 Spring 2020 Hw 6 2 7. connects: instance method with one parameter of type Flight. This method returns a boolean value of true if the destination city of the Flight object calling the method is the same as the departure city for the Flight object passed as an argument. Otherwise, a value of false is returned. 8. longer: instance method with one parameter of type Flight that returns a value of type int. If the Flight object calling the method has a longer duration than that of the Flight object passed as an argument, return a value of 1. If the reverse is true (i.e., the Flight object calling the method has a shorter duration), then return a value of -1. If both have the same duration, return a value of 0. (This is similar to the functionality provided by the compareTo method in the String class, which determines whether the calling string or the string passed to the method comes first alphabetically.) The following should be added after we have covered constructors and toString methods. While they are described later in this assignment, constructors should appear in your code immediately after the instance variables. Someone reading your program will then be able to readily find the properties of the class (i.e., instance variables) and how to create objects of the class (i.e., available constructors). 9. A no-argument (0-arg) constructor that does nothing. 10. A four-argument constructor that is passed four arguments in the following order: flight code, departure city, destination city, and flight duration. This constructor must call the appropriate mutator (setter) methods for assigning values to the corresponding instance variables. 11. toString: instance method with no parameters that returns a string description of the Flight object calling the method, including the flight code, departure city, destination city, flight duration, and either “No meal” or “Meal included,” depending on which is the case. For example: Flight code: JVA1234 Departure: BOSTON Destination: NEW YORK Duration: 77 minutes No meal Flight code: JVA113 Departure: NEWARK Destination: MIAMI Duration: 310 minutes Meal included For full credit, make use of the hasMeal method to determine whether or not a meal is served on the flight. The TestFlight class (6 points) This class has been started for you and includes code that tests some of the functionality to be provided by your Flight class, including the following: - uses the no-arg constructor to create a Flight object populated with user-specified inputs - tests the getter methods and hasMeal method - uses the four-arg constructor to create a second Flight object - prints each flight (which automatically invokes the toString method) Read over and run the code included in class TestFlight to test the functionality of your Flight class again (you should have already added and run your own testing code in the main method of class Flight). Then add code after the “TO DO” comments appearing in class TestFlight to provide the following functionality: 1. Call the connects method to determine if the two flights connect. Print either “Connecting” or “Not connecting,” depending on the value returned by your method call. 2. Call the longer method to determine which if either flight has the longer duration. Then print the flight code for the longer flight followed by “is longer” or print “Same duration,” depending on the value returned by your method call. CS180 Spring 2020 Hw 6 3 Following are sample interactions, with user input shown in boldface, that show the output from running the completed TestFlight class: Sample 1: Enter the flight code: jva2332 Enter the departure city: Nome Enter the destination city: New York City Enter the flight duration in minutes: 985 Output using get methods and hasMeal: Flight1: JVA2332 NOME NEW YORK CITY 985 true Descriptions generated by toString: Flight code: JVA2332 Departure: NOME Destination: NEW YORK CITY Duration: 985 minutes Meal included Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 0 minutes No meal After resetting duration of second flight: Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 300 minutes Meal included Output from additional testing code: Not connecting JVA2332 is longer Sample 2: Enter the flight code: sjva237 Enter the departure city: newark Enter the destination city: boston Enter the flight duration in minutes: 77 Output using get methods and hasMeal: Flight1: JVA000 NEWARK BOSTON 77 false Descriptions generated by toString: Flight code: JVA000 Departure: NEWARK Destination: BOSTON Duration: 77 minutes No meal Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 0 minutes No meal After resetting duration of second flight: Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 300 minutes Meal included Output from additional testing code: Connecting JVA234 is longer CS180 Spring 2020 Hw 6 4 Sample 3: Enter the flight code: jv Enter the departure city: st. louis Enter the destination city: louisville Enter the flight duration in minutes: 300 Output using get methods and hasMeal: Flight1: JVA000 ST. LOUIS LOUISVILLE 300 true Descriptions generated by toString: Flight code: JVA000 Departure: ST. LOUIS Destination: LOUISVILLE Duration: 300 minutes Meal included Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 0 minutes No meal After resetting duration of second flight: Flight code: JVA234 Departure: BOSTON Destination: ST. LOUIS Duration: 300 minutes Meal included Output from additional testing code: Not connecting Same duration 3. Grading Your programs must compile and