Assignment #99 and Fill-In Functions
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Fill-in Functions
/// File Name: FillInFunctions.java
/// Date Finished: 1/07/2016
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;
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 Joshua Davis");
System.out.println("modified by Lauren Baird");
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()
{
int numval;
char charval;
numval = (int)(Math.random()*26);
charval = (char) ('A' + numval);
return charval;
}
public static void counter( int start, int stop )
{
while ( start <= stop )
{
System.out.print( start + " " );
start = start + 1;
}
}
public static int abso( int x )
{
int absval;
if ( x < 0 )
absval = -x;
else
absval = x;
return absval;
}
}