Task #1 Correcting Logic Errors in Formulas 1. Copy the file NumericTypes.java (see Code Listing 2.1) from
Question:
Task #1 Correcting Logic Errors in Formulas 1. Copy the file NumericTypes.java (see Code Listing 2.1) from the Student CD or as directed by your instructor. 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 temperature conversion formula. The logic errors could be due to conversion between data types, order of operations, or formula problems. The necessary formulas are: average = score score numberOfScores 1 2 C = 5 9 F 32 3. Each time you make changes to the program code, you must compile again for the changes to take 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. Task #2 Using the Scanner Class for User Input 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. 3. Prompt the user to enter his or her first name. 4. Read the name from the keyboard using the nextLine method, and store it into a variable called firstName (you will need to declare any variables you use). 5. Prompt the user to enter his or her last name. 6. Read the name from the keyboard and store it in a variable called lastName. 7. Concatenate the firstName and lastName with a space between them and store the result in a variable called fullName. 8. Print out the fullName. 9. Compile, debug, and run, using your name as test data. 10. Since we are adding on to the same program, each time we run the program we will get the output from the previous tasks before the output of the current task. Task #2 (Alternate) Using Dialog Boxes for User Input 1. Add an import statement above the class declaration to make the JOptionPane class available to your program. Copyright 2016 Pearson Education, Inc., Hoboken NJ 2. In the main method, prompt the user to enter his or her first name by displaying an input dialog box and storing the user input in a variable called firstName (you will need to declare any variables you use). 3. Prompt the user to enter his or her last name by displaying an input dialog box and storing the user input in a variable called lastName. 4. Concatenate the firstName and lastName with a space between them and store the result in a variable called fullName. 5. Display the fullName using a message dialog box. 6. Compile, debug, and run, using your name as test data. 7. Since we are adding on to the same program, each time we run the program we will get the output from the previous tasks before the output of the current task. Task #3 Working with Strings 1. Use the charAt method to get the first character in firstName and store it in a variable called firstInitial (you will need to declare any variables that you use). 2. Print out the user's first initial. 3. Use the toUpperCase method to change the fullName to uppercase and store it back into the fullName variable. 4. Add a line that prints out the value of fullName and how many characters (including the space) are in the string stored in fullName (use the length method to obtain that information). 5. Compile, debug, and run. The new output added on after the output from the previous tasks should have your initials and your full name in uppercase characters. Task #4 Using Predefined Math Functions 1. Add a line that prompts the user to enter the diameter of a sphere. 2. Read in and store the number into a variable called diameter (you will need to declare any variables that you use). 3. The diameter is twice as long as the radius, so calculate and store the radius in an appropriately named variable. 4. The formula for the volume of a sphere is: 3 4 V r 3 Convert the formula to Java code and add a line which calculates and stores the value of volume in an appropriately named variable. Use Math.PI for and Math.pow to cube the radius. 5. Print your results to the screen with an appropriate message. 6. Compile, debug, and run using the following test data and record the results. Copyright 2016 Pearson Education, Inc., Hoboken NJ Diameter Volume (hand calculated) Volume (resulting output) 2 25.4 875,000
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill