Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class NumericTypesOriginal { public static void main (String [] args) { //TASK #2 Create a Scanner object here //identifier declarations final int 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 = 5/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 } } 

Task #1 Correcting Logic Errors in Formulas In this task you will use an existing Java program and correct several logic errors 1. Download the file NumericTypes.java from Blackboard. 2. Compile the source file, run the program, and observe the output. Some of the output is incorrect You need to correct logic errors in the average formula and the temperatureo or formula problems. The necessary formulas are average (score1+score2)umberOfScores C (5/9)*(F-32) 3. Each time you make changes to the program effect before running the program again. 4. Make sure that the output makes sense before you continue. The average of 95 and 100 should be 97.5 and the temperature that water boils is 100 degrees Celsius, or 212 degrees Fahrenheit. code, you must compile again for the changes to take Task #2 Using the Scanner Class for User Input In this task you will read in the user's 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 nextLineO method, and store it into the variable called scorel (comment out the line that originally defined scorel) 5. Prompt the user to enter the second score 6. Read the second score from the keyboard using the nextLine0 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). Task #3-Create a program from scratch / Using Predefined Math Functions In this task you will create a new program that calculates the result of a mathematical formula. You will use string expressions, assignment statements, input and output statements to communicate with the user 1. Create a new file in your IDE or text editor. Create the shell for your first program by entering: public class Sphere Volume public static void main(String[] args) our 2. Save the file as SphereVolume.java. In Java, each public class is written in a file with the same name as the class name 3. Translate the algorithm below into Java, using the hints in 2 through 6 below. Don't forget to declare variables before they are used. Each variable must be one word only (no spaces). Java naming convention is that variables start with a lower-case letter (your compiler will not object, though, if you do not follow this rule) Pseudo-code for SphereVolume. java: Print the purpose of the program Print a prompt asking for the diameter of a sphere Read the diameter Calculate the radius as diameter divided by.2 Calculate volume of the sphere using the formula (see Task #3b) Print the volume 4. Using the Scanne sphere. 5. Read in diameter which you will store in a variable called diam. You must declare diam before you use it. Declare it as a double. There are two ways to read in the value a. First option is to use in.next0, which returns the user input is returned as a String. Then you will need to use the method Double.parseDouble(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions