Purchase Solution

Change code in Java program input of floating point values

Not what you're looking for?

Ask Custom Question

Change code in Java program so that input of floating point values is possible.

/* Java program which outputs the average speed of an
*object given the distance and time travelled
* (speed = distance/time). */

// Java extension packages
import java.util.*; // import class
import java.io.*; // import class

public class AverageSpeed
{
// main method begins execution of Java application
public static void main( String args[])
{

Scanner input = new Scanner( System.in );

int Distance; // Number keyed in by user representing distance travelled
int Time; // Number keyed in by user representing time taken
int Speed; // Calculated average speed

// Takes input of number to be process representing distance travelled
System.out.print( "Please enter the distance travelled in kilometres: ");
Distance = input.nextInt();

// Takes input of number to be process representing travel time
System.out.print( "Please enter the time taken to cover the distance in hours : ");
Time = input.nextInt();

Speed = Distance/Time; // Calculates the average speed

// display the results calculated average speed
System.out.printf( "Your average speed per hour is: %dn" , Speed );

} // end method main
} // end class AverageSpeed

Purchase this Solution

Solution Summary

The change code in Java programs so that the input of floating point values are determined. The average speed of the outputs are found.

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.