//the code below is the class
public class FactorGenerator
{
//creates the FactorGenerator object
public FactorGenerator(int n1)
{
number = n1;
factor = 2;
}
//determines whether there are more factors or not
public boolean hasMoreFactors()
{
answer = true;
while(number % factor != 0 && answer == true)
{
if (factor >= number)
{
answer = false;
}
factor++;
}
return answer;
}
//calculates the next factor
public int nextFactor()
{
while(factor < number)
{
if(number%factor == 0)
{
number/= factor;
break;
}
else
factor++;
}
return factor;
}
private boolean answer;
private int factor, number;
}
/*the code above is the class, tester is below
NOTE: THEY ARE TWO SEPARATE FILES ON MY COMPUTER.
*/
import javax.swing.JOptionPane;
public class FactorGeneratorTester
{
public static void main(String[] args)
{
String n1=JOptionPane.showInputDialog("Enter a number to factor");
int number = Integer.parseInt(n1);
FactorGenerator f1 = new FactorGenerator(number);
f1.hasMoreFactors();
do
{
System.out.println(f1.nextFactor());
}while(factor<0);
}
}
Refactorings
No refactoring yet !
b-kovar.myopenid.com
October 22, 2009, October 22, 2009 20:52, permalink
nah never mind I got it with some help from my friend. lol, it was so simple now that I think about it
Hello, I am making a FactorGenerator Class and Tester, but I am stuck. So far, I have the lines of code below for my class and my tester. Can someone proofread them and help me out?
P.S. I am new to Java, so I may have messed up a few things.