Question

In: Computer Science

double calculateCost (char, int, int) with Drjava calculateCost will compute and return the cost of the...

double calculateCost (char, int, int) with Drjava
calculateCost will compute and return the cost of the vacation It will take as input 3 pieces of information. First, a char representing the type of room being rented (‘d’ double, ‘k’ kingsize, ‘p’ for penthouse). The second input is an int representing the number of days they will stay, the last input is an int representing the number of people staying.
To compute the cost of the stay we start with a base price, determined by the type of the room. Daily fee for the room: $15 for double, $20 for king size, $30 for penthouse. Only two people per room, add a $20 flat fee for each extra person for a folding bed.
If they stay more than 7 days there is a 10% discount, more than 14 days a 15% discount and more than 21 days a 20% discount.
Example: Ted, who is 23, is renting a penthouse for 12 days for a party with 5 of his best buds. He owes $30*12days + $20*3 extra people for the folding beds and he gets a discount of 10% because he is staying more than 7 days.

The total would be $360 + $60 is the total fee of $420
The discount is 10% so $42
The amount to pay is $420 - $42 is $378

Solutions

Expert Solution

Explanation:I have written the method ouble calculateCost (char, int, int) and have also shown the output by using the main method, please find the image attached with the answer.Please upvote if you liked my answer and comment if you need any modification or explanation.

//code

public class RoomCost {

   public double calculateCost(char type, int noOfDays, int noOfPeople) {
       double totalCost = 0;
       // room cost
       if (type == 'd') {
           totalCost += noOfDays * 15;
       } else if (type == 'k') {
           totalCost += noOfDays * 20;
       } else if (type == 'p') {
           totalCost += noOfDays * 30;
       }
       // folding bed cost
       if (noOfPeople > 2)
           totalCost += (20 * (noOfPeople - 2));
       // discount on stay
       if (noOfDays > 7 && noOfDays <= 14) {
           totalCost -= (0.10 * totalCost);
       } else if (noOfDays > 14 && noOfDays <= 21) {
           totalCost -= (0.15 * totalCost);
       } else if (noOfDays > 21) {
           totalCost -= (0.20 * totalCost);
       }
       return totalCost;

   }

   public static void main(String[] args) {
       RoomCost roomCost = new RoomCost();
       System.out.println(
               "The amount to pay is $" + roomCost.calculateCost('p', 12, 5));

   }

}

Output:


Related Solutions

boolean isEligibile (int, char, char) using Drjava isEligibile will return true when the customer is eligible...
boolean isEligibile (int, char, char) using Drjava isEligibile will return true when the customer is eligible to book a vacation package, and false otherwise. It takes as input 3 pieces of information, first an int representing the customer’s age. Second, a char representing the country where the rental is being made (‘c’ for Canada, ‘u’ for United States, ‘f’ for France). The third input is a char representing if the customer has a valid Canadian passport ‘y’ for Yes, ‘n’...
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char...
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char *state; int time_spent; }; Given Array: struct patients* patientsArray[4] = {&p1, &p2, &p3, &p4}; Create two functions one for pushing this array to the stack and one for popping the variables such as p1 p2 p3 p4 by its ID
int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1],...
int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1], O_RDONLY)) == -1) || ((fd2 = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0700)) == -1)){ perror("file problem "); exit(1); } while((n1=read(fd1, buffer, 512) > 0)) if(write(fd2, buffer, n1) != n1){ perror("writing problem "); exit(3); } // Case of an error exit from the loop if(n1 == -1){ perror("Reading problem "); exit(2); } close(fd2); exit(0); } Could anyone fix the two issues in the while loop, so the ouput can...
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; }...
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; } //same as fileSize except if the file is a directory then it recursively finds the size of directory and all files it contains unsigned int fileSizeRec(const char* name){     return 0; }
public static int punishOrMercy(char direction, int reward) Output: int which will be the value of zero...
public static int punishOrMercy(char direction, int reward) Output: int which will be the value of zero or the initial reward. Functionality: After the result of the reward function is stored, this function should be called. The goal of this function is to help the robot in case it faced a lot of damage in the current step. However, this function will help the robot only if the robot’s reward was negative and the direction that the user inputted was up....
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int...
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int i; for (i = 0; i < x; i++) { if (s[i] == ‘A’) { return power(10, i); } } return -1; } int power(int base, int i) { int j = 0; while (j < base) { base = base * base; j++; } return base; }
Write a function int strlen(char s1[]) which returns the length of the char array s1.
Write a function int strlen(char s1[]) which returns the length of the char array s1.
string getStyle() ; int getNumOfBedRooms() ; int getNumOfBathRooms(); int getNumOfCarsGarage(); int getYearBuilt(); int getFinishedSquareFootage() ; double...
string getStyle() ; int getNumOfBedRooms() ; int getNumOfBathRooms(); int getNumOfCarsGarage(); int getYearBuilt(); int getFinishedSquareFootage() ; double getPrice(double p) ; double getTax(double t) ; void print() ; houseType(); houseType(string s, int numOfBeds, int numOfBaths, int numOfCars, int yBuilt, int squareFootage, double p, double t); private: string style; int numOfBedrooms; int numOfBathrooms; int numOfCarsGarage; int yearBuilt; int finishedSquareFootage; double price; double tax; }; Questions a.Write the definition of the member function set so that private members are set accordingy to the parameters....
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;...
#include<iostream> using namespace std; int main() {    int number_resistors;    double Resistors;    double series;    double parellel;    cout << "how many resistors: ";    cin >> number_resistors;    while (number_resistors != 0)    {        cout << "Enter the values of" << number_resistors << " resistors ";        for (int i = 0; i < number_resistors; i++) {            cin >> Resistors;            series += Resistors;                parellel...
1.) Answer the following programs a.) Let f be the following function: int f(char *s, char...
1.) Answer the following programs a.) Let f be the following function: int f(char *s, char *t) {     char *p1, *p2;     for(p1 = s, p2 = t; *p1 != '\0'&& *p2 != '\0'; p1++, p2++){               if (*p1 == *p2) break;     }     return p1 -s; } What is the return value of f(“accd”, “dacd”)? b.) What will be the output of the below program? #include <stdio.h> int main()   {    char x[]="ProgramDesign", y[]="ProgramDesign";   if(x==y){   printf("Strings are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT