SlideShare a Scribd company logo
1 of 5
Download to read offline
Task #1 Correcting Logic Errors in Formulas
Copy and compile the source file NumericTypes.java, 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 = (score1+score2) / numberOfScores
C = 5/9 (F-32)
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 #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
Task #4 UsingPredefined Math Functions
Add a line that prompts the user to enter the diameter of a sphere.
Read in and store the number into a variable called diameter (you will need to declare any
variables that you use).
The diameter is twice as long as the radius, so calculate and store the radius in an appropriately
named variable.
The formula for the volume of a sphere is
r3
Convert the formula to Java 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.
Print your results to the screen with an appropriate message.
Compile, debug, and run using the following test data and record the results.
Diameter
Volume (hand calculated)
Volume (resulting output)
2
25.4
875,000
Code Listing 2.1 (NumericTypes.java)
// TASK #2 Add an import statement for the Scanner class
// TASK #2(Alternate)
// Add an import statement for the JOptionPane class
/**
This program demonstrates how numeric types and
operators behave in Java.
*/
public class NumericTypes
{
public static void main (String [] args)
{
// TASK #2 Create a Scanner object here
// (not used for alternate)
// Identifier declarations
final int NUMBER = 2 ; // Number of scores
final int SCORE1 = 100; // First test score
final int SCORE2 = 95; // Second test score
final int BOILING_IN_F = 212; // Boiling temperature
int fToC; // Temperature Celsius
double average; // Arithmetic average
String output; // Line of output
// TASK #2 declare variables used here
// TASK #3 declare variables used here
// TASK #4 declare variables used here
// Find an arithmetic average.
average = SCORE1 + SCORE2 / NUMBER;
output = SCORE1 + " and " + SCORE2 +
" have an average of " + average;
System.out.println(output);
// Convert Fahrenheit temperature to Celsius.
fToC = 5/9 * (BOILING_IN_F - 32);
output = BOILING_IN_F + " in Fahrenheit is " +
fToC + " in Celsius.";
System.out.println(output);
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #2 HERE
// Prompt the user for first name
// Read the user's first name
// Prompt the user for last name
// Read the user's last name
// Concatenate the user's first and last names
// Print out the user's full name
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #3 HERE
// Get the first character from the user's first name
// Print out the user's first initial
// Convert the user's full name to uppercase
// Print out the user's full name in uppercase
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #4 HERE
// Prompt the user for a diameter of a sphere
// Read the diameter
// Calculate the radius
// Calculate the volume
// Print out the volume
}
}
Diameter
Volume (hand calculated)
Volume (resulting output)
2
25.4
875,000
Solution
public class NumericTypes
{
public static void main (String [] args)
{
// TASK #2 Create a Scanner object here
// (not used for alternate)
// Identifier declarations
final int NUMBER = 2 ; // Number of scores
final int SCORE1 = 100; // First test score
final int SCORE2 = 95; // Second test score
final int BOILING_IN_F = 212; // Boiling temperature
int fToC; // Temperature Celsius
double average; // Arithmetic average
String output; // Line of output
// TASK #2 declare variables used here
// TASK #3 declare variables used here
// TASK #4 declare variables used here
// Find an arithmetic average.
average = SCORE1 + SCORE2 / NUMBER;
output = SCORE1 + " and " + SCORE2 +
" have an average of " + average;
System.out.println(output);
// Convert Fahrenheit temperature to Celsius.
fToC = 5/9 * (BOILING_IN_F - 32);
output = BOILING_IN_F + " in Fahrenheit is " +
fToC + " in Celsius.";
System.out.println(output);
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #2 HERE
// Prompt the user for first name
// Read the user's first name
// Prompt the user for last name
// Read the user's last name
// Concatenate the user's first and last names
// Print out the user's full name
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #3 HERE
// Get the first character from the user's first name
// Print out the user's first initial
// Convert the user's full name to uppercase
// Print out the user's full name in uppercase
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #4 HERE
// Prompt the user for a diameter of a sphere
// Read the diameter
// Calculate the radius
// Calculate the volume
// Print out the volume
}
}

More Related Content

Similar to Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf

Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingLidetAdmassu
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Hermann Hueck
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************Emad Helal
 
C chap02
C chap02C chap02
C chap02Kamran
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.pptMahyuddin8
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfadithyaups
 
SeriesTester.classpathSeriesTester.project SeriesT.docx
SeriesTester.classpathSeriesTester.project  SeriesT.docxSeriesTester.classpathSeriesTester.project  SeriesT.docx
SeriesTester.classpathSeriesTester.project SeriesT.docxlesleyryder69361
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 

Similar to Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf (20)

Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
C chap02
C chap02C chap02
C chap02
 
