105 lines
2.8 KiB
Java
105 lines
2.8 KiB
Java
/**
|
|
* <PRE>
|
|
* IterationTest.java
|
|
*
|
|
* Revisions: 1.0 Sep. 02, 2002
|
|
* Created the IterationTest class
|
|
* 1.1 Sep. 03, 2002
|
|
* Compiled, Finished, Tested, Commented
|
|
*
|
|
* </PRE>
|
|
*
|
|
* Collaboration Statement:
|
|
* I worked on the homework assignment alone, using only
|
|
* course materials.
|
|
*
|
|
* Created with JCreatorLE, some indents are off when viewed through notepad
|
|
* or EMACS
|
|
*
|
|
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @version Version 1.1, Sep. 02, 2002
|
|
*/
|
|
|
|
public class IterationTest {
|
|
|
|
public static final boolean bDebug = false;
|
|
|
|
/**
|
|
* Prints the specified message the specified number of times.
|
|
* <BR>
|
|
* For example: printMessageALot("5 times!",5) would print
|
|
* 5 times!
|
|
* 5 times!
|
|
* 5 times!
|
|
* 5 times!
|
|
* 5 times!
|
|
* <BR><BR>
|
|
* @param message the message to print
|
|
* @param count the number of times to print the message
|
|
*/
|
|
public void printMessageALot(String message, int count) {
|
|
|
|
if(bDebug){
|
|
System.out.println("Begin iteration");
|
|
}
|
|
|
|
//actual code
|
|
for(int i = 0; i<count; i++){
|
|
System.out.println(message);
|
|
}
|
|
|
|
if(bDebug){
|
|
System.out.println("End iteration");
|
|
}
|
|
} //end printMessageALot(String,int)
|
|
|
|
|
|
/**
|
|
* Returns the first number raised to the power of the second number.
|
|
* <BR>
|
|
* For example: power(4,3) would return 4 * 4 * 4 = 64
|
|
* <BR><BR>
|
|
* @param base the number to raise to the power
|
|
* @param exponent the power to raise the base to (will always be greater
|
|
* then 0)
|
|
* @return the base raised to the exponent
|
|
*/
|
|
public int power(int base, int exponent) {
|
|
int current = base;
|
|
|
|
if(bDebug){
|
|
System.out.println("Begin iteration");
|
|
}
|
|
|
|
//actual code
|
|
for(int i=1; i<exponent;i++){
|
|
current *= base;
|
|
}
|
|
|
|
if(bDebug){
|
|
System.out.println("End iteration");
|
|
}
|
|
return current;
|
|
} //end power(int,int)
|
|
|
|
/**
|
|
* Debugging main for class IterationTest.
|
|
* This method will rigorously test my code.
|
|
*
|
|
* <br><br>
|
|
* @param args a String array of command line arguments.
|
|
*/
|
|
public static void main(String[] args) {
|
|
|
|
IterationTest iterationtest = new IterationTest();
|
|
|
|
//HelloWorld to the XTREME!!! Live the eXPerience!!!
|
|
iterationtest.printMessageALot("Hello World!",5);
|
|
|
|
System.out.println(iterationtest.power(2,2));
|
|
System.out.println(iterationtest.power(3,3));
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class IterationTest
|