Program #99

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Fill-In Functions
    /// File Name: Fill.java
    /// Date Finished: 3/8/2016 public class Fill

        import java.util.Random;
        
        public class Fill
        {
        	static Random r = new Random();
        	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");
        		char c = '!';
        		c = randChar();
        		System.out.println("The character is: " + c );
        
        		System.out.println();
        		System.out.println("Now let's count from -10 to 10");
        		int begin, end;
        		begin = -10;
        		end = 10;
        		counter(begin,end);
        		System.out.println("How was that?");
        
        		System.out.println();
        		System.out.println("Now we take the absolute value of a number.");
        		int x, y = 99;
        		x = -10;
        		y = abso(x);
        		System.out.println("|" + x + "| = " + y );
        
        		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 Afaf Nabeeha");
        		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);
        		// new word, capital letter!!!
        		return charVal;
        	}
        
        
        
        
        	public static void counter(int start,int stop )
        	{
        		int ctr;
        
        		ctr = start;
        		while ( ctr <= stop )
        		{
        			System.out.print(ctr + " ");
        			ctr = ctr + 1;
        		}
        		System.out.println("\n");
        	}
        
        
        
        	public static int abso(int value )
        	{
        		int absval;
        
        		if ( value < 0 )
        			absval = -value;
        		else
        			absval = value;
        		return absval;
        	}
        
        
        }
    

Picture of the output

Assignment 99