C chap02
C chap02C chap02
C chap02
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.ppt
 
Cinfo
CinfoCinfo
Cinfo
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
SeriesTester.classpathSeriesTester.project SeriesT.docx
SeriesTester.classpathSeriesTester.project  SeriesT.docxSeriesTester.classpathSeriesTester.project  SeriesT.docx
SeriesTester.classpathSeriesTester.project SeriesT.docx
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 

More from info706022

Many biologists will talk about the group known as Ungulates, or hoo.pdf
Many biologists will talk about the group known as Ungulates, or hoo.pdfMany biologists will talk about the group known as Ungulates, or hoo.pdf
Many biologists will talk about the group known as Ungulates, or hoo.pdfinfo706022
 
Match the function with the appropriate organelle in the column at ri.pdf
Match the function with the appropriate organelle in the column at ri.pdfMatch the function with the appropriate organelle in the column at ri.pdf
Match the function with the appropriate organelle in the column at ri.pdfinfo706022
 
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdf
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdfIt costs $16 to travel in a specific zone in paris. Now suppose thei.pdf
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdfinfo706022
 
Let X and Y be two random variables whose joint probability density .pdf
Let X and Y be two random variables whose joint probability density .pdfLet X and Y be two random variables whose joint probability density .pdf
Let X and Y be two random variables whose joint probability density .pdfinfo706022
 
Identify whether the Fed should continue its current pace of securit.pdf
Identify whether the Fed should continue its current pace of securit.pdfIdentify whether the Fed should continue its current pace of securit.pdf
Identify whether the Fed should continue its current pace of securit.pdfinfo706022
 
If 2 and z are incompletely dominant, how many different phenotypes a.pdf
If 2 and z are incompletely dominant, how many different phenotypes a.pdfIf 2 and z are incompletely dominant, how many different phenotypes a.pdf
If 2 and z are incompletely dominant, how many different phenotypes a.pdfinfo706022
 
How are criminals maximizing their total utilitySolutionThe o.pdf
How are criminals maximizing their total utilitySolutionThe o.pdfHow are criminals maximizing their total utilitySolutionThe o.pdf
How are criminals maximizing their total utilitySolutionThe o.pdfinfo706022
 
How do I change this javascript code so that the new page opens up b.pdf
How do I change this javascript code so that the new page opens up b.pdfHow do I change this javascript code so that the new page opens up b.pdf
How do I change this javascript code so that the new page opens up b.pdfinfo706022
 
Help with my biostats Homework. Please show all work!! Mendel develo.pdf
Help with my biostats Homework. Please show all work!! Mendel develo.pdfHelp with my biostats Homework. Please show all work!! Mendel develo.pdf
Help with my biostats Homework. Please show all work!! Mendel develo.pdfinfo706022
 
genetics q If the offspring of a dihydric testcross are roughly 50 .pdf
genetics q If the offspring of a dihydric testcross are roughly 50 .pdfgenetics q If the offspring of a dihydric testcross are roughly 50 .pdf
genetics q If the offspring of a dihydric testcross are roughly 50 .pdfinfo706022
 
for fiscal year 2006, the national debt of a country was approximate.pdf
for fiscal year 2006, the national debt of a country was approximate.pdffor fiscal year 2006, the national debt of a country was approximate.pdf
for fiscal year 2006, the national debt of a country was approximate.pdfinfo706022
 
Explain why Linux makes system performance monitoring available to t.pdf
Explain why Linux makes system performance monitoring available to t.pdfExplain why Linux makes system performance monitoring available to t.pdf
Explain why Linux makes system performance monitoring available to t.pdfinfo706022
 
Discuss the relationships between competitive avantage, istinctive c.pdf
Discuss the relationships between competitive avantage, istinctive c.pdfDiscuss the relationships between competitive avantage, istinctive c.pdf
Discuss the relationships between competitive avantage, istinctive c.pdfinfo706022
 
Determine the intervals of the domain over which each function is.pdf
Determine the intervals of the domain over which each function is.pdfDetermine the intervals of the domain over which each function is.pdf
Determine the intervals of the domain over which each function is.pdfinfo706022
 
A storage reservoir contains 200 kg of a liquid that has a specific .pdf
A storage reservoir contains 200 kg of a liquid that has a specific .pdfA storage reservoir contains 200 kg of a liquid that has a specific .pdf
A storage reservoir contains 200 kg of a liquid that has a specific .pdfinfo706022
 
4. Define modal split model transportation demand . central vision .pdf
4. Define modal split model transportation demand . central vision .pdf4. Define modal split model transportation demand . central vision .pdf
4. Define modal split model transportation demand . central vision .pdfinfo706022
 
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdf
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdfComparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdf
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdfinfo706022
 
