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

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; };...
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...
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...
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...
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...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement...
In java design and code a class named comparableTriangle that extends Triangle and implements Comparable. Implement the compareTo method to compare the triangles on the basis of similarity. Draw the UML diagram for your classes. Write a Driver class (class which instantiates the comparableTriangle objects) to determine if two instances of ComparableTriangle objects are similar (sample output below). It should prompt the user to enter the 3 sides of each triangle and then display whether or not the are similar...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
(JAVA) Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented. NumericAnalyzer...
(JAVA) Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented. NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric values do not need to be ordered (although you’ll need to display these values sorted ascendingly). NOTE: Don’t prompt the user for input – this is an exercise passing values to your program via the command line! Error checking: if the user fails to pass in parameters, the program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT