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
All of the following are valid Excel arithmetic operators except _____.
stellarik [79]
All the following are valid Excel arithmetic operators except D (>). caret(^), asterisk(*), percent(%) and plus/minus (+,-) signs are all arithmetic. Letter D the greater than and less than sign(<, >) is a comparison operators where you compare two values using greater/less than signs.
3 0
3 years ago
Your first submission for the CIS 210 Course Project should include the following functionality: - Requests the user to input hi
Viefleur [7K]

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String name;

 System.out.print("First name: ");

 name = input.next();

 name= name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();

 System.out.print(name);

}

}

Explanation:

This declares name as string

 String name;

This prompts the user for first name

 System.out.print("First name: ");

This gets the name from the user

 name = input.next();

This capitalizes the first letter of name and makes the other letters to be in lowercase

 name= name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();

This prints the formatted name

 System.out.print(name);

5 0
3 years ago
What are 7 key traits for knowing your audience
evablogger [386]
Ask them what's ur name and get to the know them i have nothing really.
5 0
3 years ago
Read 2 more answers
How does the speaker feel about traditional forms of poetry
Salsk061 [2.6K]
A speaker sometimes is not able to capture the intended details since it is affected by homophones.
7 0
3 years ago
Read 2 more answers
Which of the following is a technique for storing or copying log events to acentralized logging server?a. Syslogb. Write­once re
Neporo4naja [7]

Answer:A) Syslog

Explanation: Syslog is the log for the messaging in the computing field.It acts as a separator for the different task that is related to messaging. The task usually are storing of message, production of the message through software,analyzing message, reporting it etc.

Other options given in the question such as WORM storage is for the storage technology,UTM is for the management for the threat situation and firewall logging is related with log/tables for firewall.

Thus, the correct option is option (A).

5 0
3 years ago
Other questions:
  • Which is the last step in conducting a url research
    11·1 answer
  • _____ _____ deals with the definitions properties of mathematical models of computation.
    8·1 answer
  • LeonRoyal15 if anyone plays fortnite
    10·2 answers
  • How do you change the name on your brainly account?
    12·1 answer
  • Which of these is an example of rebranding ?
    6·2 answers
  • What happens if none of the selector values match selector in a simple case expression in pl/sql
    6·1 answer
  • Edhesive unit 4 test answers
    15·1 answer
  • Which class members should be declared as public?
    12·1 answer
  • Your network has been having problems lately when users are participating in video conferences - the video and audio stutters ve
    13·1 answer
  • Hyperlink is a term used to refer to the specific manner of specifying the address of a website. Write reason for true or false.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!