Question: 2.14 Lab Full Program: Basic Java Output and Input Fill in the program template so that it will do the following: (i.e. replace the comments
2.14 Lab Full Program: Basic Java Output and Input
Fill in the program template so that it will do the following: (i.e. replace the comments that say /* FIX ME */ ) (1) Output this exact hourglass to the screen.
########### # # #*****# #***# #*# #*# #*# # * # # * # #*******# ###########
(2) Add more code to your program to read user input and display output as described below: First output two blank lines after the hourglass. Then output the following prompt to the user:
Enter the current year:
Create a Scanner object to use for reading input. Create an integer variable to use for storing the current year read from input. Read the input and store it in the variable you created.
Then output the following, including the year that was input. For example, if the input was 2018, the program would output:
Time passes... We are now in year 2018
(3) Add more code to calculate and display the next year, as follows:
Time passes... We are now in year 2018 2019 will be next!
(4) Add more code to your program to read and output a social security number (SSN) as described below: First output one blank line after the previous outputs. Prompt for each part of an SSN, as shown below, and read and store the input parts into the variables already defined in the program code template. Then output one blank line and output the formatted SSN.
Enter first 3 digits of SSN: 111 Enter middle 2 digits of SSN: 22 Enter last 4 digits of SSN: 3333 Formatted SSN [111-22-3333]
Note: This zyLab outputs a newline after each user-input prompt.
For convenience in the examples above, the user's input value was shown on the next line, but such values don't actually appear as output when the program runs.
The last lines of program output for the above examples would be:
Enter first 3 digits of SSN: Enter middle 2 digits of SSN: Enter last 4 digits of SSN: Formatted SSN [111-22-3333]
And program input for the above examples would be:
2018 111 22 3333
import java.util.Scanner; // required for user input
public class BasicOutputInput { public static void main(String[] args) { int first3digits = 0; int middle2digits = 0; int last4digits = 0;
// FIX ME (1): Draw hourglass System.out.println("###########");
// FIX ME (2): Prompt for and read year input and then output results // FIX ME (3): Prompt for and read SSN input and then output results return; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
