Factoring of integers. Write a program that asks the user for an integer and then prints out all its factors in increasing order. For example, when the user enters 150, the program should print

2
3
5
5

Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorPrinter whose main method reads a user input, constructs a FactorGenerator object, and prints the factors.

Complete the following files:

FactorGenerator.java

/** This class generates all the factors of a number. */ public class FactorGenerator { // TODO: instance fields /** Creates a FactorGenerator object used to determine the factor of an input value. @param aNum is the input value */ public FactorGenerator(int aNum) { // TODO } /** Determine whether or not there are more factors. @return true there are more factors */ public boolean hasMoreFactors() { // TODO } /** Calculate the next factor of a value. @return factor the next factor */ public int nextFactor() { // TODO } }

FactorPrinter.java

Use the following file:

FactorGeneratorTester.java

public class FactorGeneratorTester
{
   public static void main(String[] args)
   {
      FactorGenerator generator = new FactorGenerator(2 * 2 * 3 * 5);
      System.out.println(generator.hasMoreFactors());
      System.out.println("Expected: true");
      System.out.println(generator.nextFactor());
      System.out.println("Expected: 2");
      System.out.println(generator.hasMoreFactors());
      System.out.println("Expected: true");
      System.out.println(generator.nextFactor());
      System.out.println("Expected: 2");
      System.out.println(generator.hasMoreFactors());
      System.out.println("Expected: true");
      System.out.println(generator.nextFactor());
      System.out.println("Expected: 3");
      System.out.println(generator.hasMoreFactors());
      System.out.println("Expected: true");
      System.out.println(generator.nextFactor());
      System.out.println("Expected: 5");
      System.out.println(generator.hasMoreFactors());
      System.out.println("Expected: false");
   }
}