The Mind Of Sauron

From Huben's Wiki
Jump to: navigation, search

Eye of sauron.jpg

We are going to write a sizable class, compile it, and run it. The goal is to get the variable and method declarations right and the arguments and returns right.

When writing variable declarations, you need to consider:

  • A good, meaningful name, usually a noun with perhaps some adjectives, following the naming conventions.
  • What type is best suited.
  • Whether or not it is an array.
  • If it is initialized here, the initial value(s).

When writing method declarations, you need to consider:

  • A good, meaningful name, usually starting with a verb following the naming conventions.
  • The arguments and their types. Some might be arrays.
  • The return type if needed, else void. The return type might be an array.
  • A few can be written completely. Others, just place a comment to show where code could be filled in later. (Those are called stubs.)


  • Be creative!
  • You may assist each other, or work in pairs. Be sure to put a comment at the top saying who takes credit for the code and who assisted you.

Write a class named Sauron with the following fields and methods:

  • Fields:
    • The number of Orcs in his army. (Make a guess.)
    • The number of Uruk-Hais in his army. (Make a guess.)
    • How many Hobbits it takes to feed an Orc one day (you can feed an Orc five days on a Hobbit.)
    • How many Hobbits it takes to feed an Uruk-Hai one day (you can feed an Uruk-Hai three days on a Hobbit.)
    • An array of three words of a spell.
  • Methods:
    • A method printing an evil cackle.
    • A method dispatching a number of ringwraiths to a location name. (It doesn't have to do anything, just have the arguments.)
    • A method for chanting a spell. Its argument is an array of words, three in number. It should call another method for each word that will print the word twice.
    • A method for calculating the number of Hobbits needed as food by a number of Orcs and a number of Uruk-Hais over some number of days.
    • A main() method.
      • Start with a cackle!
      • Chant the spell in your field, then chant another spell you make up.
      • Send 9 ringwraiths to The Shire.
      • Print the number of Hobbits needed as food for your army every week.
      • Print the number of Hobbits needed as food for your army every week if you double the number of Orcs.

When you are done, put the code and the results from running it into a document, then print it for me to grade. You can also show me what you've done at the computer any time. Do not get stuck: you should be able to get this done today if you persevere. If you can't then finish it for homework.

Rubric (partial credit is available for all items):

Points Description
30 Following instructions closely and completely.
20 Translation of an English description into a field or method.
10 Using a method more than once with different arguments rather than duplicating code.
10 Making and using arrays.
10 Initializing Strings and arrays of Strings.
10 Returned values must match the return type.
10 The difference between int and double, especially for division.
10 Meaningful names for methods and variables
Personal tools