Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import javax.swing.JOptionPane; public class CarRent { public static void main(S

ID: 3630271 • Letter: I

Question

import javax.swing.JOptionPane;

public class CarRent
{
public static void main(String[] args)
{

char carType = ' ';
double rentDays = 0.0, startOdometer = 0.0,
endingOdometer = 0.0, totalMileage = 0.0, carRented = 0.0;
String inputString;

// Get type of car, days rented, starting odometer and ending

inputString = JOptionPane.showInputDialog("Which Car Class is the rental: C - Compact M - Midsize F - Full Size L - Luxury Enter C,M,F,or L");
carClass = Char.parseChar(inputString);

inputString = JOptionPane.showInputDialog("how many days was teh car Rented?");
rentDays = Double.parseDouble(inputString);

inputString = JOptionPane.showInputDialog("Enter the starting odometer reading.");
startOdometer = Double.parseDouble(inputString);

inputString = JOptionPane.showInputDialog("Enter the ending odometer reading");
endingOdometer = Double.parseDouble(inputString);

totalMileage = endingOdometer - startOdometer;
// calculate total mileage

// Calculate total cost

if (carType == 'C')
{
carType = Compact;
carRented = 9.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType == 'M')
{
carType = Midsize;
carRented = 13.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType == 'F')
{
carType = Fullsize;
carRented = 19.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType == 'L')
{
carType = Luxury;
carRented = 23.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else // If character is not entered correctly
{
JOptionPane.showMessageDialog(null, "Please enter Capital C,M,F, or L");
}




JOptionPane.showMessageDialog(null, "Rental Class: " + carType +
" Days Rented: " + rentDays + " Total Mileage: " + totalMileage + " totalCost: $" +
carRented);

System.exit(0);
}
}

Explanation / Answer

if (carType.equals("C"))
{
carType = "Compact";
carRented = 9.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType.equals ("M"))
{
carType = "Midsize";
carRented = 13.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType.equals ("F"))
{
carType = "Fullsize";
carRented = 19.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else if (carType.equals ("L"))
{
carType = "Luxury";
carRented = 23.00 * rentDays * (0.20 * (totalMileage - (200 * rentDays)));
}
else // If character is not entered correctly
{
JOptionPane.showMessageDialog(null, "Please enter Capital C,M,F, or L");
}

JOptionPane.showMessageDialog(null, "Rental Class: " + carType +
" Days Rented: " + rentDays + " Total Mileage: " + totalMileage + " totalCost: $" +
carRented);
System.exit(0);
}
}