“Web 2.0 is simply a new label for a range of web technologies and c.pdf
“Web 2.0 is simply a new label for a range of web technologies and c.pdf“Web 2.0 is simply a new label for a range of web technologies and c.pdf
“Web 2.0 is simply a new label for a range of web technologies and c.pdfinfo706022
 
You are required, but not limited, to turn in the following source f.pdf
You are required, but not limited, to turn in the following source f.pdfYou are required, but not limited, to turn in the following source f.pdf
You are required, but not limited, to turn in the following source f.pdfinfo706022
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfinfo706022
 

More from info706022 (20)

Many biologists will talk about the group known as Ungulates, or hoo.pdf
Many biologists will talk about the group known as Ungulates, or hoo.pdfMany biologists will talk about the group known as Ungulates, or hoo.pdf
Many biologists will talk about the group known as Ungulates, or hoo.pdf
 
Match the function with the appropriate organelle in the column at ri.pdf
Match the function with the appropriate organelle in the column at ri.pdfMatch the function with the appropriate organelle in the column at ri.pdf
Match the function with the appropriate organelle in the column at ri.pdf
 
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdf
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdfIt costs $16 to travel in a specific zone in paris. Now suppose thei.pdf
It costs $16 to travel in a specific zone in paris. Now suppose thei.pdf
 
Let X and Y be two random variables whose joint probability density .pdf
Let X and Y be two random variables whose joint probability density .pdfLet X and Y be two random variables whose joint probability density .pdf
Let X and Y be two random variables whose joint probability density .pdf
 
Identify whether the Fed should continue its current pace of securit.pdf
Identify whether the Fed should continue its current pace of securit.pdfIdentify whether the Fed should continue its current pace of securit.pdf
Identify whether the Fed should continue its current pace of securit.pdf
 
If 2 and z are incompletely dominant, how many different phenotypes a.pdf
If 2 and z are incompletely dominant, how many different phenotypes a.pdfIf 2 and z are incompletely dominant, how many different phenotypes a.pdf
If 2 and z are incompletely dominant, how many different phenotypes a.pdf
 
How are criminals maximizing their total utilitySolutionThe o.pdf
How are criminals maximizing their total utilitySolutionThe o.pdfHow are criminals maximizing their total utilitySolutionThe o.pdf
How are criminals maximizing their total utilitySolutionThe o.pdf
 
How do I change this javascript code so that the new page opens up b.pdf
How do I change this javascript code so that the new page opens up b.pdfHow do I change this javascript code so that the new page opens up b.pdf
How do I change this javascript code so that the new page opens up b.pdf
 
Help with my biostats Homework. Please show all work!! Mendel develo.pdf
Help with my biostats Homework. Please show all work!! Mendel develo.pdfHelp with my biostats Homework. Please show all work!! Mendel develo.pdf
Help with my biostats Homework. Please show all work!! Mendel develo.pdf
 
genetics q If the offspring of a dihydric testcross are roughly 50 .pdf
genetics q If the offspring of a dihydric testcross are roughly 50 .pdfgenetics q If the offspring of a dihydric testcross are roughly 50 .pdf
genetics q If the offspring of a dihydric testcross are roughly 50 .pdf
 
for fiscal year 2006, the national debt of a country was approximate.pdf
for fiscal year 2006, the national debt of a country was approximate.pdffor fiscal year 2006, the national debt of a country was approximate.pdf
for fiscal year 2006, the national debt of a country was approximate.pdf
 
Explain why Linux makes system performance monitoring available to t.pdf
Explain why Linux makes system performance monitoring available to t.pdfExplain why Linux makes system performance monitoring available to t.pdf
Explain why Linux makes system performance monitoring available to t.pdf
 
Discuss the relationships between competitive avantage, istinctive c.pdf
Discuss the relationships between competitive avantage, istinctive c.pdfDiscuss the relationships between competitive avantage, istinctive c.pdf
Discuss the relationships between competitive avantage, istinctive c.pdf
 
Determine the intervals of the domain over which each function is.pdf
Determine the intervals of the domain over which each function is.pdfDetermine the intervals of the domain over which each function is.pdf
Determine the intervals of the domain over which each function is.pdf
 
A storage reservoir contains 200 kg of a liquid that has a specific .pdf
A storage reservoir contains 200 kg of a liquid that has a specific .pdfA storage reservoir contains 200 kg of a liquid that has a specific .pdf
A storage reservoir contains 200 kg of a liquid that has a specific .pdf
 
4. Define modal split model transportation demand . central vision .pdf
4. Define modal split model transportation demand . central vision .pdf4. Define modal split model transportation demand . central vision .pdf
4. Define modal split model transportation demand . central vision .pdf
 
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdf
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdfComparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdf
Comparison of dysplasia and hyperplasiaSolutionDysplasia Dys.pdf
 
