*int*. The constructor should take an

*int*as its only parameter. I had to write a recursive method that checks if that

*int*is a multiple of 5, and also have to write a client class to test the class.

I have everything written, but my recursive method will not give me the correct result when the given number is _not_ a multiple of 5. I've tried restructuring the if/else statement, and also using a flag variable, with no luck. I'm assuming it's probably something little that I'm missing, but I've sat here looking at it for a while now and still can't figure it out.

Here is the class, MultipleOfFive.java:

/** * @(#)multipleOfFive.java * * * @author Dustin * @version 1.00 2009/11/30 */ public class MultipleOfFive { private int num; /** overloaded constructor * @param num number to be tested */ public MultipleOfFive( int number ) { num = number; } /** minusFive method * @param size the number to be tested to see if it is a multiple of five * @return string indicating if the number is a multiple of five */ public String minusFive( int size) { //boolean flag = false; if( (size == 0) || (size >= 5) ) { System.out.println( "Checking the number " + size + "\n" ); minusFive( size - 5 ); //flag = true; return num + " is a multiple of five"; } else { //flag = false; System.out.println( "Checking the number " + size + "\n" ); return num + " is not a multiple of five"; } //return num + " is a multiple of five"; //if ( flag == false ) //{ // return num + " is not a multiple of five"; //} //else //{ // return num + " is a multiple of five"; //} } /** accessor method * @return number to be tested */ public int getNumber( ) { return num; } /** mutator method * @param newNumber new number to be tested */ public void setNumber( int newNumber ) { num = newNumber; } /** toString method * @return prints the number to be tested */ public String toString( ) { return ""; } /** equals method * @param o1 another ArraySum object * @return a boolean, true if this object * has the same field values as the parameter o1 */ public boolean equals( Object o1 ) { if ( ! ( o1 instanceof MultipleOfFive ) ) return false; else { MultipleOfFive objMultFive = ( MultipleOfFive ) o1; return ( num == objMultFive.num ); } } }

The problem, I think, is in the recursive method, specifically lines 32-44. there's some stuff commented out, ignore it, it was other things I had tried.

Here's the client, in case it's needed:

/** * @(#)MultipleOfFiveClient.java * * * @author Dustin * @version 1.00 2009/11/30 */ import java.util.Scanner; public class MultipleOfFiveClient { public static void main ( String [] args ) { Scanner scan = new Scanner( System.in ); System.out.println( "This program will use recursion to test a number to see" + "\nif it is a multiple of five by repeatedly subtracting five." + "\n\nIf the process does not eventually end at zero, then the " + "\nnumber is not a multiple of five." + "\n\nEnter a number larger than 4 to test >" ); int testNumber = scan.nextInt( ); MultipleOfFive m1 = new MultipleOfFive( testNumber ); //MultipleOfFive.minusFive( MultipleOfFive.getNumber( ) ); System.out.println( "Results of test:\n" + m1.minusFive( m1.getNumber( ) ) ); } }

No matter what number is given, it always returns that the number _is_ a multiple of 5.

Thanks in advance for any advice on it.