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 java class

Write a Java class called PQueue that extends the provided abstract QueueADT class.

  What is the average response time for this system?

A web server receives a request every 50ms and processes web requests every 8 ms. Using queuing theory, 1. What is the average response time for this system?

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  Write a method called printlevel

Write a method called printLevel that takes an integer n as a parameter and that prints the values at level n from left to right. The values should be printed one per line.

  Create a web application for sheridan restaurant

Create a web application for Sheridan Restaurant Reviews that contains the following functionality - Display a table of all restaurants based on the city entered by the user

  Write a while loop that lets the user enter a number

1) Write a while loop that lets the user enter a number. The number should then be multiplied by 10, and stored in a variable called product. The loop should then iterate as long as product contains a value less than 100.

  Write a program that reads a set of floating-point

Write a program that reads a set of floating-point data values from the input.

  Elements from a html document

Function test Count List Elements should simply retrieve an array of all list elements on the page and assert that their total count is 3.

  Write ijvm program to multiply two hexadecimal numbers

Write the IJVM program that multiplies two (hexadecimal) numbers. The user inputs the hex numbers and the result is printed out. The program then accepts another pair of numbers.

  The menu is displayed and the user must select

The menu is displayed and the user must select an option (a number between 0 and 7). The action corresponding to the selection is performed, then the menu is displayed again and the user can choose another option.

  Design an adt for a two-color

Design an ADT for a two-color, double-stack ADT that consists of two stacks one "red" and one "blue" and has as its operations color-coded versions of the regular stack ADT operations.

  Using an array in java

Using an array in Java - have a list of keywords from a web service and have to print out the list of keywords on the screen with one keyword on each line. This is my code

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