Question

in .java Write a program that computes the time to arrive to destination. It asks for...

in .java

Write a program that computes the time to arrive to destination. It asks for the distance and the car speed. It will assume that the car travels at constant speed at all time.
Sample run 1:

This program will compute the travel time.
Enter the distance (miles): 105
Enter the car speed (miles/hour): 75
Travel time: 1.40
or: 1 hour and 23 minutes


Sample run 2:

This program will compute the travel time.
Enter the distance (miles): 150
Enter the car speed (miles/hour): 60
Travel time: 2.50
or: 2 hour and 30 minutes

Homework Answers

Answer #1
import java.util.Scanner;

public class DistanceTravelled {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("This program will compute the travel time.");
        System.out.print("Enter the distance (miles): ");
        double distance = in.nextDouble();
        System.out.print("Enter the car speed (miles/hour): ");
        double speed = in.nextDouble();
        double time = distance / speed;
        System.out.printf("Travel time: %.2f\n", time);
        int hours = (int) time;
        int minutes = (int) ((time - hours) * 60);
        System.out.println("or: " + hours + " hour and " + minutes + " minutes");
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in .java Write a program that asks the user to enter 3 grades and computes the...
in .java Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
in c++ Write a program that asks the user for the speed of a vehicle (in...
in c++ Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should use a loop to display the total distance traveled. The speed traveled should be limited by the fastest speed achieved by a car thus far. Values should not be negative.•Ex: if hours = 3 and speed = 40, then the program should display•Hour 1: Distance Traveled: 40 miles•Hour 2: Distance Traveled: 80...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed *...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display the distance a vehicle has traveled for each hour of a...
Your team was asked to program a self-driving car that reaches its destination with minimum travel...
Your team was asked to program a self-driving car that reaches its destination with minimum travel time. Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given. (I just need the algorithm for it thanks!)
do the java code below and prove that it works. 2. Distance Traveled The distance a...
do the java code below and prove that it works. 2. Distance Traveled The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display...
Write a program that asks the user to enter a series of numbers separated by commas....
Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6 The program should calculate and print the sum of all the numbers. Sample Run java NumberSum Enter·numbers·separated·by·commas:1,2,3↵ 6↵
In one C++ program: a.) Write a code to asks the user for her/his full name...
In one C++ program: a.) Write a code to asks the user for her/his full name b.) Write a code that asks the user to enter information related to a car the user likes (year, make, model) c.) Write a code that asks the user to enter the amount of time or gas or money the user spends to commute weekly d.) Write a code that asks the user to enter the number Kwh (used monthly) and compute the user...
Java: Distance calc. This question is fairly straightforward. Design implement (source code) a program to compute...
Java: Distance calc. This question is fairly straightforward. Design implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs. Note: for C++, #include and then call sqrt(). For Java, you’ll...
Visitors arrive at Kid’s World entertainment park according to an exponential interarrival time distribution with mean...
Visitors arrive at Kid’s World entertainment park according to an exponential interarrival time distribution with mean 2.5 minutes. The travel time from the entrance to the ticket window is normally distributed with a mean of 3 minutes and a standard deviation of 0.5 minute. At the ticket window, visitors wait in a single line until one of four cashiers is available to serve them. The time for the purchase of tickets is normally distributed with a mean of fi ve...
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...