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

Write a class named UsedCarClassifier whose main method contains variables speci

ID: 3871412 • 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 "Creampuff is considered a "Beater" an moret miles is a "Beater" and with less than 10,000 miles is a Creampuff. A car whose mileage in between the two extremes is considered Average". Regard miles is considered Average Implement the a e logic and display the vehicle's classification

Explanation / Answer

Here is the code for you:

import java.util.*;
class UsedCarClassifier
{
    public static void main(String[] args)
    {
       int totalMileage;
       boolean cityDriven, rebuilt;
       String classification;
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the mileage of car: ");
       totalMileage = sc.nextInt();
       //Reads the input from the terminal.
       System.out.print("Is the city driven in city/suburb (1 for city, any other digit for suburb): ");
       int temp = sc.nextInt();
       if(temp == 1)
           cityDriven = true;
       else
           cityDriven = false;
       System.out.print("Is the car re-built (1 for Yes, any for No): ");
       temp = sc.nextInt();
       if(temp == 1)
           rebuilt = true;
       else
           rebuilt = false;
       //If driven in suburbs.
       if(cityDriven == false)
       {
          if(totalMileage > 100000)   //Beater if mileage greater than 100000      
              classification = "Beater";
          else if(totalMileage < 20000)   //Creampuff if mileage less than 20000
              classification = "Creampuff";
          else
              classification = "Average";   //Average otherwise.
       }
       else   //If driven in city.
       {
          if(totalMileage > 70000)   //Beater if mileage greater than 70000
              classification = "Beater";
          else if(totalMileage < 10000)   //Creampuff if mileage less than 10000
              classification = "Creampuff";
          else
              classification = "Average";   //Average otherwise.
       }
       if(rebuilt && totalMileage < 120000)     //If the car engine is rebuilt and mileage is less than 120000
           classification = "Average";       //Its an average.
       System.out.println("the car is a: " + classification);   //Print the classification to screen.
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote