7.14 Programming Activity 2: Writing a Class Definition, Part 2 In this programming activity, you will complete the definition of the Airport class. Then you will run a prewritten client program that...

1 answer below »
Please see attachment. I am using NetBeans
I am trying to attach a file, but I'm not having any success.


7.14 Programming Activity 2: Writing a Class Definition, Part 2 In this programming activity, you will complete the definition of the Airport class. Then you will run a prewritten client program that instantiates several Airport objects, calls the methods that you have written, and displays the values of the objects’ data. Copy into a folder on your computer all the files from this chapter’s Programming Activity 2 folder in the supplied code files. Note that all files should be in the same folder. Load the Airport.java source file; you’ll notice that the class already contains the class definition from Programming Activity 1. Your job is to complete the class definition by adding a static class variable (and its supporting code) and writing the toString and equals methods. It is important to define the static class variable and the methods exactly as described in the comments, because the AirportDrawing class will call each method to test its implementation. Searching for five asterisks in a row (*****) will position you at the six places in the class definition where you will add your code. The Airport.java code is shown here in Example 7.20: EXAMPLE 7.20 The Airport.java File 1 /* Airport class 2 Anderson, Franceschi 3 */ 4 5 public class Airport 6 { 7 8 // instance variables 9 private String airportCode; 10 private int gates; 11 12 // 1. ***** Add a static class variable ***** 13 // countAirports is an int 14 // assign an initial value of 0 15 16 17 // 2. ***** Modify this method ***** 18 // Default constructor: 19 // method name: Airport 20 // return value: none 21 // parameters: none 22 // function: sets the airportCode to an empty String 23 // ***** add 1 to countAirports class variable 24 public Airport( ) 25 { 26 airportCode = ""; 27 28 } 29 30 // 3. ***** Modify this method ***** 31 // Overloaded constructor: 32 // method name: Airport 33 // return value: none 34 // parameters: a String airport code and an int startGates 35 // function: assigns airportCode the value of the 36 // startAirportCode parameter; 37 // calls the setGates method, 38 // passing the startGates parameter 39 // ***** add 1 to countAirports class variable 40 public Airport( String startAirportCode, int startGates ) 41 { 42 airportCode = startAirportCode; 43 setGates( startGates ); 44 45 } 46 47 // Accessor method for the airportCode instance variable 48 // method name: getAirportCode 49 // return value: String 50 // parameters: none 51 // function: returns airportCode 52 public String getAirportCode( ) 53 { 54 return airportCode; 55 } 56 57 // Accessor method for the gates instance variable 58 // method name: getGates 59 // return value: int 60 // parameters: none 61 // function: returns gates 62 public int getGates( ) 63 { 64 return gates; 65 } 66 67 // 4. ***** Write this method ***** 68 // Accessor method for the countAirports class variable 69 // method name: getCountAirports 70 // return value: int 71 // parameters: none 72 // function: returns countAirports 73 74 75 76 77 // Mutator method for the airportCode instance variable 78 // method name: setAirportCode 79 // return value: Airport 80 // parameters: String airportCode 81 // function: assigns airportCode the value of the 82 // airportCode parameter 83 public Airport setAirportCode( String airportCode ) 84 { 85 this.airportCode = airportCode; 86 return this; 87 } 88 89 // Mutator method for the gates instance variable 90 // method name: setGates 91 // return value: Airport 92 // parameters: int gates 93 // function: validates the gates parameter. 94 // if gates is greater than 0, sets gates to gates; 95 // otherwise, does not change value of gates 96 public Airport setGates( int gates ) 97 { 98 if ( gates >= 0 ) 99 this.gates = gates; 100 return this; 101 } 102 103 // 5. ***** Write this method ***** 104 // method name: toString 105 // return value: String 106 // parameters: none 107 // function: returns a String that contains the airportCode 108 // and gates 109 110 111 112 113 114 115 // 6. ***** Write this method ***** 116 // method name: equals 117 // return value: boolean 118 // parameter: Airport object 119 // function: returns true if airportCode 120 // and gates in this object 121 // are equal to those in the parameter object; 122 // returns false otherwise 123 124 125 126 127 128 129 130 } // end of Airport class definition When you finish modifying the Airport class, compile the source file. When Airport.java compiles without any errors, load and compile the AirportPractice2Application.java file. This source file contains main, so you will execute the application from this file. When the application begins, you should see the window shown in Figure 7.14. Figure 7.14 AirportPractice2Application Opening Window As you can see, the client class has declared two Airport object references, airport1 and airport2. The references are null because no Airport objects have been instantiated. Note also that the value of the countAirports class variable is displayed. The client class will call methods of the Airport class to instantiate the two Airport objects, call the toString and equals methods, and get the value of the static class variable, countAirports. As the application does its work, it displays a status message at the bottom of the window indicating which method has been called, and it also displays the current state of the Airport objects. You can check your work by comparing the state of the objects with the status message.
Answered 4 days AfterMay 02, 2021

Answer To: 7.14 Programming Activity 2: Writing a Class Definition, Part 2 In this programming activity, you...

Pulkit answered on May 06 2021
151 Votes
82973_java/Airport.class
public synchronized class Airport {
private String airportCode;
private int gates;
private static int countAirports;
public void Airport();
public void Airport(String, int);
public String getAirportCode();
public int getGates();
public static int getCountAirports();
public Airport setAirportCode(String);
public Airport setGates(int);
public String toString();
public boolean equals(Airport);
static void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here