Assignment #98: Fill In Functions

Code

// Fill-In Methods - Fix the broken methods and method calls.

import java.util.Random;

public class FillInFunctions
{
	public static void main( String[] args )
	{
		// Fill in the method calls where appropriate.

		System.out.println("Watch as we demonstrate methods.");

		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 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 = -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 String credits()
	{

		System.out.println();
		System.out.println("programmed by Joshua Davis");
		System.out.println("modified by Kiran O'Farrell");
		System.out.print("This code is distributed under the terms of the standard ");
		System.out.println("BSD license.  Do with it as you wish.");

		return "credits";
	}


	public static char randChar()
	{
		// chooses a random character in the range "A" to "Z"
		
		int numval;
		char charval;
        Random r = new Random();

		// pick a random number from 0 to 25
		numval = r.nextInt(26);
		// now add that offset to the value of the letter 'A'
		charval = (char)('A' + numval);

		return charval;
	}



	public static int counter( int begin, int end )
   
	{
		// counts from start to stop by ones
		int ctr;

		ctr = begin;
		while ( ctr <= end )
		{
			System.out.print(ctr + " ");
			ctr = ctr+1;
		}

		return ctr;
	}

	public static int abso( int value )

	{
		// finds the absolute value of the parameter
		int absval;

		if ( value < 0 )
			absval = -value;
		else
			absval = value;

		return absval;
      
    }
}


    

Picture of the output