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
What are the advantages and disadvantages of UTF-8 compared to ASCII?
Romashka [77]

Answer:

UTF-8 and ASCII both are the character encoding.

In a system,every character has some binary representation,these are the method to encode them.Earlier only ASCII was there, for every character it uses 8 bits to represent.In ASCII only 8 bytes were there i.e 2^8 that is 256.We can't represent number beyond than 127 so it generate a need for other encoding to get into,these drawbacks lead to Unicode,UTF-8.

As ASCII codes only uses a single byte,UTF-8 uses upto 6 bytes to represent the characters.So we can save characters which are as long as 2^48 characters. We can read this encoding easily by the help of shift operators and it is also independent of byte order.

As messages on internet were transferred over 7 bit ASCII messages,so many mail servers removed this encoding.    

6 0
3 years ago
The ________ keyboard layout gets its name from the first six letters in the top left row of alphabetic keys on the keyboard and
wel
The qwerty layout Is what it's called
7 0
3 years ago
_____ refers to software for creating, maintaining, and manipulating data. group of answer choices extranet rom internet 2 ram d
Sliva [168]

Database management system (DBMS) refers to software for creating, maintaining, and manipulating data.

In the field of software engineering, a database management system (DBMS) can be described as a software whose function is to properly manage a database. Any kind of data in a database can be created, changed, or retrieved through the database management system (DBMS).

It is through the database management system (DBMS) that data is created, gets secured and its integrity is maintained. Through the database management system (DBMS), a certain piece of data can be assessed by various people at the same time from different locations.

Some examples of database management systems are columnar DBMS, NoSQL DBMS, and in-memory DBMS.

To learn more about the database management system (DBMS), click here:

brainly.com/question/19089364

#SPJ4

5 0
2 years ago
In an array list the time complexity of the remove function is identical to the time complexity of the ____ function.
yaroslaw [1]

Answer:

C. is Full

Explanation:

In an array list the time complexity of the remove function is identical to the time complexity of the ''isFull'' function.

3 0
4 years ago
Read 2 more answers
How is binary number related to real number?
Bogdan [553]

Answer:

.....................????..?..

7 0
3 years ago
Read 2 more answers
Other questions:
  • In which slot is a video card most commonly installed within a laptop?
    9·1 answer
  • How do I change the year I was born on this website? I made a mistake and now I can't fix it. Can somebody please help me?
    5·1 answer
  • Explain the ten characteristics of a digital computers​
    14·1 answer
  • Write down the pseudo code of a program that calculates the Body Mass Index (BMI) of
    9·1 answer
  • The number of square units required to cover a surface.
    13·1 answer
  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Promp
    10·1 answer
  • Implement a function called merge that does the following in C#:
    7·1 answer
  • Charlie makes pizza at a restaurant. The customers always compliment how great the pizza tastes. But Charlie takes a long time t
    7·2 answers
  • REAL ANSWERS ONLY!!! BRAINLLIEST AND 50 POINTS FOR BEST ANSWER
    11·2 answers
  • What is the purpose of memory address?​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!