Java

OOP GUIDE / WORK

 

MULTPRACTICE CLASS

 

Topics

  • Using an interface
  • Class design

 

Source

  • This question was part of the 2017 AP exam free response questions.  You can find a link to all free response questions on the previous page.

 

 

TASK – PART 1 – SETUP – STUDYPRACTICE INTERFACE

 

Copy and paste the following interface to your IDE.

 

 

public interface StudyPractice

{

     /** Returns the current practice problem. */

     public String getProblem();

 

     /** Changes to the next practice problem. */

     public void nextProblem();

}  

 

 

 

TASK – PART 2 – WORK

 

Click here for a PDF containing the work that you must do.

 

 

TASK – PART 3 – TESTING YOUR CLASS

 

Copy and paste the following code that will test your MultPractice class.  Note that the program below matches the examples from the questions so you should compare your results with the results in the examples.  You should also consider adding your own tests.

 

Note that your program should have implemented the StudyPractice interface.  If you forgot to do so, the program below will still work but you would have not got perfect on this question.

 

 

public class MultPracticeTester

{

     public static void main(String[] args)

     {

           //EXAMPLE 1

           StudyPractice p1 = new MultPractice(7, 3);

           System.out.println(p1.getProblem());

           p1.nextProblem();

           System.out.println(p1.getProblem());

           p1.nextProblem();

           System.out.println(p1.getProblem());

           p1.nextProblem();

           System.out.println(p1.getProblem());

          

           //EXAMPLE 2

           StudyPractice p2 = new MultPractice(4, 12);

           p2.nextProblem();

           System.out.println(p2.getProblem());

           System.out.println(p2.getProblem());

           p2.nextProblem();

           p2.nextProblem();

           System.out.println(p2.getProblem());

           p2.nextProblem();

           System.out.println(p2.getProblem());

     }

}