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
The steps for creating a newsletter are to ____.
leonid [27]

Answer:

C) Plan, write, format, and proofread

Explanation:

You need a plan for any professional newspaper. Proofreading is also a vital step in the process. You can only format what you've already written, so it has to be C.

4 0
3 years ago
Which of the following is NOT one of the three basic structures used to solved logical problems?
Oliga [24]
I think module is not one of the theee basic structure
8 0
3 years ago
Wireshark capture files, like the DemoCapturepcap file found in this lab, have a __________ extension, which stands for packet c
grin007 [14]

Answer:

The answer is ".pcapng"

Explanation:

Wireshark format includes a "dump" with data packets, which is collected over a channel and sometimes a common folder to store, that data in the PCAP Next Iteration file system.

  • The .pcapng stands for the file system, this file system compatible with the recorded data transmission packet. It includes several data blocks.
  • It is quite robust, but it should not be helped by the other devices. Wireshark allows the libpcap system as well.
5 0
3 years ago
Someone help me out eh?
Elodia [21]

Line 4

It should be font-size: 15px

Also there should be curly braces in line 5.

6 0
3 years ago
Read 2 more answers
This is gonna be very long but I have no idea what to do, I'm confused.
kaheart [24]

for such experiment, you do it with care and to acquire and determine to put experience in it

Explanation:

because without you been or using experience the experiment will not correct

8 0
2 years ago
Other questions:
  • This is the main work area of your computer.
    7·1 answer
  • Define a function CoordTransform() that transforms the function's first two input parameters xVal and yVal into two output param
    11·1 answer
  • Erick, who is taking an online course, sent an e-mail to his
    14·2 answers
  • Which device on a network performs network address translation?
    8·1 answer
  • Which of the following statements is true?
    12·1 answer
  • In regard to protective actions for explosive devices, the area where the blast originates is referred to as ___________ perimet
    8·1 answer
  • Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well all vehicles in its Guz
    15·1 answer
  • What do level meters show?
    8·1 answer
  • Draw
    7·1 answer
  • can you still receive messages on messenger from a person when you deleted the conversation with them? (But not blocked them)
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!