Final Exam Information Another batch of problems
1. What is a Frame? Does a Frame define
a paint() method? Does it have access to such a method?
Where does it get it from? Explain how paint() works,
since we never make an explicit reference to that function in our
code.
2. Write the code for an application that extends Frame,
draws a circle, has one button and when the button gets pressed the
circle moves one pixel (randomly chosen) to the right, left, up, or
down.
3. In problem 2 above make sure that the window closes when we press
the icon on its upper right corner. Explain how you accomplish that
effect (it's similar to noticing that the button has been pressed).
Also, explain how actionPerformed() gets called since we
never make an explicit reference to that function in our code.
4. Write a class representation for the rational numbers (fractions). Have functions to deal with multiplication and addition.
5. Write a simulation (a class) for a coke machine. A coke machine
can contain an arbitrary number of different types of soft drinks, and
when you push the button for a certain drink that number decreases by
one. There is a certain person (or message, or method invocation) that
the coke machine will understand, which refills it (call it, in your
implementation, theCokeGuy()).
6. Write a Processor class that describes objects which
upon instantiation fill an internal (instance, that is) array with a
certain number of randomly chosen integers (the size of the array is
specified as an argument to the constructor). Processor
objects should have a sort() method, that will sort the
elements in the internal array in ascending order, then prints them
out. You can use any sorting algorithm you're comfortable with.
7. Write a function which will accept a mathematical operator (e.g.,
+, -, *, /, as a
String) and two integer numbers (ints) and
returns the result of the operation on them.
8. List the four default methods of an applet and explain what each one of them does.