Assignment #99
Code
/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Fill-In Functions
/// File Name: FillInFunctions.java
/// Date Finished: 1/29/2016
import java.util.Random;
public class FillInFunctions {
public static void main( String[] args ) {
System.out.println("Watch as we demonstrate functions.");
System.out.println();
System.out.println("I'm going to get a random character from A-Z");
System.out.println("The character is: " + randChar() );
System.out.println();
System.out.println("Now let's count from -10 to 10");
int start, stop;
start = -10;
stop = 10;
counter( start, stop);
System.out.println("How was that?");
System.out.println();
System.out.println("Now we take the absolute value of a number.");
int x = -10;
System.out.println("|" + x + "| = " + abso( x ) );
System.out.println();
System.out.println("That's all. This program has been brought to you by:");
credits();
}
public static void credits() {
System.out.println();
System.out.println("programmed by Graham Mitchell");
System.out.println("modified by Jonathan Grant Stine");
System.out.print("This code is distributed under the terms of the standard ");
System.out.println("BSD license. Do with it as you wish.");
}
public static char randChar() {
Random r = new Random();
int numval;
char charval;
numval = 1 + r.nextInt(26);
charval = (char) ('A' + numval);
return charval;
}
public static int counter( int begin, int end ) {
int ctr;
ctr = begin;
while ( ctr <= end ) {
System.out.print(ctr + " ");
ctr = ctr+1;
}
return ctr;
}
public static int abso( int value ) {
int absval;
if ( value < 0 )
absval = -value;
else
absval = value;
return absval;
}
}
Code Output