Question: JAVA Part 3 Description Modify the Multiples class so that it implements the Sequence interface (which is given to you already completed). It should have
JAVA
Part 3 Description
Modify the Multiples class so that it implements the Sequence interface (which is given to you already completed). It should have a constructor that takes an integer num and stores it in a field. Its nextVal method should return (as an int) the next multiple of num (num*1, num*2, num*3, etc.) The reset method should cause it to start back at the first multiple. For example:
| Multiples m = new Multiples(3); m.nextVal(); // returns 3 m.nextVal(); // returns 6 m.nextVal(); // returns 9 m.reset(); m.nextVal(); // returns 3 m = new Multiples(2); m.nextVal(); // returns 2 m.nextVal(); // returns 4 |
Part 3 Starter Code
Copy the following start code into a file called Multiples.java
| public class Multiples { private int num; private int counter; // YOUR CODE HERE } |
Copy the following start code into a file called Sequence.java
| public interface Sequence{ public int nextVal(); public void reset(); } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
