Time to show what y'all know!
Before continuing, verify each of the following:
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:
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.
For this problem, you are to write two classes, one called Food and the other called Microwave. These are illustrated below:
Food | Microwave |
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.
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.
Your Food and Microwave classes should probably each have instance variables. It's up to you to decide what they are.
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:
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"
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:
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.
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.
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.
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
When you have completed your class and gotten all the test cases to pass, do the following:
If you can't get all the test cases before time's up, don't despair, but do perform step #2, above.