loop to input multiple points to calculate final distance and speed

loop to input multiple points to calculate final distance and speed

import java.util.Scanner;

public class Travel { private double time;
private double distance;

public Travel() 
{
    time=0;
    distance=0;
}

public void setTime(double t)
{
    time=t;
}

public void setDistance(double d)
{
    distace=d;
}

public void getTime()
{   
    return time;
}

public void getDistance()
{
    return distance;
}


public static void main (String[] args)
{
    Scanner input= new Scanner(System.in);
    System.out.print(" Enter two doubles for points and an integer for speed");
    double x1= input.nextDouble();
    double y1= input.nextDouble();
    int s1= input.nextInt();
    int n=2;

    do{
        System.out.print(" Way point", +n);
        Scanner input= new Scanner(System.in);
        double x2 =input.nextDouble();
        double y2=input.nextDouble);
        int s2=input.nextInt();
        n=n+1;

        double d= Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1, 2);
        distance=distance+d;
        double t= distance/s1;
        time=time+t;

        x1=x2;
        y1=y2;
        s1=s2;


    } while(s1!=0)

System.out.println(" The total distance is", +distance); System.out.println("The total time is ", time/60, "hours ", time%60, "minutes");

}

View Answers









Related Tutorials/Questions & Answers:
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  ... doubles for points and an integer for speed"); double x1= input.nextDouble...; private double distance; public Travel() { time=0; distance=0
calculate reward points.
calculate reward points.  How to calculate reward points in a multiplex automation system
Advertisements
how to calculate max and min in the loop - Java Beginners
and min value in the loop. the input is from the user. could u teach me. thanks...how to calculate max and min in the loop  thanks coz giving me..., in a loop...till the end of the array...check each values against the max
Managing Multiple User Input Data in an Array (or ArrayList)
Managing Multiple User Input Data in an Array (or ArrayList)  Hey there! I need to make a code of an employee record. Here's how it should work: (1... record alphabetically (2) If user chooses choice1, the input data is stored
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop. ... that when in a loop i trying to choose single checkbox among multiple checkboxes but here am getting multiple selection(previous selected item also coming again
final
final  what does final means in "public static final void main (string args[])" ?   keyword final can be assigned only once. They cannot be modified
class distance
class distance  class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required
plotting of points inside a rectangle
plotting of points inside a rectangle  I want to plot various points inside a rectangle such that any two points are at a distance of at least 3... example ,if I have a Rectangle of 20m by 14m then one possible placement of points
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
For Loop
For Loop  Write a program using a for loop that computes the following sum: 1/2 + 2/2 + 3/2 + 4/2 + 5/2 + ... N/2 N will be an integer limit... input=new Scanner(System.in); System.out.print("Enter the value of n
loop
to output the following code using a loop the code is as follows with the user... { public static void main(String[] args) { Scanner input=new... static void main(String[] args) { Scanner input=new Scanner(System.in
input
input  a java program that will exchange the last names of two students that were input by a user
loop
loop  what is the difference b/w do while,while and for loop..with example
loop
loop  i want to write my name(inder) through loop in java using star
for loop
for loop  what is for loop   Loops are used for iteration... for a number of times it is finite loop and if repetition is done infinitely it is infinite loop. Java provides several loop structures for iteration. Those
For loop
For loop  Hi! Please explain the following loop: for(i=0;i<a[j];i++) THANX!!   Please reply as soon as possible
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
Loop
to understand a loop my quesiton are: what du i do wrong in my code since.... (made in blueJ) Class Loop public void loopUpGeneral(int start, int stop... dk  Hi, Please check the for loop once again: for (int i
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
final grade
final grade  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point... input a student?s final grade from 50-100. Evaluate the Final grade and display
Road distance using Java - Java Beginners
Road distance using Java  Dear All i am calculating the straight line distance between two latlong points using the simple mathematical formula... it in java // Calculate driving distance with Google Maps API
ModuleNotFoundError: No module named 'speed'
ModuleNotFoundError: No module named 'speed'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'speed' How to remove the ModuleNotFoundError: No module named 'speed'
Finding a Factorial using while loop
to calculate the factorial .Now use while loop and pass the condition that until...Finding a Factorial using while loop     ... the while loop. In while loop the loop will run until the condition we have given
final keyword
final keyword  why is final keyword used in java
Calculate factorial of a number.
Calculate factorial of a number.  How to calculate factorial...("Please Input Any Number"); int num = 0; BufferedReader br = new... Integer.parseInt(). For loop from 1 to num-1 calculating the factorial value of num
CPU fan speed - Security
CPU fan speed  Hi, my question is how can we get the cpu fan speed... of fan and temperature. Just update us if find the example to find the speed...(System.out); }}-------------But I don't know how to get the speed of fan
Final Keyword
Final Keyword  hello, What is final?   hiiADS_TO_REPLACE_1 In case of class if we use final then this class can not be extended or final class may not be subclassed. A final method can't be overridden when its class
ModuleNotFoundError: No module named 'points'
ModuleNotFoundError: No module named 'points'  Hi, My Python... 'points' How to remove the ModuleNotFoundError: No module named 'points'... to install padas library. You can install points python with following command
Java Final Project - Java Beginners
Java Final Project  I am having a real hard time with this java assignment. Any help or tips will be great!!! This is the requirements: Final...!!! Do not think this is what you have to do to get the maximum number of points
calculate the time ..
calculate the time ..  [CODE] Elapsed Time Example...();"> <div> <form> <input type="button" value="Start Time" onclick="captureStartTime();" /> <input type
final variable
final variable  Please give some easiest and understanding example program for final variable
Calculate sum and Average in java
Calculate sum and Average in java  How to calculate sum and average... { System.out.println("Input any No."); BufferedReader br = new BufferedReader(new...); System.out.println("Avg- " + avg); } } Output Input any Value
calculate average
and write a program and calculate your final average in this course. The details...calculate average   Design and write a java program to determine all three digit numbers such that the sum of the cubes of the digits is equal
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display... input a student?s final grade from 50-100. Evaluate the Final grade and display
points being displayed in the world
points being displayed in the world  how do i display points in my world   Hi Friend, Please clarify your problem. Thanks
loop statements
loop statements  write a program that reads from input an interger n and prints the factorial of all numbers between 1 and n
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
Final Project - Java Beginners
Final Project  The importance of a graphical user interface..., but it is suggested that you begin working on the final project assignment in Week 5, which... the lectures, Quick Test Programs, and Lab assignments will prepare you for the final
ModuleNotFoundError: No module named 'Distance'
ModuleNotFoundError: No module named 'Distance'  Hi, My Python... 'Distance' How to remove the ModuleNotFoundError: No module named 'Distance... to install padas library. You can install Distance python with following
Delete points from database
Delete points from database  I have a polygon on a web page... in database. However the points are not getting deleted. I used this code..._error())); I also used: mysqlquery("DELETE FROM points WHERE ID=".$GET['ID
Until Loop In a Procedure
is false, the loop will be executed, until the final line of code in loop. ... Until Loop In a Procedure       Until Loop In a Procedure is used to execute a set of statements
How to put points on a JButton
How to put points on a JButton  I wanted to ask....what am i supposed to do if i wanna set points on my JButton so as to be able to draw arcs or curves.... supposedly my button represents a tile with 2 openings and the opening
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
Artifacts of com.end-points
List of Artifacts of com.end-points maven depenency
ModuleNotFoundError: No module named 'speed-date'
ModuleNotFoundError: No module named 'speed-date'  Hi, My Python... 'speed-date' How to remove the ModuleNotFoundError: No module named 'speed-date' error? Thanks   Hi, In your python environment you

Ads