Return to the lecture notes index

Lecture #32 (Wednesday, Dec 6, 2006)

Daily Excercise Three

Today we did our fourth daily excercise. For this one, all we were asked to do was write a class that models a membership card. We defined a membership card to have four properties: A membership number that does not necessarily contain only numbers, an organization, the club type, and the signature.

Note that with an open ended assignment like this, it's possible to get a few different answers, but more than anything try and keep it simple.

import java.util.*;

public class MembershipCard {
	private String org;
	private String club;
	private String signature;
	//Note it's a string because it can contain letters as well
	private String cardNumber;
	public MembershipCard (String org, String club, String cardNumber) { = org; = club;
	      //When we create a card, there is no signature on it
		this.signature = "";
		this.cardNumber = cardNumber;	
	public String getOrg(){
		return org;
	public String getClub(){
		return club;
	public String getSignature(){
		return signature;
	public String getCardNumber(){
		return cardNumber;

	//Our method that allows us to sign a card
	// If you wanted to make sure you can only sign a card once,
      // you could only set the signature if(!this.signature.equals(""))
	public void sign(String signature){
		this.signature = signature;
	//Standard equals method
	public boolean equals(Object o) {
		MembershipCard mC = (MembershipCard) o;
		if (!club.equals(
			return false;
		if (!signature.equals(mC.signature))
			return false;

		if (!org.equals(
			return false;

		if (!cardNumber.equals(mC.cardNumber))
			return false;

		return true;
	//Nicely formatted toString() method
	public String toString() {
		String list = "Organization: " + org + "\n" + "Club: " + club + "\n" + "Card Number: " + cardNumber + "\n" + "Signature: " + signature; 
		return list;