Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I created most of the code I just need help making the JUnit test. IT IS AT THE BOTTOM. (JAVA) Create JUnit Tests Create JUnit

I created most of the code I just need help making the JUnit test. IT IS AT THE BOTTOM. (JAVA)

  1. Create JUnit Tests
    1. Create JUnit Tests to test the budgetBalance methods in both the AllInclusive and ALaCarte classes.
    2. Test each method from polymorphically via an object variable that is of type Vacation.
    3. Review the JUnit API and documentation as since the budgetBalance method returns a double, you will need to use one of the assertEquals methods that handles doubles since doubles values may not be exact due to rounding errors.

Vacation.java:

public abstract class Vacation { private String destination; private double budget; public Vacation(){ super(); } public Vacation(String destination, double budget) { super(); this.destination = destination; this.budget=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; } public abstract double budgetBalance(); public abstract void printItem(); }

AlIInclusive.java:

//concrete class called AllInclusive that is a subclass of Vacation

//represents an all inclusive vacation like Sandals or Club Med. public class AllInclusive extends Vacation { private String brand; private int rating; private double price;

public AllInclusive() { super(); }

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 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; } public double budgetBalance() { double budgetBal = getBudget(); return budgetBal - price; } @Override public void printItem() { System.out.println("Your trip to, "+brand+" a "+ rating + " star resort at, "+getDestination()+" will cost $"+price ); System.out.println("Your budget for this trip was $"+getBudget()); if(budgetBalance()>0){ System.out.println("*The vacation is within your budget. the balance remaining is: $"+budgetBalance()); }else { System.out.println("*The vacation is not within your budget. the balance remaining is: $"+budgetBalance()); } System.out.println(" "); }

}

ALaCarte.java:

//concrete class called ALaCarte that is a subclass of Vacation //represents a vacation that requires payment for each activity separately public class ALaCarte extends Vacation{ private String hotelName; private double roomCost; private String airline; private double airfair; private double meals; public ALaCarte() { super(); } public ALaCarte(String destination, double budget, String hotelName, double roomCost, String airline, double airfair, double meals) { super(destination, budget); this.hotelName = hotelName; this.roomCost = roomCost; this.airline = airline; this.airfair = airfair; this.meals = meals; }

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 getAirfair() { return airfair; }

public void setAirfair(double airfair) { this.airfair = airfair; }

public double getMeals() { return meals; }

public void setMeals(double meals) { this.meals = meals; } public double budgetBalance() { double budgetBal = getBudget(); double total = airfair+meals+roomCost; return budgetBal - (total); } @Override public void printItem() { System.out.println("Your trip to "+getDestination()+" resort at "+hotelName+" will cost $"+(airfair+roomCost)+" not including meals,"); System.out.println("which will cost an additional $"+meals); System.out.println("You will arrive via " +airline+" which will cost an additional $"+airfair); System.out.println("Your budget for this trop was $"+getBudget()); if(budgetBalance()>0){ System.out.println("*The vacation is within your budget. the balance remaining is: $"+budgetBalance()); }else { System.out.println("*The vacation is not within your budget. the balance remaining is: $"+budgetBalance()); } System.out.println(" "); } } VacationTester.java:

import java.util.ArrayList;

public class VacationTester {

public static void main(String[] args) { AllInclusive vac1; ALaCarte vac2;

ArrayList vacationList = new ArrayList(); vac1 = new AllInclusive(); vac1.setDestination("The Bahamas"); vac1.setBudget(2000.0); vac1.setBrand("Sandals"); vac1.setRating(5); vac1.setPrice(550.0); vac2 = new ALaCarte(); vac1.setDestination("Hawaii"); vac2.setBudget(700.0); vac2.setHotelName("Ocean Waves"); vac2.setRoomCost(500.0); vac2.setAirline("American Airlines"); vac2.setAirfair(300.0); vac2.setMeals(100.0); vacationList.add(vac1); vacationList.add(vac2); for (int i = 0; i vacationList.get(i).printItem(); // Calls correct printItem() } } }

JUnitVacationClass.java: (NEED HELP COMPLETING THIS)

import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;

import org.junit.jupiter.api.Test; //Create JUnit Tests to test the budgetBalance methods in both the AllInclusive and ALaCarte classes. //Test each method from polymorphically via an object variable that is of type Vacation. class JUnitVacationClass {

AllInclusive a1 = new AllInclusive("Hawaii", 1000.00, "Sandals", 5, 1450.00); ALaCarte s1 = new ALaCarte("Hawaii", 1000.00, "Tony's", 450.00, "American", 350.00, 200.00); @Test void testMethods() { } //use one of the assertEquals methods that handles doubles since doubles //values may not be exact due to rounding errors. }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

What is the mode?

Answered: 1 week ago

Question

75. Let a1 Answered: 1 week ago

Answered: 1 week ago