Lab 5
Interface vs. Abstract Class
Due Wednesday, March 29, 11:55pm.
Submission through SVN.
Please submit your work in SVN directory
https://www.cs.usfca.edu/svn/< your username >/cs112/lab5
e.g. https://www.cs.usfca.edu/svn/ejung/cs112/lab5
Goal
This lab is designed for you to practice using interface and inheritance, and to deepen your understanding of pros and cons of them. You will design and implement three different kinds of slot machines, once using interface SlotMachine and once using abstract class SlotMachine, in total 6 new classes. In your README, explain which is a better design, using either interface or inheritance(abstract class) in this lab.
Specifications
- (50%) In slotinterface package:
- (40%) Each class implements the interface correctly, following the comments in SlotMachine interface.
- Hint: See SlotMachine class in slotinheritance package for addTokens and endTheGame methods.
- (10%) Correct implementation of constructor in three classes.
- (5%) Correct implementation of addTokens method in three classes.
- (20%) Correct implementation of pull method in three classes.
- (5%) Correct implementation of endTheGame method in three classes.
- (10%) Modify Driver.java to use your classes.
- (40%) In slotinheritance package:
- (30%) Each class extends the abstract class correctly, following the comments in SlotMachine class.
- (10%) Correct implementation of constructor in three classes.
- (20%) Correct implementation of pull method in three classes.
- (10%) Modify Driver.java to use your classes.
- Hint: You may use the same Driver.java in both packages, if your classes' names are the same.
- (10%) Write a README document that explains which is a better design, using either interface or abstract class in this lab. Discuss pros and cons of each approach in terms of how much coding you have to do, how much redundancy there is, and how easy it is to make different slot machines. You are welcome to use other criteria you can think of.
- Extra-credit (up to 10%): Design a new lab 5. If your README says interface is better for this lab, then design a lab that shows a scenario where abstract class is a better choice. If your README says abstract class is better for this lab, then design a lab that shows a scenario where interface is a better choice. You don't need to provide Driver class, but need to provide interface and abstract class.
Java hint
(int) Math.random()*n
This code returns a random int value between 0..(n-1), inclusive on both ends.
What to submit
README, and all class files in slotinheritance package and slotinterface package.