Question
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
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Solution for the above question is Airport class Anderson Franceschi public class Airport instance variable private String airportCode private int gat...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started