Answered step by step
Verified Expert Solution
Question
1 Approved Answer
RobotSE (extension of becker.jar/becker robot)is a new kind of robot with extended capabilities such as turnAround, and turnRight. RobotSE also makes public a number of
RobotSE (extension of becker.jar/becker robot)is a new kind of robot with extended capabilities such as turnAround, and turnRight. RobotSE also makes public a number of protected methods in Robot.
[For this problem, you are creating a new kind of robot.] Write a class called PrimeMover that extends RobotSE. Include a standard 4-parameter constructor, and then write a custom move (int n) method that makes the robot move forward n intersections, but only if n is a prime number, otherwise, the robot should not move. Recall that a prime number is a positive integer greater than 1 whose only positive integer factors are 1 and itself. The first few primes are 2, 3, 5, 7, 11, 13, 17, ... (An integer larger than 1 that is not prime is called composite. The integer 1 itself is a special case, since it is neither prime nor composite it is called a unit.) Instead of putting the prime-testing code inside your custom move method, apply the principle of stepwise refinement, which says you should break larger tasks into smaller sub-tasks, and then write a method for each sub-task. For the current exercise, the sub-task is testing whether or not an integer is prime. Since a prime-testing method does not need to use any information about a robot, it is most appropriate to make it static (standalone), and this means it can easily be placed in another class. Write a class called ExtraMath, and in this class put a static method called isprime that takes an int argument and returns a boolean. The return value should, of course, be true if the input is a prime number, and false otherwise. Recall that in Java, a return statement looks like this: returnStep 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