Game Platform

A gaming company is working on a platformer game. They need a method that will compute the character's final speed, given a map and a starting speed.

The terrain on which the game character moves forward is made from various pieces of land placed together. Implement the method calculateFinalSpeed which takes the initial speed of the character, and an array of degrees of inclination that represent the uneven terrain.

The speed of the character will increase or decrease proportionally to the incline of the land, as shown in the image below:

Image showing the increase and decrease of character speed.

The magnitude of the angle of inclination will always be < 90°. The speed change occurs only once for each piece of land. The method should immediately return 0 as the final speed if an incline reduces the speed to 0 or below 0, which makes the character lose 1 life.

For example, the below code:

System.out.println(calculateFinalSpeed(60.0, new int[] { 0, 30, 0, -45, 0 }));

should print:

75
Java SE 21
Loading...
Loading...

Tags

  • AI-resistant
  • Java
  • Arithmetic
  • Arrays
  • Iteration
  • New
  • Public
  • Easy

Information

Difficulty: Easy

Duration: 15 min

Score Distribution

Not enough data for chart.

Would you like to see our other questions?

We have 1000+ premium hand-crafted questions for 160+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.

Would you like to see our tests?

The following tests contain Java related questions:

On the blog

Since we're all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they've been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts...