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

in java Design and implement a class called Dog that contains instance data that represents the...
in java Design and implement a class called Dog that contains instance data that represents the dog’s name and age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in “person years” (seven times the dog’s age). Include a toString method that returns a one-line description of the dog. Create a Tester class called Kennel, whose main...
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...
In Java, design and implement a class called Cat. Each Cat class will contain three private...
In Java, design and implement a class called Cat. Each Cat class will contain three private variables - an integer representing its speed, a double representing its meowing loudness, and a String representing its name. Using the Random class, the constructor should set the speed to a random integer from 0 to 9, the meowing loudness to a random double, and the name to anything you want; the constructor should take no parameters. Write “get” and “set” methods for each...
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...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class...
JAVA PROGRAM 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,...
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; };...
Based on a Node class; Use Java to implement the OrderedList class which represents an ordered...
Based on a Node class; Use Java to implement the OrderedList class which represents an ordered singly linked list that cannot contain any duplicates. Note that items in the OrderedList are always kept in descending order. Complete the class with the following methods. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the list at the proper location in the list. If the insertion is successful, the function returns true; otherwise,...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT