Question

In: Computer Science

Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without...

Write multiple if statements:
If carYear is before 1967, print "Probably has few safety features." (without quotes).
If after 1971, print "Probably has head rests.".
If after 1992, print "Probably has anti-lock brakes.".
If after 2000, print "Probably has tire-pressure monitor.".
End each phrase with period and newline. Ex: carYear = 1995 prints:

Probably has head rests.
Probably has anti-lock brakes.

public class SafetyFeatures {
public static void main (String [] args) {
int carYear;

carYear = 1968;

Solutions

Expert Solution

Screenshot of the code:

Sample Output:

//Here the sample output will be nothing as the carYear=1968 does not satisfy any of the 'if' condition

Code to copy:

public class SafetyFeatures

{

     

      public static void main (String [] args)

      {

            //Declare the variable carYear.

            int carYear;

            //Assign a value to the variable carYear.

            //Here, assign the value 1968 (according to the question).

            carYear = 1968;

           

            //If carYear is before 1967,

            //print "Probably has few safety features."

            if(carYear<1967)

                  System.out.println("Probably has few safety features. \n");

           

            //If carYear is after 1971,

            //print "Probably has head rests.".

            if(carYear>1971)

                  System.out.println("Probably has head rests. \n");

           

            //If carYear is after 1992,

            //print "Probably has anti-lock brakes.".

            if(carYear>1992)

                  System.out.println("Probably has anti-lock brakes.\n");

           

            //If carYear is after 2000,

            //print "Probably has tire-pressure monitor."

            if(carYear>2000)

                  System.out.println("Probably has tire-pressure monitor. \n");

           

      }

}

Scenario 2:

If the value of carYear is 1995, then the screenshot of the code and sample output is as follows:

Sample Output:

//Here the sample output will be according to the 'if' condition in which carYear>1992, so "Probably has anti-lock brakes" will be printed.

Code to copy:

public class SafetyFeatures

{

      

       public static void main (String [] args)

       {

             //Declare the variable carYear.

             int carYear;

             //Assign a value to the variable carYear.

             //Here, assign the value 1995.

             carYear = 1995;

            

             //If carYear is before 1967,

             //print "Probably has few safety features."

             if(carYear<1967)

                    System.out.println("Probably has few safety features. \n");

            

             //If carYear is after 1971,

             //print "Probably has head rests.".

             if(carYear>1971)

                    System.out.println("Probably has head rests. \n");

            

             //If carYear is after 1992,

             //print "Probably has anti-lock brakes.".

             if(carYear>1992)

                    System.out.println("Probably has anti-lock brakes.\n");

            

             //If carYear is after 2000,

             //print "Probably has tire-pressure monitor."

             if(carYear>2000)

                    System.out.println("Probably has tire-pressure monitor. \n");

            

       }

}


Related Solutions

Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without...
Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has head rests.". If after 1991, print "Probably has anti-lock brakes.". If after 2002, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has head rests. Probably has anti-lock brakes. I want the answers in C++ not in java script data type
In java Write multiple if statements: If carYear is before 1967, print "Probably has few safety...
In java Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has head rests.". If after 1991, print "Probably has anti-lock brakes.". If after 2002, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints: Probably has head rests. Probably has anti-lock brakes. public class SafetyFeatures { public static void main (String [] args) { int carYear; carYear = 1991; *insert...
What probably happened that a government decided it needed to print the below banknote? (Write a...
What probably happened that a government decided it needed to print the below banknote? (Write a minimum of 100 words in your answer)
Write anoutput(number)functionthat printsout information according to the requirements below.-If numberis a multiple of 3and 4, print"Multiple...
Write anoutput(number)functionthat printsout information according to the requirements below.-If numberis a multiple of 3and 4, print"Multiple of 3 and 4". -If numberis onlya multiple of 4, print "Multiple of 4".-If numberis onlya multiple of 3, print "Multiple of 3". -If numberis not a multiple of 3or 4, print "Not a multiple of 3or 4" >>output(12)'Multiple of 3 and 4'>>>output(8)'Multiple of 4'>>>output(5)'Not a multiple of 3 or 4
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future"...
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline C++
5. Write a C++ statement or statements that will:       Print the first two digits and the  last...
5. Write a C++ statement or statements that will:       Print the first two digits and the  last two digits of any 4 digit number stored in an integer variable n.         For example, given int n = 5623, print 56    23. 6. Write  C++ statements that will align the following three lines as printed in two 20 character columns. Name                                                 Years President Abraham Lincoln                                 1860-1865 Thomas Jefferson                               1801-1809 7.  Write a C++ statement or statements that will Output if a string has a length greater than 10, equal...
/* Homework Lab 8 Nested If statements Write the nested decision logic to print the recommended...
/* Homework Lab 8 Nested If statements Write the nested decision logic to print the recommended meal based on the user's choices for Restaurant and Load given the table shown below: Restaurant Preference Meal ----------------------------------------------------- (M)cDonald's (B)eef Quarter Pounder            (C)hicken Chicken McNuggets            (F)ish Filet-o-Fish            (S)alad Side Salad (O)utback            (B)eef Ribeye            (C)hicken Alice Springs Chicken            (F)ish Grilled Tilapia            (S)alad Aussie...
The unprecedented Ebola outbreak probably has more virologists thinking about Ebola than ever before. And while...
The unprecedented Ebola outbreak probably has more virologists thinking about Ebola than ever before. And while scientists have learned a lot about this virus since it was discovered almost four decades ago, there's still a lot left to wonder about. Pick an aspect of Ebola and share your research with other students. You may want to research and discuss: 1. What is the reservoir for the Ebola virus? Can it spread to household pets? 2. What cells does it attack...
8a)If Vaughn Ltd. has a margin of safety of $113000, which of the following statements is...
8a)If Vaughn Ltd. has a margin of safety of $113000, which of the following statements is correct? a. Sales can increase by $113000 before Vaughn have an operating loss. b. Sales can increase by $56500, and fixed costs can decrease by $56500 before Vaughn have an operating loss. c. Fixed costs can increase by $113000 before Vaughn have an operating loss. d. Sales can decrease by $56500 and fixed costs can increase by $45200 before Vaughn have an operating loss....
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print all elements of a linked list in order. B. Method to print all elements of a linked list in reverse order. C. Method to print all elements of a linked list in order starting from specific position. D. Method to join two linked lists into the first list in the parameters. E. Method to clone a linked list. The copy list has to be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT