In: Computer Science
An auto company produced some models of cars that may be difficult to drive because the car wheels are not exactly round. Cars with model numbers 119, 179, 189 through 195, 221, and 780 have been found to have this defect. Create a CarRecall application that prompts a customer for the model number of their car to find out if it is defective and then displays “Your car is not defective.” when the user typed a model number without a defect. Otherwise, the message “Your car is defective. It must be repaired.” should be displayed. Application output should look similar to:
Enter the car's model number: 191
Your car is defective. It must be repaired.
Must be coded in Java.
Has to be easy code so no keyboard or any advanced coding.
Easiest code must be used for a grade 11 comp sci class I just started
Code:
import java.util.Scanner;/*importing the scanner class*/
class car
{
public static void main(String[] args)
{
int carNum;/*Declared a variable
carNum*/
Scanner scnr=new
Scanner(System.in);/*Creating scanner object*/
System.out.print("Enter the car's
model number:");
carNum=scnr.nextInt();/*Reading the
car model number*/
if(carNum==119 || carNum==179
||(carNum>=189 &&
carNum<=195)||carNum==221||carNum==780)
{/*If car model numbers matches the
above model numbers then we print it is defective*/
System.out.print("Your car is defective. It must be
repaired.");
}
else
{
/*Else we print
it is not deffective*/
System.out.print("Your cat is not defective");
}
}
}
Output:
Indentation;