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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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