Write a class named UsedCarClassifier whose main method contains variables speci
ID: 3871846 • Letter: W
Question
Write a class named UsedCarClassifier whose main method contains variables specifying a car's total mileage, whether it was driven in the city or in the suburbs, and whether its engine was rebuilt. The main method also has a String variable containing the vehicle's classification as either Beater, "Average", or "Creamputr A car driven in the suburbs with more than 100,000 total miles is considered a Beater with less than 20,000 miles is a Creampuff. A car driven in the city with more than 70,000 milles is a Beater, and with less than 10,000 miles is a Creampufr. A car whose mileage is in between the two extremes is considered "Average. Regardless of where it was driven, a car whose engine was rebuilt and has less than 120,000 miles is considered "Average Implement the above logic and display the vehicle's classification.Explanation / Answer
Here the vehicle Classifier ::
import javax.swing.JOptionPane;
public class UsedCarClassifier {
public static String classifyVehicle(String location, String mileage, String engineCondition) {
Integer mileageInt = Integer.parseInt(mileage);
String classification = null;
if ("suburbs".equalsIgnoreCase(location)) {
if (mileageInt >= 100000) {
classification = "Beater";
} else if (mileageInt <= 20000) {
classification = "CreamPuff";
} else {
classification = "Average";
}
}
if ("city".equalsIgnoreCase(location)) {
if (mileageInt >= 70000) {
classification = "Beater";
} else if (mileageInt <= 10000) {
classification = "CreamPuff";
} else if (mileageInt > 10000 && mileageInt < 70000) classification = "Average";;
}
if ("rebuilt".equalsIgnoreCase(engineCondition)) {
if (mileageInt < 120000) {
classification = "Average";
}
}
return classification;
}
public static void main(String[] args) {
// Getting Mileage fron user using JoptionPane
String mileage;
mileage = JOptionPane.showInputDialog(" Totla mileage ");
//Getting DriveLocation from user using JoptionPane
String driveLoc;
driveLoc = JOptionPane.showInputDialog(" where it was driven all these time? [city or suburb]");
//Getting engineCondition from user using JOptionpane
String engineCondition;
engineCondition = JOptionPane.showInputDialog("Was the engine rebuilt?");
String vehicleClassification;
// Calculating and determining the vehicle
vehicleClassification = classifyVehicle(driveLoc, mileage, engineCondition);
//Displaying the Classification
System.out.println("Vehicle classified as : " + vehicleClassification);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.