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 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; };...
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.
public class Flight extends java.lang.Object This class represents a single flight within the travel agency system....
public class Flight extends java.lang.Object This class represents a single flight within the travel agency system. Constructor Summary Constructors Constructor and Description Flight(java.lang.String airline, int flightNum, java.lang.String from, java.lang.String to, java.util.Calendar leavesAt, java.util.Calendar arrives, double price) Creates a new flight leg in the system. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description double getPrice() Retrieves the price of this flight. java.lang.String toString() Retrieves a formatted string summarizing this Flight. Methods inherited from class java.lang.Object...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT