Pseudocode : Write an abstract class called Vacation includes a budget and a des
ID: 3744686 • Letter: P
Question
Pseudocode :
Write an abstract class called Vacation includes a budget and a destination. It has an abstract method returning by how much the vacation is over or under budget. This class has two non-abstract subclasses:
All-Inclusive Vacation
brand (such as ClubMed, Delta Vacations, etc)
a rating (you can use # of stars)
price
Piecemeal Vacation
set of items (hotel, meal, airfare, etc)
set of corresponding costs (hotel cost, meal cost, airfare cost, etc.)
You need to write a test class to test all these classes and methods in each.
Explanation / Answer
Please find the steps to be followed for the requirement in the question.
Step 1: Create a class Vacation.
Step 2:Create two Inner Variables Budjet and Destination and an abstract Class method isOverOrUnderBudjet which takes budjet as a parameter.
Step 3: Create an inner class AllInclusiveVacation with brand,price and rating as items which extends its Parent class Vacation.
Step 4:Create a constructor of inner class AllInclusiveVacation to set all the items of class ,also create a method isOverOrUnderBudjet which determines whether a vacation is over/underpriced.
Step 3: Create an inner class PriceMealVacation with hotel,meals,airbus,hotelprice,mealsPrice,airbusprice as items which extends its Parent class Vacation
Step 4:Create a constructor of inner class PriceMealVacation to set all the items of class and user a map to set hotel with required hotelprice(meal with required mealprice and airbus with required airbus price), then it sums all the required prices and returns totalPrice of the vacation. also create a method isOverOrUnderBudjet which determines whether a vacation is over/underpriced.
Step 5.Write a main method to test all the functionalities.
Please find the java Implemention of the same
package com.abc.common;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
public abstract class Vacation {
String budjet; //Create a vacation Class with two identifiers budjet and Destination which is an abstract Class
String Destination;
abstract boolean isOverOrUnderBudjet(String budjet); //an abstract mathod which determines //whether the vacation is over or under Budjet
static class AllInclusiveVacation extends Vacation { //Inner Class AllInclusiveVacation which extends Vacation
String brand;
String ratings;
String price;
AllInclusiveVacation(String brand, String ratings, String price) { //We define a constructor to set all the //variables of the inner Class AllInclusiveVacation
this.brand = brand; //this method
this.ratings = ratings;
this.price = price;
}
boolean isOverOrUnderBudjet(String Budjet) { //Method to determine whether the vacation is //Under or Over Budjet;
if (Double.parseDouble(this.price) > Double.parseDouble(Budjet)) {
return true;
} else
return false;
}
}
static class PriceMealVacation extends Vacation { //Inner Class PriceMealVacation which extends //Vacation
String Hotel;
String Meals;
String AirLine;
String hotelPrice;
String MealsPrice;
String AirFarePrice;
String totalPrice;
public PriceMealVacation(String Hotel,String Meals,String AirLine,String hotelPrice,String MealsPrice,String AirFarePrice) {// Method which instaniated all
//items of a class calculates a total Price and returns It.
this.Hotel=Hotel; this.Hotel=hotelPrice;
this.MealsPrice=MealsPrice;
this.Meals=Meals;
this.AirFarePrice=AirFarePrice;
this.AirLine=AirLine;
HashMap<String, String> price = new HashMap<>();
price.put(Hotel, hotelPrice);
price.put(Meals, MealsPrice);
price.put(AirLine, AirFarePrice);
Double totalPrice1 = 0.0;
for (String sio : price.keySet()) {
Double d = Double.parseDouble(price.get(sio));
totalPrice += d;
}
this.totalPrice = totalPrice1.toString();
}
boolean isOverOrUnderBudjet(String Budjet) { //Method to determine whether the vacation is Under //or Over Budjet;
if (Double.parseDouble(this.totalPrice) > Double.parseDouble(Budjet)) {
return true;
} else
return false;
}
}
public static void main(String args) throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String destination=br.readLine();//We take our preference of destination and budjet
String budjet=br.readLine();
Vacation v=new AllInclusiveVacation(destination, "4#", "4000"); //Initializing a subclass //AllInclusiveVacation from a parent Class
if(v.isOverOrUnderBudjet(budjet)==true) //Checking whether vacation is over or Under Priced
System.out.println("Over Budjet");
else
System.out.println("UnderBudjet");
Vacation V1=new PriceMealVacation("hotel","meal","airBus","hotelPrice","MealPrice","AirBusPrice"); //Initializing a subclass PriceMealVacation from a parent Class
if(V1.isOverOrUnderBudjet(budjet)==true)
System.out.println("Over Budjet");
else
System.out.println("UnderBudjet");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.