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.import java.util.Scanner;public class YearChecker {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int givenYear;givenYear = scnr.nextInt();

Question
Asked Feb 28, 2020
8 views

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.

import java.util.Scanner;

public class YearChecker {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int givenYear;

givenYear = scnr.nextInt();

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

The below given java program will obey the following rubrics:

  • Importing essential header files.
  • Declaring main class, YearChecker.
  • Declaring main method, in the main method instantiating Scanner class.
  • Displaying message to user to enter year.
  • Reading input form user.
  • Now checking the input against the given cases to display output to user.
  • First case is to, check that, if entered year is equal to or greater than 2101, if yes, then displaying message to user "Distant future.
  • In second case, checking that if the entered year is equal to or greater than 2001, if yes, then, displaying message to user "21st Century".
  • In third case, if entered year is equal to or greater than 1901, if yes, then displaying message to user "20st Century".
  • And if none of the case matches (i.e., the entered year is equal to or less than 1900), then displaying message to user "Long ago".
Step 2

Program code:

 

//importing essential header file

import java.util.Scanner;

//main class

public class YearChecker

{

    //main method

public static void main (String [] args)

{

    //instantitating scanner class

Scanner scnr = new Scanner(System.in);

//declaring variable

int givenYear;

//displaying message to user to enter year

System.out.println("Enter year: ");

//reading input from user

givenYear = scnr.nextInt();

//if entered year is equal to or greater than 2101

if(givenYear>=2101)

{

    //displaying message to user

    System.out.println("Distant future");

}

//else if entered year is equal to or greater than 2001

else if(givenYear>...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Please help me with question b to find the running time. Thank you.

A: For function F1 the number of steps assuming only if branch: T(1) = 1 T(n) = 1 + T(n/2) Hence by re...

question_answer

Q: If we wanted to rewrite the code on page 275 to use while loops instead of do-while loops, what woul...

A:   Explanation: In the given problem the user is prompted to enter the number that is printed in the ...

question_answer

Q: Not allowed to use decisions or loops, if then statements, I haven't learned that. I have to use div...

A: Since here no programming language is specified. So, we are providing the solution in Java. The belo...

question_answer

Q: Create a flowchart and write a Python program to: ask the user to enter two integers: int1 and int2....

A: Click to see the answer

question_answer

Q: In C code, Given an int variable count that has already been declared, write a for loop that prints ...

A: The C program and its approach is given below: - Approach: - Declaring the necessary headers. Defin...

question_answer

Q: What are some of the competitive advantages Vivobarefoot gained through its infrastructure update?

A: Vivobarefoot is a shoe organization that has picked up such a great amount of notoriety in the less ...

question_answer

Q: I'm stuck on this question and I don't know how I should be approaching this. What should I do? My c...

A: The program makes a class Student and a nested class GPA. The members of class Student includes name...

question_answer

Q: Assignment: Problem #7 from Chapter 4 of the textbook. The case study is United Helpers. With the us...

A:   [ Note: We’ll answer the first three subparts of the question since the exact one wasn’t specified...

question_answer

Q: Discuss components of information technology under 1. Data 2. Information 3. Network 4. Internet 5. ...

A: Components of the information system are Data: Data are the crude raw numbers that are chaotic and a...