Distance traveled modification

Assignment Help JAVA Programming
Reference no: EM13166134

Distance Travelled Java how to go about modifying my code to complete this hw question.

Here is the question: Distance Traveled Modification

The distance a vehicle travels can be calculated as follows:

distance=Speed * time

Write a method named distance that accepts a vehicle's speed and rime as arguments, and

returns the distance the vehicle has traveled. Modify the "Distance Traveled" program you

wrote in Chapter 4.

 

My code for that problem was :

 

import javax.swing.JOptionPane; // Joption class

 

public class PROB4_CHAL2

{

public static void main(String[] args)

{

 

int distance;

int speed;

int time;

String input;

 

input = JOptionPane.showInputDialog("What is the speed " +

"of the vehicle in miles-per-hour?");

speed = Integer.parseInt(input);

 

while (speed < 0)

{

input = JOptionPane.showInputDialog("What is the speed " +

"of the vehicle in MPH? " +

"Please enter a POSITIVE number");

speed = Integer.parseInt(input);

}

input = JOptionPane.showInputDialog("How many hours " +

"has the vehicle travelled?");

time = Integer.parseInt(input);

 

while (time < 1)

{

input = JOptionPane.showInputDialog("How many hours " +

"has the vehicle travelled? " +

"Please enter a value that is no less than 1");

time = Integer.parseInt(input);

}

distance = speed * time;

String out = "Hour Distance Travelled\n\nTotal Hours: " + time + "\nTotal Distance: " + distance + "\n\n";

for(int i=1; i<=time; i++)

{

out+= "Hour " + i + ": " + (speed*i) + " miles travelled\n";

}

JOptionPane.showMessageDialog(null, out);

}

}

 

 

Reference no: EM13166134

Questions Cloud

How much heat is required to convert ethanol : How much heat is required to convert 25.0g ethanol at 25C to the vapor phase at 78C? How much to convert 5.00 L?
State what are the partial pressures of the gases in mmhg : Standard Atmos. Pressure is 90.0 atm. What are the Partial Pressures of the Gases in mmHg?
State carbon dioxide obeys the ideal gas and pr equations : the fraction of the initial mass of gas remaining in the tank if carbon dioxide obeys the ideal gas and PR equations of state
What mass of co2 will be produced : Fe3O4 reacts with CO according to the reaction Fe3O4(s) + 4CO(g) --> 4CO2(g) + 3Fe(s). If 201 grams of Fe3O4 is reacted with excess CO, what mass of CO2 will be produced?
Distance traveled modification : Distance Traveled Modification
You have poisson arrivals into your system : You have Poisson arrivals into your system with ?= 5 packets/second. The slot length is 1 second. Your current estimate for n^ is 20 (for the k-th time slot iteration).
How much fuel should he carry : A backpacker wants to carry enough fuel to heat 2.7 of water from 30 to 100.0 . If the fuel he carries produces 36 of heat per gram when it burns, how much fuel should he carry? (For the sake of simplicity, assume that the transfer of heat is 100 ..
State what is the enthalpy of solution for salt mx : If the specific heat of the salt is 0.663 J/C.g, what is the enthalpy of solution for salt MX if its molar mass is 68.0 g/mol?
What is the composition in mole fractions of the gas : What is the composition in mole fractions of the gas mixture that is expelled? The solubilities of CH4 and C2H6 at 20 degrees celcius and 1 atm are .0175 g/L H20 and .059g/L H2O, respectively.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a class named test scores

Write a class named TestScores.The class constructor should accept an array of test scores as an argument.The class should have a method that returns the average of the test scores.

  Write the bubble sort

The village of Marengo conducted a census and collected records that have household data, including the number of occupants in each household.

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  Determine product a inferior or normal good

Research illustrates that prices of related goods are given by Py = $5,900 and ; Pz = $90, while average income of individuals consuming this product is M = $55,000. Is X inferior or normal good?

  Program that allows a user to input coordinates

In Java make a program that allows a user to input coordinates as to make a Hexagon via an array, and my professor has set the standards of: Write a class Polygon which draws a hexagon for a set of numbers given by the user.

  Simulate some people catching fish in a lake in java program

In this project, you will simulate some people catching fish in a lake. The purpose of the assignment is to get used to using Arrays as well as getting more experience in having objects interact together.

  Write a java loop

write a java loop ( of your choice ) that produces exactly the following output to the screen: 2-4-6-8-

  Describe principles of data abstraction and inheritance

Study the principles of data abstraction, inheritance and dynamic binding. Use Library to get started on finding resources.You must take the terms and describe it.

  Reads contents of two vectors

Write a program that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Display student details and classes in applet

Display student details and classes they have enrolled in Applet. The Applet should have following features. Update and View.

  Object-oriented gui drawing editor

A simple object-oriented GUI drawing editor that allows a user to create, move and erase rectangles, squares, circles and lines in an interactive graphics. How can I draw move erase rectangles, squares, circles and lines in GUI/java.

  Accepts a scanner representing an input file

Write a method in JAVA called stripHtmlTags that accepts a Scanner representing an input file containing an HTML web page as its parameter, then reads that file and prints the file's text with all HTML tags removed. A tag is any text between the c..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd