Question: Task #2 Using the Scanner Class for User Input In this task you will read in the users name, and let the user enter values

Task #2 Using the Scanner Class for User Input In this task you will read in the users name, and let the user enter values to replace the hard-coded values in Task #1.

1. Add an import statement above the class declaration to make the Scanner class available to your program.

2. In the main method, create a Scanner object and connect it to the System.in object. Reuse this Scanner object to read in each of the following entries.

3. Prompt the user to enter the first score.

4. Read the first score from the keyboard using the nextLine() method, and store it into the variable called score1 (comment out the line that originally defined score1).

5. Prompt the user to enter the second score.

6. Read the second score from the keyboard using the nextLine() method, and store it into the variable called score2 (comment out the line that originally defined score2).

7. Prompt the user to enter another temperature in Celsius after the original temperature conversion is printed out.

8. Read the temperature and print out the result in Fahrenheit.

9. Compile, debug, and run, using other score values as test data.

10. Submit your completed NumericTypes.java to Blackboard (NOT the class file).

import java.util.Scanner;

//NumericTypes.java

public class NumericTypes {

public static void main (String [] args) {

//TASK #2 Create a Scanner object here

//identifier declarations

final double NUMBER = 2 ; // number of scores

int score1 = 100; // first test score

int score2 = 95; // second test score

final int BOILING_IN_F = 212; // boiling temperature

double fToC; // temperature in Celsius

double average; // arithmetic average

String output; // line of output to print out

//Task #2 declare a variable to hold the users temperature

//Task #2 prompt user to input score1

//Task #2 read score1

//Task #2 prompt user to input score2

//Task #2 read score2

// Find an arithmetic average

average = (score1 + score2) / NUMBER;

output = score1 + " and " + score2 + " have an average of " + average;

System.out.println(output);

// Convert Fahrenheit temperatures to Celsius

fToC = (double)(5/(double)9 * (BOILING_IN_F - 32));

output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius.";

System.out.println(output);

//Task #2 prompt user to input another temperature

//Task #2 read the users temperature in Fahrenheit

//Task #2 convert the users temperature to Celsius

//Task #2 print the users temperature in Celsius

System.out.println("Goodbye"); // to show that the program is ended

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!