1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nataly862011 [7]
3 years ago
12

"Consider yourself driving with 60 miles/hour in a city that has only grid like streets, and your GPS is broken.The specificatio

ns of the problem are:• With (x, y) as the coordinates of the car, consider the initial position
(0,0)."At each intersection, the only directions available are North, South, East or West

The GPS is broken, and it chooses the direction randomly at each intersection, which happens every 5 minutes

The assumption is that the car has the same speed at all times, including when it changes direction and turns.

Write a program that calculates the distance from the initial point to the location point of the driver after one hour of driving.
Computers and Technology
1 answer:
timama [110]3 years ago
4 0

Answer:

see explaination

Explanation:

// Include the necessary header files.

import java.io.*;

import java.util.Random;

import java.lang.Math;

// Declare a class

public class GPS

{

// Definition of the function.

public static int randSel(int start, int fin)

{

// Declare the object of a class.

Random r = new Random();

// Declare an integer value and store

// value in it.

int rNum = r.nextInt((fin - start) + 1) + start;

// return value.

return rNum;

}

// Definition of the function.

public static double DistFromOrig(double X, double Y)

{

// Declare a double variable.

double dist;

// Calculate the distance.

dist = Math.sqrt(X * X + Y * Y);

// return distance.

return dist;

}

// Start the main method.

public static void main(String[] args)

{

try

{

// declare variables

double X = 0, Y = 0;

int time = 60;

final int NORTH = 0;

final int EAST = 1;

final int SOUTH = 2;

final int WEST = 3;

int Direction = 0;

// Start the while loop

while (time > 0)

{

// check whether the time is greater

// than 5 or not.

if (time >= 5)

{

// update the value of time.

time -= 5;

// call to the method.

Direction = randSel(0, 3);

if (Direction == NORTH)

{

// update the value of y cordinate.

Y = Y + 5;

// display the statement on console.

System.out.println("MOVED NORTH");

}

// Check the direction

if (Direction == EAST)

{

// update the value of x cordinate.

X = X + 5;

// display the statement on console.

System.out.println("MOVED EAST");

}

// Check the direction

if (Direction == WEST)

{

// update the value of x cordinate.

X = X - 5;

// display the statement on console.

System.out.println("MOVED WEST");

}

// Check the direction

if (Direction == SOUTH)

{

// update the value of y cordinate.

Y = Y - 5;

// display the statement on console.

System.out.println("MOVED SOUTH");

}

}

else

{

// Check the direction

if (Direction == NORTH)

{

// update the value of y cordinate.

Y = Y + time * 1;

time = 0;

}

// Check the direction

if (Direction == EAST)

{

// update the value of x cordinate.

X = X + time * 1;

time = 0;

}

// Check the direction

if (Direction == WEST)

{

// update the value of x cordinate.

X = X - time * 1;

time = 0;

}

// Check the direction

if (Direction == SOUTH)

{

// update the value of y cordinate.

Y = Y - time * 1;

time = 0;

}

}

}

// Display the statement on console.

System.out.println(

"Distance of Car After Traveling 1 Hr is "

+ DistFromOrig(X, Y)

+ " miles");

}

// Start the catch block.

catch (Exception e)

{

e.printStackTrace();

}

}

}

You might be interested in
CODING IN C++ URGENT HELP PLEASE
forsale [732]

Answer:

this is hard i thought i knew it wow u have hard stuff in your school

Explanation:

7 0
3 years ago
Peter has a website that promotes his local vacation rental site. He uses Google Ads to manage his advertising campaign. He's cr
Mkey [24]

Answer:

The attributed reason for the discrepancy is that Conversion tracking is generating duplicate conversions.

4 0
3 years ago
If the transmitting device would like for the receiving device to push currently buffered data to the application on the receivi
Andreyy89

Answer:

The right approach will be "PSH".

Explanation:

  • The PSH flag seems to be an acceptable solution through TCP which always encourages the submit implementation to immediately transfer data but only whenever the buffer isn't complete.
  • The implementation helps to formulate this same flag towards true for something like the connection, as well as TCP will instantly begin transmitting the relevant information.
3 0
3 years ago
Why hasn't net neutrality been taken away? It's past Dec 14.
Roman55 [17]
Because it was only passed, now they have to decide what they want to do 
6 0
3 years ago
Which of the following statements is true?
Luden [163]

Answer:

Option (A) int expressions are always computed exactly; but float expressions can suffer round-off error.

Explanation:

Round - Off Error can be defined as the digital computers have limitations on denoting the decimal numbers,  due to this the floating point numbers have to be rounded off or even it is represented exactly after the calculation on the numbers the resulting number has to be adjusted / rounded off according to the specified precision. The resulted number has to be rounded off back to the required precision, this leads to the round off errors in digital computers. As integers don't need to go through the rounding off in computers, the integer numbers don't have round off errors, only floating point numbers have round off errors. So, options (B) , (C) and (D) are false.

6 0
3 years ago
Other questions:
  • The key invention that enabled computers to go into every home and office is
    7·1 answer
  • Tom is the aerobics coordinator at a fitness center. He needs a more efficient way for his instructors to share information. Cla
    13·2 answers
  • 3. How can you correct the color of your photos automatically?​
    15·2 answers
  • How many worksheets display in the Excel window when you create a new blank workbook? A. 1 B. 2 C. 3 D. 4
    9·2 answers
  • Joel has left his computer unattended while answering a phone call. A TV repairer in his house tries to surf through the applica
    13·1 answer
  • Write a deffrentiate between inkjet peinter and laser printer​
    8·1 answer
  • What natural resources products are discussed in the article? Are they renewable or nonrenewable?
    6·2 answers
  • The optical phenomenon that allows us to view rapidly changing still images as moving images is called _______.
    15·2 answers
  • Place the steps in order for creating a filter in Outlook 2016.
    9·1 answer
  • What was one effect of better printing methods during the Ming Dynasty? Updated trade routes A new merchant class Increased lite
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!