Write a Java program that determines the total price to rent

Write a Java program that determines the total price to rent a car based on certain perameters which the user will specify using their keyboard:

- The desired car size (full or economy)

- The desired color of the car (black, white, or red)

- The desired number of days to rent

The daily and weekly rates for cars that are black and white are determined from the following: (There is no difference for the rental rates between black and white cars. *Red cars have a 15% upcharge from the below prices.)

If the user specifies a number of days to rent that is not evenly divisible by 7 (i.e., is not a whole number of weeks), then give them the weekly rate for the number of complete weeks, plus whatever rate is more favorable based on the number of days remaining vs. one additional week.

Calculate the best rate for the inputted time.

**Use at least one if-else or if statement.

**Use at least one switch / case statement.

**Use constants.

Example Outputs:

Quote for a white, full-sized car for 9 days:

Your best rate is 1 week at $216.25/week + 2 days at $39.40/day, total $295.05

Daily Weekly
Economy 25.50 120.50
Full-size 39.40 216.25

Solution

CarEstimation.java

import java.util.Scanner;


public class CarEstimation {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println(\"Enter the desired car size (full or economy): \");
       String size = scan.next();
       System.out.println(\"Enter the desired color of the car (black, white, or red): \");
       String color = scan.next();
       System.out.println(\"Enter the desired number of days to rent: \");
       int days = scan.nextInt();
       int weeks = days / 7;
       days = days % 7 ;
       double weekAmount = 0;
       double dayAmount = 0;
       final double ECONOMY_CAR_CHARGE_DAILY = 25.50;
       final double ECONOMY_CAR_CHARGE_WEEKLY = 120.50;
       final double FULL_SIZE_CAR_CHARGE_DAILY = 39.40;
       final double FULL_SIZE_CAR_CHARGE_WEEKLY = 216.25;
       final int RED_CAR_PERCENTAGE = 15;
       int percentage = 0;
       if(size.equalsIgnoreCase(\"Economy\")){
           dayAmount = ECONOMY_CAR_CHARGE_DAILY;
           weekAmount = ECONOMY_CAR_CHARGE_WEEKLY ;
       }
       else{
           dayAmount = FULL_SIZE_CAR_CHARGE_DAILY;
           weekAmount = FULL_SIZE_CAR_CHARGE_WEEKLY;
       }
       char ch = color.charAt(0);
       switch(ch){
       case \'r\':
       case \'R\':percentage = RED_CAR_PERCENTAGE; break;
       case \'b\':
       case \'B\':percentage = 0; break;
       case \'w\':
       case \'W\':percentage = 0; break;
       default: percentage = 0;
       }
       double rate = weeks * weekAmount + days * dayAmount;
double additionalCharge = (rate * percentage)/100;
double finalRate = rate + additionalCharge;
       System.out.println(\"Your best price total is $\"+finalRate);
   }

}

output:

Enter the desired car size (full or economy):
economy
Enter the desired color of the car (black, white, or red):
white
Enter the desired number of days to rent:
12
Your best price total is $248.0

Enter the desired car size (full or economy):
full
Enter the desired color of the car (black, white, or red):
black
Enter the desired number of days to rent:
9
Your best price total is $295.05

Write a Java program that determines the total price to rent a car based on certain perameters which the user will specify using their keyboard: - The desired c
Write a Java program that determines the total price to rent a car based on certain perameters which the user will specify using their keyboard: - The desired c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site