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

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....
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....
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...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc != 2) || (sscanf(argv[1],"%d",&count) != 1)) { fprintf(stderr,"Usage: %s <integer>\n", argv[0]); exit(1); } pid_t pid1, pid2; while (count > 0) { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); count = count - 2; } else if (pid1 == 0) { count = count - 1; } } exit(0); } Question #1 [2 pts] If the command-line argument passed to this...
Write a method with the following header: public static char calculateLetterGrade(int grade, int totalMarks) This method...
Write a method with the following header: public static char calculateLetterGrade(int grade, int totalMarks) This method calculates grade/totalMarks and returns a letter grade based on the following scale: 0-50 = F 51-60 = D 61-70 = C 71-80 = B 81-100 = A
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10];...
#include #include #include int main(void) { int feof(FILE *stdin); int i, num; int binary[10]; char input[10]; printf("Starting the CPSC 1011 Decimal to Binary Converter!\n"); while(1) {    i=0;    printf("\nPlease enter a positive whole number (or EOF to quit): ");    scanf("%s", input); // user inputs value as a string for separate values    if(strcmp(input,"")==0) {        printf("\n\tThank you for using the CPSC 1011 Decimal to Binary Generator.\nGoodbye!\n\n");    return(0); } num=atoi(input); if (num<=0) {    printf("\n\tSorry, that was...
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT