166k views
0 votes
Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has seat belts." If 1990 or later, print "Probably has antilock brakes." If 2000 or later, print "Probably has airbags." End each phrase with a period and a newline. Sample output for input: 1995 Probably has seat belts. Probably has antilock brakes.

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class Hggg {

public static void main (String [] args) {

System.out.println("Enter the car make year");

Scanner in = new Scanner(System.in);

int car_year = in.nextInt();

if (car_year<1969){

System.out.println("Few safety features.");

}

else if (car_year>=1970 && car_year<1990){

System.out.println("Probably has seat belts.");

}

else if (car_year>=1990 && car_year<2000){

System.out.println("Probably has seat belts.");

System.out.println("Probably has antilock brakes.");

}

else if (car_year>=2000){

System.out.println("Probably has seat belts.");

System.out.println("Probably has antilock brakes.");

System.out.println("Probably has airbags.");

}

}

}

Step-by-step explanation:

In this solution, multiple if statements have been used to accomplish each step. Observe that there are more than one print statements when year is greater than 1990 because the condition applied to year greater than 1970 holds true for every year greater than 1970 (1990, 2000 etc)

User Torfi
by
4.8k points