In city street grids, intersections are often defined by two integers, counting the position of horizontal and vertical streets (sometimes called streets and avenues). Imagine traveling from position (h,, vi) to (h2, v2). How many blocks do you traverse? (h,, v.) (h,, v,) Even though there are many possible routes, the distance only depends on the differences h, - h, and v2 - V1. However, you need to take the absolute value because the differences might be negative. Complete the following program that prints the number of blocks traveled, given the origin and destination of the trip (which will change as your code is tested). Distance.java 1 public class Distance 2 { public static void main(String[] args) { // These values will be changed during testing int hl = 3; int vl = 4; int h2 = 4; int v2 = 4; 4 7 9. 10 11 .. 12 codecheck-bjlo-1e-02_06 System.out.print("Distance: "); System.out.println(distance); } 13 14 15 16 }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

In city street grids, intersections are often defined by two integers, counting the position of horizontal and vertical streets (sometimes called streets and avenues). Imagine traveling from position (h1, v1) to (h2, v2). How many blocks do you traverse? 

 

In city street grids, intersections are often defined by two integers, counting the position of horizontal and vertical streets (sometimes called streets and avenues). Imagine traveling from position (h,,
vi) to (h2, v2). How many blocks do you traverse?
(h,, v.)
(h,, v,)
Even though there are many possible routes, the distance only depends on the differences h, - h, and v2 - V1. However, you need to take the absolute value because the differences might be negative.
Complete the following program that prints the number of blocks traveled, given the origin and destination of the trip (which will change as your code is tested).
Distance.java
1 public class Distance
2 {
public static void main(String[] args)
{
// These values will be changed during testing
int hl = 3;
int vl = 4;
int h2 = 4;
int v2 = 4;
4
7
9.
10
11
..
12
codecheck-bjlo-1e-02_06
System.out.print("Distance: ");
System.out.println(distance);
}
13
14
15
16 }
Transcribed Image Text:In city street grids, intersections are often defined by two integers, counting the position of horizontal and vertical streets (sometimes called streets and avenues). Imagine traveling from position (h,, vi) to (h2, v2). How many blocks do you traverse? (h,, v.) (h,, v,) Even though there are many possible routes, the distance only depends on the differences h, - h, and v2 - V1. However, you need to take the absolute value because the differences might be negative. Complete the following program that prints the number of blocks traveled, given the origin and destination of the trip (which will change as your code is tested). Distance.java 1 public class Distance 2 { public static void main(String[] args) { // These values will be changed during testing int hl = 3; int vl = 4; int h2 = 4; int v2 = 4; 4 7 9. 10 11 .. 12 codecheck-bjlo-1e-02_06 System.out.print("Distance: "); System.out.println(distance); } 13 14 15 16 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr