|
|
Homework #5Due: Friday, March 5. The written part of this assignment is due by 5:00 p.m. Hand it in during lecture on Friday or in the CSE main office in the Allen Center by 5:00 p.m. The programming part is due online by 9:00 p.m. No late asssignments will be accepted.This homework is meant to give you a bit of practice thinking about inheritance while you get started with the final project. We also hope to clear up some of the lingering confusion about return statements vs. printed output. 1. (written exercise only) (a) Suppose we are writing the following class to model a playing card. /** Model of a playing card*/ public class Card { private String suit; // card suit; one of "spade", "heart", // "club", or "diamond" ... Write a (b) Now suppose we're writing a different class, say 2. (written exercise only) Suppose you are designing classes to represent vehicles for a traffic simulation system. In particular, we want classes to represent cars, trucks, and busses. For this problem we will explore the design of these classes only. There is no Java coding involved. (a) For each of the individual classes (b) Now take your answer to part (a) and expand on your design using inheritance
to factor out common properties and responsibilities from the different
classes and put them in a parent class. You should design a class
3. (to be implemented on the computer) For this problem, design and implement a set of small classes to model some characters from the movie The Wizard of Oz, including Dorothy, the Scarecrow, and the Cowardly Lion. All of these characters can report who they are, sing, skip down the Yellow Brick Road, tell you how many times they have skipped, and they all have a favorite saying. When asked who they are, they reply with their character's name. When asked to sing, all of them reply with "Ding! Dong! The witch is dead!". When asked to skip a certain number of times, they all reply with "skip skip skip skip", where the word "skip" appears as many times as they were asked to skip. They can all report the total number of times they have skipped. Finally, they all have a favorite saying, such as "There's no place like home" for Dorothy, "If I only had a brain" for the Scarecrow, and "If I only had courage" for the Cowardly Lion. More specifically, each of the Java objects that model a character should implement the following methods /** Return the name of this character */ public String getName() /** Return words from the song that this character sings */ public String sing() /** Return a string with "skip" appearing n times * @param n the number of times to skip */ public String skip(int n) /** Return the total number of skips this character has done * @return sum of all of the times this character has skipped */ public int getSkips() /** Return this character's favorite saying */ public String getSaying() Notice that none of these methods actually print anything on (a) Implement a base class (b) Create a class What to Turn inTurn in written answers to the first two questions either in lecture or in the CSE main office on the due date given at the top of the page by 5 pm. Turn in your Java code for the last question using this online turnin form by 9 pm that day.
|