I am trying to write a program that will take the integer input from a user and print out its factors. I'm trying to do this by creating a class FactorGenerator and methods nextFactor and hasMoreFactors.
The nextFactor method must return an integer and the hasMoreFactors must return a boolean.
I am a bit confused as to how to declare a method that returns a boolean. Because, I think that if I'm able to do that properly, most of my errors might go away. Please guide me as to what I need to fix because I've spent a lot of time trying to fix the code and look up boolean methods but haven't reached anywhere.
import java.util.Scanner;
import java.lang.Boolean;
public class myProgram
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = in.nextInt();
FactorGenerator myFacGenerator = new FactorGenerator(num);
while (myFacGenerator.hasMoreFactors())
System.out.println(myFacGenerator.nextFactor);
}
public int FactorGenerator(int number)
{
int number = num1;
return num1;
}
public int nextFactor(int num1) // method that returns the factors of the input number
{
int i;
System.out.format("Factors of %d\n " + num1);
for (i = 1; i <= num1; i++)
{
if (num1 % i == 0)
{
return i;
}
}
}
public Boolean hasMoreFactors(boolean b) // method that is meant to check if there are any more factors left. This method returns boolean
{
Boolean b1 = num1.equals(i);
return b1;
}
}
` Some of the error messages include:
MyProgram.java:27: error: illegal start of expression
public int nextFactor(int num1) //Returns integer
^
MyProgram.java:27: error: ';' expected
public int nextFactor(int num1) //Returns integer
^
MyProgram.java:27: error: ';' expected
public int nextFactor(int num1) //Returns integer
^
MyProgram.java:45: error: illegal start of expression
public Boolean hasMoreFactors(boolean b); // Returns boolean
^
MyProgram.java:45: error: ';' expected
public Boolean hasMoreFactors(boolean b); // Returns boolean
^
MyProgram.java:45: error: ';' expected
public Boolean hasMoreFactors(boolean b); // Returns boolean
^
6 errors