Question: Program in Java. Consider the following class hierarchy where Vacation is an abstract superclass containing basic vacation data and methods. Vacation has two subclasses: one

Program in Java.
Consider the following class hierarchy where Vacation is an abstract superclass containing basic vacation data and methods. Vacation has two subclasses: one for All-Inclusive vacations (all costs included in the price) and one for Detailed vacations where hotel, airfare, meals, and transfers are considered separately. TrackVacations Main (args: String[]); void Vacation (Abstract Class *) # String: destination # String: departureDate # String: returnDate + Vacation Vacation (String destination, String departureDate, String returnDate) + getDestination(): String + getDepartureDate(): String + getReturnDate(): String + setDestination (String destination) : void + setDepartureDate(String departureDate): void + setReturnDate(String returnDate): void + toString(): String + getTotalCost(* : double AllInclusive Detailed brand: String - starRating: int - price: double + AllInclusive + AllInclusive(String destination, String departureDate, String returnDate, String brand) + getBrand(): String getRating : int + setBrand(String brand): void + setRating(int rating) : void + setPrice(double price) : void + toString(): String + get TotalCost(): double + I hotel: double airfare: double meals: double transfers: double + Detailed + Detailed(String destination, String departureDate, String returnDate, double hotel, double airfare, double meals, double transfers) get HotelCost(): double getAirfareCost(): double getMealCost(: double + getTransfersCost(): double set HotelCost(double hotel) : void setAirfareCost(double airfare) : void setMealCost(double meals) : void + setTransfersCost(double transfers) : void toString(): String + getTotalCost: double Part 1: Creating vacation objects You are to create the Vacation, All-Inclusive, and Detailed classes using the UML diagram on the previous page (retaining method names, etc.). Additional requirements: The Vacation class is abstract. The All-Inclusive and Detailed classes are non-abstract classes. The All-Inclusive and Detailed classes each contain a default constructor (no parameters) and a constructor with multiple parameters. Note the order of the data used as parameters. The abstract method in Vacation must be defined for both child classes: o All-Inclusive - this simply returns the price Detailed - this is a total of the hotel, airfare, meals, and transfers costs The toString() methods always return a string and never prints anything. They include all data from the class. Child classes will include data from the parent along with the child data. The toString() method for All-Inclusive class will convert the star rating to a string of "stars" along with the other data from the class. For example, a 3 star resort would have *** contained in the string it returns rather than the value 3. Part 2: Instantiate objects and display vacation data using the toString() methods You will use polymorphism via inheritance in this assignment. o O Create a driver class to create an array of 12 vacations. Populate the array with data as follows: 6 All-Inclusive vacations to various destinations. (Tests constructors and mutators.) 3 are instantiated with the default constructor (no parameters) and then the mutators are used to update the class data. Make sure the parent and child data are updated. 3 are instantiated with the constructor which has 4 parameters. Use the mutators for rating and price to update these data items. 6 Detailed vacations to various destinations. (Tests constructors and mutators.) 3 are instantiated with the default constructor (no parameters) and then the mutators are used to update the class data. Make sure the parent and child data are updated. 3 are instantiated with the constructor which has 7 parameters. Quality matters. Use realistic and meaningful test data. Test your driver by displaying each of the 12 vacations using a loop and the toString() method. (NOTE: this loop will remain in your final version of the driver.) Let's look at a similar example. Suppose you have an abstract parent class named Animal (similar to Vacation), and child classes called Chick, Cow, Dog, Pig and Horse. Look at the following code: Animal[] farmerBrownAnimals = new Animal[5]; farmer BrownAnimals [0] = new Chick(); farmer BrownAnimals [1] = new Cow(); farmer BrownAnimals [2] = new Dog(); farmer BrownAnimals [3] = new Pig(); farmer BrownAnimals [4] = new Horse(); Suppose each of the classes e a getAnimalSound() method which returns the sound the anima example, cow makes a "Moo" sound and a dog makes a "Woof" sound. Similarly, your vacations each have a getTotalCost() method as each vacation is priced differently. When the animal array is used, Java will use polymorphism to call the correct getAnimal Sound() method based upon the corresponding animal type. For example, would return a "Woof" sound (string) since this was a dog. farmer BrownAnimals [2].getAnimalSound(); The following loop would go through the array, retrieve each animal sound and display it on the screen. Each time the getAnimalSound() method is called, Java looks at the object type (Chick, Cow, Dog, Pig, or Horse) and get the correct getAnimalSound() method. This is using polymorphism to call the correct method. for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
