An upstart rental car company would like you to write a program to generate rent
ID: 3751140 • Letter: A
Question
An upstart rental car company would like you to write a program to generate rental car bills The company only offers compact size and full size cars, with the following car charges: Compact Full size $19.99 per day + $4.99 per day for unlimited mileage $29.99 per day for the car S5.99 per day for unlimited mileage When the customer chooses unlimited mileage, there are no additional mileage charges Otherwise, these daily rates include 80 miles per day. When the customer goes over 80 miles per day, the customer must pay additional mileage charges of 9 cents for each mile over the included miles Cars rented for more than a week will get one day free per full week (7 days) rented, valid on car charges only (not mileage charges) Implementation Requirements The program will be written in NetBeans Create a new project named with a main class name of: Topic8project RentalCarBillGenerator . Within your program code, you must Include a complete JavaDoc program description and author/version tag at the top of the file Include JavaDoc comments above each defined method, including a method description and @param and @return tags for parameters and return values Define and use constants for ALL fixed prices and the included miles per day (so there should be no hardcoded values in the program calculations). Store values individually-not sums Instead of defining all constants in the main method, each constant should be defined within the method that uses it o Follow all other CS210 Coding Standards From the main method First display a one line program header to the user Then prompt for and read the following inputs from the user: . o o o The car size: C for compact or F for full size, converted to uppercase when reading The number of days rented Unlimited mileage (Y or N), converted to lowercase when reading Create a Boolean variable that will hold true when the user chooses unlimited mileage and set its value, according to the customer's input -Explanation / Answer
package org.students;
import java.util.Scanner;
public class RentalCarBillGenerator {
public static void main(String[] args) {
//Declaring variables
char size,unlimited;
int noOfDays,noOfMilesDriven;
boolean b=false;
double mileageCharges=0,carCharges=0;
//Declaring and initializing an array
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.println("::Rental Car Company ::");
//Getting the input entered by the user
System.out.print("Enter Car size (C=Compact / F=Full Size):");
size=sc.next(".").charAt(0);
size=Character.toUpperCase(size);
System.out.print("No of days rented :");
noOfDays=sc.nextInt();
System.out.print("Unlimited Mileage (Y =yes / N=no):");
unlimited=sc.next(".").charAt(0);
unlimited=Character.toUpperCase(unlimited);
if(unlimited=='Y')
b=true;
if(!b)
{
System.out.print("No of miles driven :");
noOfMilesDriven=sc.nextInt();
}
else
{
noOfMilesDriven=0;
}
carCharges=calculateCarCharges(size,b,noOfDays);
if(!b)
{
mileageCharges=calculateMileageCharges(noOfMilesDriven,noOfDays);
}
rentalSummary(size,noOfDays,noOfMilesDriven);
displayBill(carCharges,mileageCharges);
}
private static void displayBill(double carCharges, double mileageCharges) {
System.out.println(" RENTAL BILL");
System.out.printf("Car Charges %.2f ",carCharges);
if(mileageCharges>0)
{
System.out.printf("Rental Charges %.2f ",mileageCharges);
System.out.println(" ----------------");
System.out.printf(" Total %.2f ",carCharges+mileageCharges);
}
}
private static void rentalSummary(char size, int noOfDays,
int noOfMilesDriven) {
final String C="compact";
final String F="full size";
final String U="unlimited";
System.out.println(" RENTAL SUMMARY");
if(size=='C')
System.out.println("Car Size: "+C);
else
System.out.println("Car Size: "+F);
System.out.println("Days rented: "+noOfDays);
if(noOfMilesDriven>0)
System.out.println("Miles driven: "+noOfMilesDriven);
else
System.out.println("Miles driven: "+U);
}
private static double calculateMileageCharges(int noOfMilesDriven,
int noOfDays) {
final double PERMILE=.09;
double milCharges=0;
if(noOfMilesDriven>80)
{
milCharges=(noOfMilesDriven-80)*PERMILE;
}
return milCharges;
}
private static double calculateCarCharges(char size, boolean b, int noOfDays) {
final double CPERDAY=19.99 ;
final double FPERDAY=29.99 ;
final double CUNLIMITED=4.99 ;
final double FUNLIMITED=5.99 ;
double carCharges=0;
if(size=='C')
{
if(b)
carCharges=noOfDays*(CPERDAY+CUNLIMITED);
else
carCharges=noOfDays*CPERDAY;
}
else if(size=='F')
{
if(b)
carCharges=noOfDays*(FPERDAY+FUNLIMITED);
else
carCharges=noOfDays*FPERDAY;
}
return carCharges;
}
}
________________________
Output:
::Rental Car Company ::
Enter Car size (C=Compact / F=Full Size):c
No of days rented :10
Unlimited Mileage (Y =yes / N=no):n
No of miles driven :1200
RENTAL SUMMARY
Car Size: compact
Days rented: 10
Miles driven: 1200
RENTAL BILL
Car Charges 199.90
Rental Charges 100.80
----------------
Total 300.70
_______________
Output#2:
::Rental Car Company ::
Enter Car size (C=Compact / F=Full Size):f
No of days rented :6
Unlimited Mileage (Y =yes / N=no):y
RENTAL SUMMARY
Car Size: full size
Days rented: 6
Miles driven: unlimited
RENTAL BILL
Car Charges 215.88
________Could you plz rate me well.Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.