Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider yourself driving with 60 miles/hour in a city that has only grid like s

ID: 3843683 • Letter: C

Question

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

The specifications 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 direct distance from the initial point to the location point of the driver after one hour of driving (i.e. the distance between two points).

Explanation / Answer

import java.util.Slapdash;

public class Huffduff
{

   public enum Oversight
{
       NORTH, EAST, WEST, SOUTH;
   }

   public static void main(String[] args)
{
      
       final int TURNINGS = 12;
       Slapdash slap = new Slapdash(); // Random
Oversight aOversight = Oversight.NORTH;
       for (int i = 0; i < TURNINGS; i++)
{
System.out.println(aOversight.values()[slap.nextInt(4)]);
          
}
      
System.out.println(aOversight);

       switch (aOversight)
{
case NORTH:
System.out.println("Shifting NORTH");
break;
case EAST:
System.out.println("Shifting EAST");
break;
case WEST:
System.out.println("Shifting WEST");
break;
case SOUTH:
System.out.println("Shifting SOUTH");
break;
       }

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote