Scrambler

A program with methods is found below. Your tasks are outlined below:

Level Tasks
1

Run the program.
Draw a structure chart for the program on paper.
Explain why (on that same paper) methods make this program more organized.
For each method (on that same paper), write the parameter names (NOT the types) and the return type.

2

Choose you own scenario.
Make a method for a scrambled word.
Make a method for a true/false test.

3

Make a method identification.
Make a method for matching.

4

Make a working multiple choice method that has this method signature. Call it correctly a few times in your program.

public int MCques (String ques, char corAns, String optA, String optB, String optC, String optD)

//pre: ques contains the question to be displayed, optA, optB, optC and optD contain the options, corAns contains 'a, 'b', 'c' or 'd', whichever is the correct answer.

//post: returns 1 if the user answers correctly and 0 if not.

4+

Make an additional method that does your own type of test.
Add correct pre and post conditions to your methods.

The program:

public class RPG_good
{ //the other version is for testing
//this one has a bit more in it

public static void main (String args [])
{
new RPG_good ();
}

   public RPG_good ()
   {
   campfire ();
   System.out.println ("You are a brownie at brownie camp. To earn your outdoors    ");
   System.out.println ("badge, you will need to pass a series of tests.");
   int points = 0;
   points = tent (points);
   points = fire (points);
   points = bear (points);
   points = animals (points);
 if (points >= 10)
   System.out.println ("You have earned your outdoors badge.");
   else
   System.out.println ("Sadly, you have not earned your outdoors badge.");
   }

   public void campfire ()
   {
   System.out.println (" ( ,&&&.");
   System.out.println (" ) .,.&&");
   System.out.println (" ( ( \\=__/");
   System.out.println (" ) ,'-'.");
   System.out.println (" ( ( ,, _.__|/ /|");
   System.out.println (" ) /\\ -((------((_|___/ |");
   System.out.println (" ( // | (`' (( `'--|");
   System.out.println (" _ -.;_/ \\\\--._ \\\\ \\-._/.");
   System.out.println (" (_;-// | \\ \\-'.\\ <_,\\_\\`--'|");
   System.out.println (" ( `.__ _ ___,') <_,-'__,'");
   System.out.println (" `'(_ )_)(_)_)'");
   }

   public int tent (int points)
   {
   System.out.println ("\n\n******* Test 1 *************\n\n");
   System.out.println ("Unscramble this word. It is a form of shelter.");
   String ans = IBIO.inputString ("ntte >>");
   int counter = 3;
   while (!ans.equals ("tent"))
   {
   System.out.println ("\tIncorrect, try again!");
   ans = IBIO.inputString ("ntte >>");
   counter--;
   }
   System.out.println ("\tCorrect, it is a tent!");
   if (counter < 0)
   counter = 0;
   printout (counter + points);
   return counter + points;
   }

   public int fire (int points)
   {
   System.out.println ("\n\n******* Test 2 *************\n\n");
   System.out.println ("Put the pieces of the fire in order, like this dcab.");
   String ans = IBIO.inputString ("a) kindling b) newspaper c) twigs d)logs    >>");
   if (ans.equals ("bacd"))
   {
   System.out.println ("\tYou are right!");
   points += 4;
   }
   else if (ans.equals ("abcd"))
   {
   System.out.println ("\tClose! put the newspaper in first!");
   points += 2;
   }
   else
   System.out.println ("\tIncorrect. The order is: newspaper, kindling, twigs,    logs");
   printout (points);
   return points;
   }

   public int bear (int points)
   {
   System.out.println ("\n\n******* Test 3 *************\n\n");
   System.out.println ("You are sleeping in your tent and you hear something    outside. True or false:");
   String ans = IBIO.inputString ("a) You scream as loudly as you can. (T/F)>>");
   if (ans.equals ("F") || ans.equals ("f"))
   {
   System.out.println ("\tYou are right!");
   points += 2;
   }
   else
   System.out.println ("\tIncorrect. That will wake up the others. There is    probably nothing.");
   ans = IBIO.inputString ("b) You stay in your tent. (T/F)>>");
   if (ans.equals ("T") || ans.equals ("t"))
   {
   System.out.println ("\tYou are right! Since you have no food stored in    your tent, you will be fine.");
   points += 2;
   }
   else
   System.out.println ("\tIncorrect. You shouldn't go to meet the bear.");
   ans = IBIO.inputString ("c) You go back to sleep? (T/F)>>");
   if (ans.equals ("T") || ans.equals ("t"))
   {
   System.out.println ("\tYou are right! It is easy to imagine there is a    bear when there isn't.");
   points += 1;
   }
   else
   System.out.println ("\tIncorrect. You need your rest.");
   printout (points);
   return points;
   }

   public int animals (int points)
   {
   System.out.println ("\n\n******* Test 4 *************\n\n");
   System.out.println ("Identify the animals.");
   bear ();
   String ans = IBIO.inputString (">>");
   if (ans.equals ("bear") || ans.equals ("Bear") || ans.equals    ("BEAR"))
   {
   System.out.println ("\tYou are right!");
   points += 1;
   }
   else
   System.out.println ("\tIncorrect. It is a bear.");
   turkey ();
   ans = IBIO.inputString (">>");
   if (ans.equals ("turkey") || ans.equals ("Turkey") || ans.equals    ("TURKEY"))
   {
   System.out.println ("\tYou are right!");
   points += 2;
   }
   else
   System.out.println ("\tIncorrect. It is a bear.");
   owl ();
   ans = IBIO.inputString (">>");
   if (ans.equals ("owl") || ans.equals ("Owl") || ans.equals    ("OWL"))
   {
   System.out.println ("\tYou are right!");
   points += 2;
   }
   else
   System.out.println ("\tIncorrect. It is a bear.");
   printout (points);
   return points;
   }

   public void bear ()
   {
   System.out.println (" (()__(()");
   System.out.println (" / \\ ");
   System.out.println (" ( / \\ \\");
   System.out.println (" \\ o o /");
   System.out.println (" (_()_)__/ \\ ");
   System.out.println (" / _,==.____ \\");
   System.out.println (" ( |--| )");
   System.out.println (" /\\_.|__|'-.__/\\_");
   System.out.println (" / ( / \\ ");
   System.out.println (" \\ \\ ( /");
   System.out.println (" ) '._____) / ");
   System.out.println (" (((____.--(((____/ grrrrr, grrrr.");
 }

   public void turkey ()
   {
   System.out.println (" _ ");
   System.out.println (" ( ) _");
   System.out.println (" (_` )_('> ");
   System.out.println (" (__,~_)8 ");
   System.out.println (" _YY_ gobble, gobble.");
   }

   public void owl ()
   {
   System.out.println (" ,___,");
   System.out.println (" (6v6) ");
   System.out.println (" (_^(_\\ ");
   System.out.println (" ^^^' ^ ' \\\\^^^^");
   System.out.println (" ^^^^^^^^^^^^^ twit, twit, twhooo");
 }

   public void printout (int points)
   {
   System.out.println ("\n\nYou currently have: " + points + " points.");
   if (points >= 10)
   System.out.println ("You have earned the outdoor badge!");
   else if (points == 5)
   System.out.println ("You are half way to earning the outdoor badge!");
   else
   System.out.println ("You have " + (10 - points) + " points left    to earn the badge\n\n");
   }
   }