4a -- exercises for 10/14

You may have a partner for this lab; but everyone needs to know how to do all these things!

Introduction:

This lab has a series of very simple tasks; do them in order.

  1. Write a class, called Exercises with an int variable, x, and a String variable name.
  2. Make the default constructor in Exercises set x to 17 and name to your name.
  3. Write a class called Driver, to test your Exercises class; in it, instantiate an Exercises, and send it as a parameter to sout; what does it print?
  4. Add a method with the signature public String toString(), which returns x and name with informative labels (so you don't just see 17 Jane, but rather, I am an Exercises, x=17, name=Jane.
  5. Run the driver again; what does it print now?
  6. Add a method, named doubleIt, which doubles the value of x. To test it, send it to your Exercises twice and then sout your Exercises... if it prints 68, then it is working.
  7. Write a method named, sout, with an int parameter, which will print that parameter (with a descriptive label).
  8. Write a method named giveMeX, which will return the value of x. Test it by saying, sout("here's what giveMeX returns..." + myExercises.giveMeX());
  9. Write a method named giveMeTwiceX that returns twice the value of x. Test it.
  10. Write a method named setXTo, which sets x to its parameter. Test it.
  11. Write a method named zeroX which sets x to 0.
  12. Write another class, Coyote, which works exactly like Exercises. You will have to include a constructor with only the line super(); to get the initialization done. Change your variable (in the driver) to a Coyote, and make sure everything still works.
  13. Override giveMeX (in Coyote), so that it returns one more than x.
  14. Override doublit (in Coyote), so it triples x.