Assignemnt #100 More Fill In Methods

Code

    ///Name: Morgan Kaplan
    ///Period: 5
    ///Project Name: More Fill In Methods
    ///File Name: MFIM.java
    
// More Fill-In Methods - Fix the broken methods and method calls (again).

import java.util.Scanner;

public class MFIM
{
	public static void main( String[] args )
	{
		// Fill in the method calls where indicated.
		System.out.println("Here we go.");

		System.out.println();
		System.out.println("Some random numbers, if you please: ");
		
        int aa=0;
        int bb=0;
        superRand(aa, bb);
		
		System.out.print("More counting, but this time not by ones: ");
		// count from 2 to 8 by 2s
		
         int first=0, last=0, step=0;
         stepCount(first, last, step);
		
		System.out.println();
		System.out.println("Let's figure a project grade.");
		
        int p1=1, p2=1, p3=1, p4=1, p5=1, p6=1;
        overall_grade(p1, p2, p3, p4, p5, p6);

		System.out.println();
		System.out.print("Finally, some easy ones.");
		
        getName();

		System.out.println();
		System.out.println("Do you feel lucky, punk?");
		
        crash();
		
        System.out.println();
	}

	public static void superRand(int aa, int bb )
	// Parameters are:
	//	int a;
	//	int b;
    {
        Scanner keyboard = new Scanner(System.in);

		System.out.print("First: ");
		aa = keyboard.nextInt();
	
        System.out.print("Second: ");
		bb = keyboard.nextInt();
		// picks a number between a and b, no matter which is larger
		int cc;

		if ( aa < bb )	// b is larger
        {
            cc = aa + (int)(Math.random()*(bb-aa+1));
        System.out.println("They are not the same.");
        }
        else if ( aa > bb )	// a is larger
            {
            cc = bb + (int)(Math.random()*(aa-bb+1));
            System.out.println("They are not the same.");
            }
            else
            {
			cc = aa;	// or c = b; doesn't matter since they're equal
        System.out.println("They are the same.");
            }
	}

 	public static void stepCount(int first, int last, int step )
	// Parameters are:
	//     int first;
	//     int last;
	//     int step;
    {
        first=2;
        last=10;
        step=2;
	
		// counts from 'first' to 'last' by 'step'
		// handles forward and backward
		int x;

		if ( first < last )
		{
			x = first;
			while ( x <= last )
			{
				System.out.print(x + " ");
				x = x + step;
			}
		}
		else
		{
			x = first;
			while ( x >= last )
			{
				System.out.print(x + " ");
				x = x - step;
			}
		}
	}

	public static void overall_grade(int p1, int p2, int p3, int p4, int p5, int p6 )
	// Parameters are:
	//     int p1, p2, p3, p4, p5, p6;
	{
		// given six integers representing scores out of five in each of the
		// six categories for the first six weeks project: tells you your
		// overall project grade out of 100

		int overall_grade;

		overall_grade = p1 * 6;    // six points per point for the first category
		overall_grade = overall_grade + ( p2 * 6 );   // six points per point
		overall_grade = overall_grade + ( p3 * 4 );   // four points per point
		overall_grade = overall_grade + ( p4 * 2 );   // two points per point
		overall_grade = overall_grade + ( p5 * 1 );   // one point per point
		overall_grade = overall_grade + ( p6 * 1 );   // one point per point

		System.out.println(" You're grade is " + overall_grade + ". ");
	}

	public static void getName()
	// No parameters.
	{
		// finds out the user's name
		Scanner keyboard = new Scanner(System.in);

		String name;
		System.out.print("Please enter your name: ");
		name = keyboard.next();

		System.out.println("Hi, " + name + ".");
	}

	public static void crash()
	// No parameters.
	{
		// displays "you win" or "you lose".  You lose 90% of the time.
		String magic_word;

		if ( (int)(Math.random()*10) == 0 )
		{
			// What do you know?  We won!
			magic_word = "win";
		}
		else
		{
			// No big suprise; we lost.
			magic_word = "lose";
		}

		System.out.print("you " + magic_word);

	}

}
    

Picture of Output

Assignment 100