Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill in the program template so that it will do the following: (i.e. replace the

ID: 3731379 • Letter: F

Question

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:

Create an integer type variable with a descriptive name, to hold the present time's current hour.
Create a Scanner object to use for reading input.
Read the user's input and store it in the variable you created.

Then output the following, including the hour the user entered.
For example, if the user entered 5, the program would output:


(3) Add more code to calculate and display the number of hours until 12 o'clock, as follows:


(4) Add more code to your program to read and output a phone number as described below:

First output one blank line after the previous output.
Prompt for each part of a phone number, as shown below, and read and store the parts into the variables already defined in the program.
Then output one blank line and output the formatted phone number.

Note: This zyLab outputs a newline after each user-input prompt.
For convenience in the examples below, the user's input values (303, 333, and 3333) are shown on the line following each prompt,
but such values don't actually appear as output when the program runs.

import java.util.Scanner; // required for user input

public class BasicOutputInput {
public static void main(String[] args) {
int areaCode = 0;
int prefixDigits = 0;
int last4digits = 0;
// FIX ME (2a): Create an integer variable to hold the current hour
// FIX ME (2b): Create a Scanner object to use for reading input
  
// FIX ME (1): Draw hourglass
System.out.println("=========");

// FIX ME (2c): Prompt for and read current hour input and then output results
  
// FIX ME (3): Calculate and output the hours until 12 o'clock

// FIX ME (4): Prompt for and read phone input and then output results  
  
return;
}
}

Explanation / Answer

import java.util.Scanner; // required for user input

public class BasicOutputInput {

public static void main(String[] args) {

int areaCode = 0;

int prefixDigits = 0;

int last4digits = 0;

// FIX ME (2a): Create an integer variable to hold the current hour

int currentHour = 0;

// FIX ME (2b): Create a Scanner object to use for reading input

Scanner scanner = new Scanner(System. in);

  

// FIX ME (1): Draw hourglass

System.out.println("=========");

int l=0;

for(int i = 4; i>0; i--){

for (l=i;l<4;l++){

System.out.print(" ");

}

for(int k = i*2 - 1;k>0;k--){

System.out.print("*");

}

System.out.println();

}

  

for(int i =1; i <=3 ; i++){

for(int k = 3 - i; k>0; k --){

System.out.print(" ");

}

for(int j = i*2 + 1 ; j>0 ; j -- ){

System.out.print("*");

}

System.out.println();

}

System.out.println("=========");

System.out.println();

System.out.println();

  

// FIX ME (2c): Prompt for and read current hour input and then output results

System.out.println("Enter the current hour: ");

String currentHourInput = scanner.nextLine();

System.out.println(currentHourInput);

System.out.println("Time passes...");

System.out.println(" We are now in the "+currentHourInput+" o'clock hour");

  

// FIX ME (3): Calculate and output the hours until 12 o'clock

currentHour = Integer.parseInt(currentHourInput);

int timeDiff = 12 - currentHour;

System.out.println(timeDiff+" hours until 12 o'clock");   

// FIX ME (4): Prompt for and read phone input and then output results  

System.out.println("Enter the area code:");

String areaCodeInput = scanner.nextLine();

System.out.println("Enter the 3-digit prefix:");

String prefixInput = scanner.nextLine();

System.out.println("Enter the last 4 digits:");

String last4digitsInput = scanner.nextLine();

System.out.println();

System.out.println("Phone number is ("+areaCodeInput+") "+prefixInput+"-"+last4digitsInput);

  

//The below code is only to set value in your variables in case you need them later

areaCode = Integer.parseInt(areaCodeInput);

prefixDigits = Integer.parseInt(prefixInput);

last4digits = Integer.parseInt(last4digitsInput);

  

return;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote