Question

In: Computer Science

JAVA PROGRAMMING RecallNoIF! Write a program named RecallNoIF that reads an integer representing a year. (In...

JAVA PROGRAMMING

RecallNoIF!

Write a program named RecallNoIF that reads an integer representing a year. (In this case there is no prompt from the program.) The program prints out RECALL if the year was 2004, 2010 or 2015 and NO RECALL otherwise.

CONSTRAINT: Nowhere in the program is an if statement used.

REMINDER: the program's output is shown here in bold; the user's data entry is shown here in italics.

Sample Interactive Run 1:

2010
RECALL

Sample Interactive Run 2:

2012
NO RECALL

Solutions

Expert Solution

Java program prompts the user to enter the input year value then check if input year is 2004 or 2010 or 2015 then print RECALL otherwise print the NO RECALL on java console window.

//RecallNoIF.java
//import Scanner class
import java.util.Scanner;
public class RecallNoIF
{
   public static void main(String[] args)
   {
       //Create an object of Scanner class
       Scanner kboard=new Scanner(System.in);
       //declare an integer variable, inputYear
       int inputYear;
       //read an integer value from keyboard
       inputYear=Integer.parseInt(kboard.nextLine());
       //Ternary operator
       //(Condition )? (expression1 if condition is true) : (expression2 if condition is false)
       //Check if inputYear is 2004 or 2010 or 2015
       //Then set the result to RECALL otherwise set result to NO RECALL
       String result=(inputYear==2004 ||inputYear==2010 ||inputYear==2015)?
               "RECALL":"NO RECALL";
       //print result on java console
       System.out.println(result);

   } //end of main method
} //end of the class,RecallNoIF

Sample output:

Sample Interactive Run 1:

Sample Interactive Run 2:

Update : The below is output for input of 1999 and 2004 for year input.


Related Solutions

*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a Java program which reads a positive integer from the command line, then displays the...
Write a Java program which reads a positive integer from the command line, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, you can use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd...
Write a program that reads an integer, a list of words, and a character.
13.14 LAB: Contains the characterWrite a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character.Ex: If the input is:4 hello zoo sleep drizzle zthen the output is:zoo drizzleIn c++ 
Write a program that reads in a continuous stream of strings representing a line of CSV...
Write a program that reads in a continuous stream of strings representing a line of CSV data in the format "NAME,AGE,EMAIL,DOB". Implement a function check_csv which verifies that each input string matches this format by ensuring that: • There are 4 tokens in the string corresponding to the 4 properties above. • The second token MUST be a number. • The fourth token should be in the format MM-DD-YYYY (hint: tokenize this as well). The function should return 0 if...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
Java Programming Create a program that prompts the user for an integer number and searches for...
Java Programming Create a program that prompts the user for an integer number and searches for it within an array of 10 elements. What is the average number of comparisons required to find an element in the array? Your program should print the number of comparisons required to find the number or determine that the number does not exist. Try finding the first and last numbers stored in the array. Run your program several times before computing the average.
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing...
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing the smallest value contained in the vector, an integer representing the largest value contained in the vector, and a double that represents the average of the values in the vector. The compileStats function will not “return” a value, it will set the Pass By Reference parameters to the correct values (smallest, largest, and average). Use the following main function in driver1b.cpp as a starting...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
How to write a java application that reads an integer, then determines and display whether it's...
How to write a java application that reads an integer, then determines and display whether it's odd or even. Use the remainder operator.
Lab 5 a) Write a program that reads in an unsigned integer K and sums the...
Lab 5 a) Write a program that reads in an unsigned integer K and sums the first K many integers that are divisible by 7. You should output the sum on a formatted manner b)Consider the following diamond it is an 11 by 11 diamond made with * signs. Write a program that takes as input positive odd integer K (greater than or equal to three and outputs a K by K diamond made with * signs * *** *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT