Task #5 – Create a program from scratch In this task the student will create a new program that calculates gas mileage in miles per gallon. The student 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. 2. Create the shell for your first program by entering: public class Mileage public static void main (String[] args) { // Add your declaration and code here. } 3. Save the file as Mileage.java. 4. Translate the algorithm below into Java code. Don't forget to declare variables before they are used. Each variable must be one word only (no spaces). Print a line indicating this program will calculate mileage Print prompt to user asking for miles driven Read in miles driven Print prompt to user asking for gallons used Read in gallons used Calculate miles per gallon by dividing miles driven by gallons used Print miles per gallon along with appropriate labels 5. Compile the program and debug, repeating until it compiles successfully. 6. Run the program and test it using the following sets of data and record the results: per gallon (hand calculated) Miles per gallon (resulting output) Miles driven Gallons used Miles 2000 100 500 25.5 241.5 10 100 7. The last set of data caused the computer to divide 100 by 0, which resulted in what is called a runtime error. Notice that runtime can occur on programs which compile and run on many other sets of data. This emphasizes the need to thoroughly test you program with all possible kinds of data. Copyright © 2016 Pearson Education, Inc., Hoboken NJ

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
I need the answer as soon as possible
Task #5 – Create a program from scratch
In this task the student will create a new program that calculates gas mileage in miles per
gallon. The student 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.
2. Create the shell for your first program by entering:
public class Mileage
{
public static void main (String [] args)
{
// Add your declaration and code here.
}
}
3. Save the file as Mileage.java.
4. Translate the algorithm below into Java code. Don't forget to declare variables
before they are used. Each variable must be one word only (no spaces).
Print a line indicating this program will calculate mileage
Print prompt to user asking for miles driven
Read in miles driven
Print prompt to user asking for gallons used
Read in gallons used
Calculate miles per gallon by dividing miles driven by gallons used
Print miles per gallon along with appropriate labels
5. Compile the program and debug, repeating until it compiles successfully.
6. Run the program and test it using the following sets of data and record the results:
Miles per gallon
(hand calculated)
Miles per gallon
(resulting output)
Miles driven
Gallons used
2000
100
500
25.5
241.5
10
100
7. The last set of data caused the computer to divide 100 by 0, which resulted in
what is called a runtime error. Notice that runtime can occur on programs which
compile and run on many other sets of data. This emphasizes the need to
thoroughly test you program with all possible kinds of data.
Copyright © 2016 Pearson Education, Inc., Hoboken NJ
Transcribed Image Text:Task #5 – Create a program from scratch In this task the student will create a new program that calculates gas mileage in miles per gallon. The student 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. 2. Create the shell for your first program by entering: public class Mileage { public static void main (String [] args) { // Add your declaration and code here. } } 3. Save the file as Mileage.java. 4. Translate the algorithm below into Java code. Don't forget to declare variables before they are used. Each variable must be one word only (no spaces). Print a line indicating this program will calculate mileage Print prompt to user asking for miles driven Read in miles driven Print prompt to user asking for gallons used Read in gallons used Calculate miles per gallon by dividing miles driven by gallons used Print miles per gallon along with appropriate labels 5. Compile the program and debug, repeating until it compiles successfully. 6. Run the program and test it using the following sets of data and record the results: Miles per gallon (hand calculated) Miles per gallon (resulting output) Miles driven Gallons used 2000 100 500 25.5 241.5 10 100 7. The last set of data caused the computer to divide 100 by 0, which resulted in what is called a runtime error. Notice that runtime can occur on programs which compile and run on many other sets of data. This emphasizes the need to thoroughly test you program with all possible kinds of data. Copyright © 2016 Pearson Education, Inc., Hoboken NJ
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY