Question

Java Program Please help me with this. It should be pretty basic and easy but I...

Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you

Create a superclass called VacationInstance Variables

destination - String

budget - double

Constructors - default and parameterized to set all instance variables

Access and mutator methods

budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in the subclass so have it return Java's integer minimum value.

Create a concrete class called AllInclusive that represents an all inclusive vacation like Sandals or Club Med.Instance Variables

brand - String, such as Sandels , Club Med etc

rating - int, representing number of stars such as 5 star rating.

price - double, the total cost of the vacation

Constructor - default and parameterized to set all instance variables

Accessor and mutator methods

Overwritten budgetBalance method.

Create a concrete class called ALaCarte - a pay for each activity separately

Instance Variables

hotelName - String

roomCost - double

airline - String

airfare - double

meals - double - estimated total meal expenses.

Constructor - default and parameterized to set all instance variables

Accessor and mutator methods

Overwritten budgetBalance method.

Create a VacationTester class

Test all methods of both classes, however test methods in the superclass Vacation from either subclass object (AllInclusive or ALaCarte)

Polymorphically call the budgetBalance method by creating at least 2 object of each Vacation subclass, and place those object in a collection of the Vacation object.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Vacation class

package vacation;

public abstract class Vacation {

public Vacation(String destination, double budget) {

this.destination = destination;

this.budget = budget;

}

public Vacation() {

}

private String destination;

private double budget;

public String getDestination() {

return destination;

}

public void setDestination(String destination) {

this.destination = destination;

}

public double getBudget() {

return budget;

}

public void setBudget(double budget) {

this.budget = budget;

}

abstract public int budgetBalance();

}

AllInclusive class

package vacation;

public class AllInclusive extends Vacation {

public AllInclusive(String destination, double budget, String brand, int rating, double price) {

super(destination, budget);

this.brand = brand;

this.rating = rating;

this.price = price;

}

public AllInclusive() {

}

@Override

public int budgetBalance() {

return (int) (getBudget() - price);

}

public String getBrand() {

return brand;

}

public void setBrand(String brand) {

this.brand = brand;

}

public int getRating() {

return rating;

}

public void setRating(int rating) {

this.rating = rating;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

private String brand;

private int rating;

private double price;

}

ALaCarte class

package vacation;

public class ALaCarte extends Vacation {

private String hotelName;

private double roomCost;

private String airline;

private double airfare;

private double meals;

@Override

public int budgetBalance() {

double totalCost = roomCost + airfare + meals;

return (int) (getBudget() - totalCost);

}

public ALaCarte(String destination, double budget, String hotelName, double roomCost, String airline,

double airfare, double meals) {

super(destination, budget);

this.hotelName = hotelName;

this.roomCost = roomCost;

this.airline = airline;

this.airfare = airfare;

this.meals = meals;

}

public ALaCarte() {

}

public String getHotelName() {

return hotelName;

}

public void setHotelName(String hotelName) {

this.hotelName = hotelName;

}

public double getRoomCost() {

return roomCost;

}

public void setRoomCost(double roomCost) {

this.roomCost = roomCost;

}

public String getAirline() {

return airline;

}

public void setAirline(String airline) {

this.airline = airline;

}

public double getAirfare() {

return airfare;

}

public void setAirfare(double airfare) {

this.airfare = airfare;

}

public double getMeals() {

return meals;

}

public void setMeals(double meals) {

this.meals = meals;

}

}

VacationTester class

package vacation;

import java.util.ArrayList;

public class VacationTester {

public static void main(String args[]) {

AllInclusive allInclusive = new AllInclusive("Miami", 3500, "Sandals", 4, 4500);

ALaCarte aLaCarte = new ALaCarte("Miami", 3500, "Drive Sern", 2000, "Emirates", 800, 400);

System.out.println(" All Inclusive data : ");

System.out.println("Destination : " + allInclusive.getDestination());

System.out.println("Bugdet : " + allInclusive.getBudget());

System.out.println("Brand : " + allInclusive.getBrand());

System.out.println("Rating : " + allInclusive.getRating());

System.out.println("Price : " + allInclusive.getPrice());

System.out.println("Budget Balance : " + allInclusive.budgetBalance());

System.out.println("\n\n Ala Carte data : ");

System.out.println("Destination : " + aLaCarte.getDestination());

System.out.println("Bugdet : " + aLaCarte.getBudget());

System.out.println("Hotel Name : " + aLaCarte.getHotelName());

System.out.println("Room Cost : " + aLaCarte.getRoomCost());

System.out.println("Airline : " + aLaCarte.getAirline());

System.out.println("Airfare : " + aLaCarte.getAirfare());

System.out.println("Meals : " + aLaCarte.getMeals());

System.out.println("Budget Balance : " + aLaCarte.budgetBalance());

// Added both object in collection of super class

ArrayList<Vacation> vacationsList = new ArrayList<>();

vacationsList.add(allInclusive);

vacationsList.add(aLaCarte);

}

}

OUTPUT ::

Add a comment
Know the answer?
Add Answer to:
Java Program Please help me with this. It should be pretty basic and easy but I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship...

    using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship (all attributes private) String attribute for the name of ship float attribute for the maximum speed the of ship int attribute for the year the ship was built Add the following behaviors constructor(default and parameterized) , finalizer, and appropriate accessor and mutator methods Override the toString() method to output in the following format if the attributes were name="Sailboat Sally", speed=35.0f and year built of...

  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand...

    Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2.        Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3.        Create a get and set methods for instance variable model variable only. (2 Marks) 4.        Create PrintInfo() method which prints all three instance variables. (2 Marks) 5.        Create a subclass GasCar with instance variable TankSize (double).. (2...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT