Question

In: Computer Science

JAVA - Design and implement a class called Flight that represents an airline flight. It should...

JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight objects (at least 5).

Solutions

Expert Solution


class Flight{
        private String name;
        private String number;
        private String origin;
        private String destination;
        /**
         * @param aName
         * @param aNumber
         * @param aOrigin
         * @param aDestination
         */
        public Flight(String aName, String aNumber, String aOrigin, String aDestination) {
                super();
                name = aName;
                number = aNumber;
                origin = aOrigin;
                destination = aDestination;
        }
        /**
         * @return the name
         */
        public String getName() {
                return name;
        }
        /**
         * @return the number
         */
        public String getNumber() {
                return number;
        }
        /**
         * @return the origin
         */
        public String getOrigin() {
                return origin;
        }
        /**
         * @return the destination
         */
        public String getDestination() {
                return destination;
        }
        /**
         * @param aName the name to set
         */
        public void setName(String aName) {
                name = aName;
        }
        /**
         * @param aNumber the number to set
         */
        public void setNumber(String aNumber) {
                number = aNumber;
        }
        /**
         * @param aOrigin the origin to set
         */
        public void setOrigin(String aOrigin) {
                origin = aOrigin;
        }
        /**
         * @param aDestination the destination to set
         */
        public void setDestination(String aDestination) {
                destination = aDestination;
        }
        @Override
        public String toString() {
                return "Flight [name=" + name + ", number=" + number + ", origin=" + origin + ", destination=" + destination
                                + "]";
        }
        
}
public class FlightTest {
        public static void main(String[] args) {
                //creating 5 Flight objects
                Flight f1 = new Flight("AIR123", "12314", "Hyderabad", "AUS");
                Flight f2 = new Flight("JET123", "45435", "Bombay", "Newyork");
                Flight f3 = new Flight("JET123", "23413", "Chennai", "UK");
                Flight f4 = new Flight("IND123", "42323", "Hyderabad", "USA");
                Flight f5 = new Flight("IND123", "12312", "Banlgore", "Hyderabad");
                //printing 5 objects data
                System.out.println(f1);
                System.out.println(f2);
                System.out.println(f3);
                System.out.println(f4);
                System.out.println(f5);
                //updating flight data
                f5.setDestination("Begumpet");
                System.out.println(f5);
                
        }
}


Related Solutions

JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the following instance variables: employee’s name reportID: this should be unique. The first reportID must have a value of 1000 and for each new reportID you should increment by 10. hourly wage Include a suitable collection of constructors, mutator methods, accessor methods, and toString method. Also, add methods to perform the following tasks: Compute yearly salary - both the gross pay and net pay Increase...
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
Write a java class called circle that represents a circle. It should have following three fields:...
Write a java class called circle that represents a circle. It should have following three fields: int x (x-coordinate), int y (y-coordinate), double radius (radius of the circle). Your circle object should have following methods: public int getRadius () public int getX () public int getY () public double area () public double perimeter() public String toString() write a client program called CircleClient that creates objects of the circle class called c1 and c2. Assign values to the fields when...
Overview For this assignment, implement and use the methods for a class called Seller that represents...
Overview For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; };...
Overview For this assignment, implement and use the methods for a class called Seller that represents...
Overview For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; };...
Design and implement a class called circle_location to keep track of the position of a single...
Design and implement a class called circle_location to keep track of the position of a single point that travels around a circle. An object of this class records the position of the point as an angle, measured in a clockwise direction from the top of the circle. Include these public member functions: • A default constructor to place the point at the top of the circle. • Another constructor to place the point at a specified position. • A function...
For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.
For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.The Seller classUse the following class definition:class Seller { public:   Seller();   Seller( const char [], const char[], const char [], double );        void print();   void setFirstName( const char [] );   void setLastName( const char [] );   void setID( const char [] );   void setSalesTotal( double );   double getSalesTotal(); private:   char firstName[20];   char lastName[30];   char ID[7];   double salesTotal; };Data MembersThe data members for the class are:firstName holds the Seller's first namelastName holds the Seller's last nameID holds the Seller's id numbersalesTotal holds the Seller's sales totalConstructorsThis class has two constructors. The default constructor (the one that takes...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields Item Name Item Serial No Item Unit Price Item Stock Level Item Reorder Level It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level. b) Extend the Retail Item class of part a) above...
a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields  Item Name  Item Serial No  Item Unit Price  Item Stock Level  Item Reorder Level  It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.    b) Extend...
Implement Java source code for a class called Temperature that does the following: a. Prompts the...
Implement Java source code for a class called Temperature that does the following: a. Prompts the user to input a temperature b. Prints “Too Hot!” when the input temperature is above 75 c. Prints “Too Cold!” when the input temperature is below 40 d. Prints “Just Right!” when the input temperature is 40 to 75 e. Be precise, include comments, prologue, etc. if needed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT