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
True or false a mirrorless camera has a pentaprism
inessss [21]

Answer:

No the pentaprism or pentamirror are both optical viewfinder viewing systems and are not part of the mirrorless camera. Some thing the pentaprism actually operates better than the electronic viewfinder of mirrorless cameras.

Explanation:

7 0
2 years ago
Read 2 more answers
Although heart rate increases and decrease depending upon activity level on average a typical person heart rate is about _____ b
ExtremeBDS [4]

Answer:

72

The normal resting heart rate is between 70 and 100 bpm.

4 0
3 years ago
AI is not embraced everywhere in every industry because _______.
Nitella [24]

Answer:

See below:

Explanation:

AI is not embraced in every industry because of the type of industry and what it requires. In some situations, a human is needed since an AI cannot determine what to do and can sometimes even cause death.

AI isn't embraced everywhere because for some things we need a person, lets say for example, we need an AI to respond to 911 calls, that simply won't work due to the many situations and training the bot too will be a nightmare. For example, if a caller says a word that normal humans can understand, or a "code word" that every human knows but they haven't bothered to tell the bot, that will be the end of the line for them.

There are mutliple reasons to not use AI depending on the situation whether its life and death or just plain impractical.

7 0
3 years ago
Which of the following is where you can save, select a template, change document properties, and close or exit excel?
Aneli [31]
It is the 'backstage' in which you can <span>save, select a template, change document properties, and close or exit excel</span>
5 0
3 years ago
Challenge activity 6.1.3 function call with parameters
Kobotan [32]

Answer:

Printing formatted measurement Define a function PrintFeetinchShort, with int parameters numFeet and numinches, that prints using and "shorthand. End with a newline. Ex: PrintFeetinchShort(5, 8) prints: 5' 8" Hint: Use to print a double quote. ра 1 #include <stdio.hu 2 3 / Your solution goes here */ 4 5 int main(void) 6 int userFeet: 7 int user Inches: 8 9 scanf("%d", BuserFeet): 10 scanf("%d", Suser Inches); 11 12 PrintFeet InchShort(userFeet, user Inches); 13 14 return 0; 15) // Will be run with (5, 8), then (4, 11) Run

5 0
2 years ago
Other questions:
  • Which of the following is NOT a good idea to do after you change the root password?
    12·1 answer
  • Why might you use the "search network campaigns with display opt-in" campaign type?
    11·2 answers
  • If you have a windows 8, but want the features of windows 8 pro, purchase and install _______.
    7·1 answer
  • Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follo
    5·1 answer
  • Advantages of purchasing a software package over developing software in-house include all of the following except ____. Group of
    13·1 answer
  • What makes a distributed denial of service attack "distributed"? It involves many ip addresses. It attacks multiple systems. It
    9·1 answer
  • Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" i
    9·1 answer
  • A web application is an example of:
    7·1 answer
  • In Excel, you can sort a table by one or more columns by.
    7·1 answer
  • Try to crack the code:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!