Welcome to SWYK check 3!

Time to show what y'all know!

Set up

Before continuing, verify each of the following:

  1. You have a partner, whose name you have memorized.
  2. The partners are sitting side by side with their laptops, and can both easily see both screens.
  3. The director has a browser open to this page: http://stephendavies.org/cpsc240/micro.html
  4. The typist has two windows logged into the cpsc server.
  5. The typist has created a new, empty directory for this SWYK check.
  6. The typist has cd'd into that directory in both windows.

The typist should then perform the following commands to download the template and test harness for this SWYK check:

Then, set up the following aliases in your right-most window (note that the test harness has been renamed to TestMicro.java):

For this SWYK check, you can type compile in the right-most window to compile your code, and runtests to run the tests against it.


The actual problem

For this problem, you are to write two classes, one called Food and the other called Microwave. These are illustrated below:

 
Food   Microwave

How food works

Every morsel of food has a name and a weight in grams. When heated by a microwave, the food rises in internal temperature until it reaches its ideal cooking temperature. On modern microwaves, this takes one second per gram. (I made that up, but that's what we'll be using for today's SWYK check.)

Food which has been heated a number of seconds between 90% and 110% of its weight in grams is considered "cooked" and yummy. Food which has been heated less than 90% that many seconds is considered "raw," and food which has been heated more than 110% that many seconds is considered "burnt."

Btw, food can be partially heated in one microwave, then switched to another and finish cooking. It does not "reset" back to its uncooked state once it is removed from a microwave.

Example (do please read through this): I have a watermelon that weighs 100 grams. I heat it in a microwave for 60 seconds. It is considered raw. I heat it for 25 seconds more (85 in total). It is still raw. I heat it for 10 more seconds (95 in total). It is now nice and cooked. I heat it for 10 more seconds (105 in total). It is still nice and cooked. I heat it for 10 more seconds (115 in total). It is now a burnt watermelon.

How microwaves work

Our microwaves each have a door to open and insert/remove food, a time display (in seconds), and a "cook" button. When a number of seconds is entered, and the cook button is pressed, the microwave will heat whatever's inside at a rate of 1 gram per second.

Microwaves cannot hold more than one food item at a time. They also cannot be operated if there's no food inside them: the device will have nothing to heat, and will implode.


The requirements

Instance variables

Your Food and Microwave classes should probably each have instance variables. It's up to you to decide what they are.

Methods

Food

Your Food class must have the following methods. You should use the Food.java template file as a starting point, which has the beginnings of each of these:

  1. A constructor that takes a food name and a weight in grams.
  2. A .heat() method that heats the food for a certain number of seconds. This will cause the food to cook for that long a time.
  3. An .isCooked() method that returns true if the food has been heated at least 90% as many seconds as it weighs in grams. Note that food that has been nuked for hundreds of hours is still considered "cooked" even though it is also "burnt."
  4. An .isOvercooked() method that returns true if the food has been heated at least 110% as many seconds as it weighs in grams. Note that overcooked (burnt) food is also considered "cooked."
  5. A .toString() method which will convert the Food object to a String. The string should be the name of the food; this should be prepended by the word "raw" if the food is not cooked, and prepended by the word "burnt" if the food is overcooked.

Example code and output

Food bagel = new Food("bagel",12);
bagel.heat(5);
System.out.println(bagel);    <-- prints "raw bagel"
bagel.heat(6);
System.out.println(bagel);    <-- prints "bagel"
bagel.heat(4);
System.out.println(bagel);    <-- prints "burnt bagel"

Microwave

Your Microwave class must have the following methods. You should use the Microwave.java template file as a starting point, which has the beginnings of each of these:

  1. A no-argument constructor that initializes a new microwave to have zero seconds on its time display.
  2. A .enterTime() method which sets the time display to a certain number of seconds (overriding whatever its current setting is). Note that the time display only shows a total number of seconds, not minutes. (For example, 80 seconds will simply be 80 on the display, not "1:20".)
  3. A .getTime() method which returns the number of seconds currently on the time display.
  4. An .insert() method which takes a Food object as an argument, and sticks it in the microwave. If there is already food in the microwave when this is called, it should throw an Exception.
  5. A .remove() method which returns the Food object currently in the microwave, and empties the microwave. If there was no food in the microwave when this is called, it should throw an Exception.
  6. A .pressCookButton() method which begins the heating process for whatever food is inside the microwave. Heating is instantaneous in "our world," so it's not like you actually have to wait some amount of clock time. When you call this method, it will instantly cook the food for the number of seconds given. Remember the warning about imploding empty microwaves! Believe it or not, this actually happens (my cousin did it) and you should throw an exception rather than attempt to heat only air.

Example code and output

Microwave micro = new Microwave();
micro.insert(bagel);
micro.enterTime(10);
micro.pressCookButton();
Food f = micro.remove();
// This previous 5 lines of code will all execute instantaneously,
// not in 10 real-time seconds.

Compiling your code

Don't forget to compile your code (using the "compile" alias defined above) every time you write (save) a change in vim! Otherwise your changes will not be reflected in what's executed when you runtests.

Running your code

Executing the "runtests" alias will trigger the entire test suite. To get full credit for the SWYK check, you must pass all the test cases. When you do, you're done! Until then, continue to study your error messages and your code, and make the food and microwave work properly.

Running your own main()

It is absolutely permissible (and a good idea, actually) to create your own main() method in either the Food or Microwave classes, and use it to experiment with your own client code. Recall that it must look like this:

class Food {

    ...possibly other stuff...

    public static void main(String args[]) {
        ...Your client code that fiddles around with Food and Microwaves...
    }

    ...possibly other stuff...

and that to run it, you would type:

$ java Food

Turning it in

When you have completed your class and gotten all the test cases to pass, do the following:

  1. Wave me over so I can look at y'all's screen and then give y'all a high-five.
  2. Download your Food.java and Microwave.java code to your laptop (using Filezilla or any other method you choose) and then send them as an email attachment to both (1) cpsc240submissions@gmail.com and (2) the partner whose laptop is not being used for this assignment. The subject line of this email should be "SWYK check 3 turn-in".

If you can't get all the test cases before time's up, don't despair, but do perform step #2, above.