“Web 2.0 is simply a new label for a range of web technologies and c.pdf
“Web 2.0 is simply a new label for a range of web technologies and c.pdf“Web 2.0 is simply a new label for a range of web technologies and c.pdf
“Web 2.0 is simply a new label for a range of web technologies and c.pdf
 
You are required, but not limited, to turn in the following source f.pdf
You are required, but not limited, to turn in the following source f.pdfYou are required, but not limited, to turn in the following source f.pdf
You are required, but not limited, to turn in the following source f.pdf
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 

Recently uploaded

REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Recently uploaded (20)

REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf

  • 1. Task #1 Correcting Logic Errors in Formulas Copy and compile the source file NumericTypes.java, 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 = (score1+score2) / numberOfScores C = 5/9 (F-32) 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 #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).
  • 2. 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 Task #4 UsingPredefined Math Functions Add a line that prompts the user to enter the diameter of a sphere. Read in and store the number into a variable called diameter (you will need to declare any variables that you use). The diameter is twice as long as the radius, so calculate and store the radius in an appropriately named variable. The formula for the volume of a sphere is r3 Convert the formula to Java 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. Print your results to the screen with an appropriate message. Compile, debug, and run using the following test data and record the results. Diameter Volume (hand calculated) Volume (resulting output) 2 25.4 875,000 Code Listing 2.1 (NumericTypes.java) // TASK #2 Add an import statement for the Scanner class // TASK #2(Alternate) // Add an import statement for the JOptionPane class /** This program demonstrates how numeric types and operators behave in Java. */ public class NumericTypes { public static void main (String [] args) { // TASK #2 Create a Scanner object here // (not used for alternate)
  • 3. // Identifier declarations final int NUMBER = 2 ; // Number of scores final int SCORE1 = 100; // First test score final int SCORE2 = 95; // Second test score final int BOILING_IN_F = 212; // Boiling temperature int fToC; // Temperature Celsius double average; // Arithmetic average String output; // Line of output // TASK #2 declare variables used here // TASK #3 declare variables used here // TASK #4 declare variables used here // Find an arithmetic average. average = SCORE1 + SCORE2 / NUMBER; output = SCORE1 + " and " + SCORE2 + " have an average of " + average; System.out.println(output); // Convert Fahrenheit temperature to Celsius. fToC = 5/9 * (BOILING_IN_F - 32); output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius."; System.out.println(output); System.out.println(); // To leave a blank line // ADD LINES FOR TASK #2 HERE // Prompt the user for first name // Read the user's first name // Prompt the user for last name // Read the user's last name // Concatenate the user's first and last names // Print out the user's full name System.out.println(); // To leave a blank line // ADD LINES FOR TASK #3 HERE // Get the first character from the user's first name // Print out the user's first initial // Convert the user's full name to uppercase // Print out the user's full name in uppercase System.out.println(); // To leave a blank line
  • 4. // ADD LINES FOR TASK #4 HERE // Prompt the user for a diameter of a sphere // Read the diameter // Calculate the radius // Calculate the volume // Print out the volume } } Diameter Volume (hand calculated) Volume (resulting output) 2 25.4 875,000 Solution public class NumericTypes { public static void main (String [] args) { // TASK #2 Create a Scanner object here // (not used for alternate) // Identifier declarations final int NUMBER = 2 ; // Number of scores final int SCORE1 = 100; // First test score final int SCORE2 = 95; // Second test score final int BOILING_IN_F = 212; // Boiling temperature int fToC; // Temperature Celsius double average; // Arithmetic average String output; // Line of output // TASK #2 declare variables used here // TASK #3 declare variables used here // TASK #4 declare variables used here // Find an arithmetic average. average = SCORE1 + SCORE2 / NUMBER;
  • 5. output = SCORE1 + " and " + SCORE2 + " have an average of " + average; System.out.println(output); // Convert Fahrenheit temperature to Celsius. fToC = 5/9 * (BOILING_IN_F - 32); output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius."; System.out.println(output); System.out.println(); // To leave a blank line // ADD LINES FOR TASK #2 HERE // Prompt the user for first name // Read the user's first name // Prompt the user for last name // Read the user's last name // Concatenate the user's first and last names // Print out the user's full name System.out.println(); // To leave a blank line // ADD LINES FOR TASK #3 HERE // Get the first character from the user's first name // Print out the user's first initial // Convert the user's full name to uppercase // Print out the user's full name in uppercase System.out.println(); // To leave a blank line // ADD LINES FOR TASK #4 HERE // Prompt the user for a diameter of a sphere // Read the diameter // Calculate the radius // Calculate the volume // Print out the volume } }