Quiz 2 Worksheet for CMSC 132: UML Class Diagrams and Code Implementation, Quizzes of Computer Science

Information about quiz 2 for the cmsc 132 course, including the quiz material, instructions, and exercises. Students are required to create uml class diagrams and write code implementation based on the provided classes. The quiz covers association relationships and the use of arraylist, arraylistlist, and enums. No solutions will be provided, but students can discuss their answers with tas and the instructor.

Typology: Quizzes

Pre 2010

Uploaded on 07/30/2009

koofers-user-boh-1
koofers-user-boh-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 132 Quiz 2 Worksheet
The second quiz of the course will be on Friday, Jun 16 . The following list provides more
information about the quiz:
The quiz material is UML class diagrams (UML material covered in Wednesday’s
lecture) and code implementation dealing with the classes provided at the end.
Answers must be neat and legible; we recommend that you use pencil and eraser.
The following exercises cover the material to be included in this quiz. Solutions to these
exercises will not be provided, but you are welcome to discuss your solutions with TAs and the
instructor.
UML Design
1. Write a UML class diagram for the class(es) representing a telephone company
system. Consider only association relationships (no generalization or dependencies).
Possible classes you can have are: TelephoneAccount, Customer, TelephoneCall, etc.
Feel free to add any fields or methods you understand are necessary.
2. Draw a class diagram for the Roster class. You do not need to draw a diagram for the
Student class and you do not need to implement any method.
public class Roster {
private ArrayList<Student> students;
private static int numberOfRosters = 0;
public Roster(int maxSize) {
throw new UnsupportedOperationException("Not Implemented");
}
public boolean addStudent(Student s) {
throw new UnsupportedOperationException("Not Implemented");
}
public static double[] getStatistics() {
throw new UnsupportedOperationException("Not Implemented");
}
public void printInfo() {
throw new UnsupportedOperationException("Not Implemented");
}
private void computeGrades() {
throw new UnsupportedOperationException("Not Implemented");
}
}
3. Answer the following question(s) based on the Card, CardSuit and CardValue classes
provided below.
a. Implement a class called Deck that represents a deck of 52 cards. Use an
ArrayList to represent the deck. For this class define a constructor that
initializes the deck of cards with the usual 52 cards present in a deck. The
order in which the cards appear in the ArrayList is not relevant (any order will
suffice). Notice you are not asked to randomize the cards’ order.
b. Define a public method named getCards that returns an ArrayList with the
cards in the deck.
pf3

Partial preview of the text

Download Quiz 2 Worksheet for CMSC 132: UML Class Diagrams and Code Implementation and more Quizzes Computer Science in PDF only on Docsity!

CMSC 132 Quiz 2 Worksheet

The second quiz of the course will be on Friday, Jun 16. The following list provides more information about the quiz:

  • The quiz material is UML class diagrams (UML material covered in Wednesday’s lecture) and code implementation dealing with the classes provided at the end.
  • Answers must be neat and legible; we recommend that you use pencil and eraser.

The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and the instructor.

UML Design

  1. Write a UML class diagram for the class(es) representing a telephone company system. Consider only association relationships (no generalization or dependencies). Possible classes you can have are: TelephoneAccount, Customer, TelephoneCall, etc. Feel free to add any fields or methods you understand are necessary.
  2. Draw a class diagram for the Roster class. You do not need to draw a diagram for the Student class and you do not need to implement any method.

public class Roster { private ArrayList students; private static int numberOfRosters = 0;

public Roster(int maxSize) { throw new UnsupportedOperationException("Not Implemented"); }

public boolean addStudent(Student s) { throw new UnsupportedOperationException("Not Implemented"); }

public static double[] getStatistics() { throw new UnsupportedOperationException("Not Implemented"); }

public void printInfo() { throw new UnsupportedOperationException("Not Implemented"); }

private void computeGrades() { throw new UnsupportedOperationException("Not Implemented"); } }

  1. Answer the following question(s) based on the Card, CardSuit and CardValue classes provided below.

a. Implement a class called Deck that represents a deck of 52 cards. Use an ArrayList to represent the deck. For this class define a constructor that initializes the deck of cards with the usual 52 cards present in a deck. The order in which the cards appear in the ArrayList is not relevant (any order will suffice). Notice you are not asked to randomize the cards’ order. b. Define a public method named getCards that returns an ArrayList with the cards in the deck.

c. Add a public method named shuffle that will “shuffle” the cards in the deck using a Random object provided as a parameter.

public enum CardValue { Ace("1"), Two("2"), Three("3"), Four("4"), Five("5"), Six("6"), Seven("7"), Eight("8"), Nine("9"), Ten("10"), Jack("J"), Queen("Q"), King("K");

CardValue(String valueIn) { value = valueIn; } public String getValue() { return value; } public int getIntValue() { switch(this) { case Jack: return 10; case Queen: return 10; case King: return 10; default: return Integer.parseInt(value); } } private String value; }

public enum CardSuit { SPADES("s"), DIAMONDS("d"), HEARTS("h"), CLUBS("c");

CardSuit(String value) { this.value = value; }

public String getValue() { return value; }

private String value; }

public class Card { private CardValue value; private CardSuit suit;

public Card(CardValue value, CardSuit suit) { this.value = value; this.suit = suit; }

public CardValue getValue() { return value; }

public CardSuit getSuit() { return suit; }

public String toString() { String result = ""; result += value + " of " + suit + " ";