Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The program below (also here) simulates a race between Achilles and a Tortoise. Achilles is twice as fast, so should overtake the Tortoise (who has
The program below (also here) simulates a race between Achilles and a Tortoise. Achilles is twice as fast, so should overtake the Tortoise (who has a head start of 100 distance units). String a = "Achilles"; String t = "Tortoise"; double aPos = 0; double tPos = 100; double aSpeed = 20; double tSpeed = 10; double totalTime = 0; while (aPos < tPos) { System.out.println("At time: " + totalTime); System.out.println(" " + a + " is at position " + aPos); System.out.println(" " + t + " is at position " + tPos); double timeToReach = (tPos - aPos) / aSpeed; totalTime = totalTime + timeToReach; aPos = aPos + timeToReach * aSpeed; tPos = tPos + timeToReach * tSpeed; }
I have a quick question here in that it's apparent that if we let aPos + timeToReach * aSpeed = tPos + timeToReach * tSpeed, it's easy to conclude that timeToReach will be 10. However, since we use while here, which indicates iteration in Java, the computer gets 3.55 x 1014 at the end. So what is the logic of applying such an algorithm
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started