JAVA Recall 2! USING IF STATEMENT Write a program that reads a single token stri
ID: 3727521 • Letter: J
Question
JAVA
Recall 2! USING IF STATEMENT
Write a program that reads a single token string that represents a car model (e.g. toyota, ford, fiat) and an integer representing a year. (In this case there are no prompts from the program.) The program prints out RECALL if the car was a chevrolet or oldsmobile and the year was either during 1987-1998 (inclusive) or in any odd-numbered year after 2004 and NO RECALL otherwise.REMINDER: the program's output are shown here in bold; the user's data entry is shown here in italics. Sample Interactive Run 1: chevrolet 1994 RECALL Sample Interactive Run 2: volvo 2009 NO RECALL Sample Interactive Run 3: honda 2009 NO RECALL Sample Interactive Run 4: oldsmobile 2001 NO RECALL
Explanation / Answer
CarRecallTest.java
import java.util.Scanner;
public class CarRecallTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the car model:");
String model = scan.next();
System.out.println("Enter the car year:");
int year = scan.nextInt();
if((model.equalsIgnoreCase("chevrolet") || model.equalsIgnoreCase("oldsmobile")) && ((year>=1987&&year<=1998)|| (year>2004 && year % 2 !=0))) {
System.out.println("RECALL");
} else {
System.out.println("NO RECALL");
}
}
}
Output:
Enter the car model:
chevrolet
Enter the car year:
1994
RECALL
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.