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)
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
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
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...
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1...
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1 to 1000. Then remove every even number. Then remove every multiple of 3 remaining Then remove every multiple of 5 Then remove every multiple of 7 Then sum the array, and print.
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.
you are to write a program in Java, that reads in a set of descriptions of...
you are to write a program in Java, that reads in a set of descriptions of various geometric shapes, calculates the areas and circumferences of the shapes, and then prints out the list of shapes and their areas in sorted order from smallest to largest area. There are four possible shapes: Circle, Square, Rectangle, and Triangle. The last is always an equilateral triangle. The program should read from standard input and write to standard output. The program should read until...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT