Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Wednesday October 25 , 2000
 
The topic of Programming Assignment # 04 dominated tonight's lecture.   CG introduced us to the Card Class,  which is an important part of the next programming assignment. 


The Card Class  

blue.cards.Card 

Constructors 

new Card (< int >,  < string >) -- >    < Card >
new Card (< string >,  < string >) -- >    < Card > 

Methods 

< Card > .print ()
< Card > .println ()
< Card > .rank () -- >    < int >
< Card > .suit () -- >    < int > 

Constants
Card.JACK -- >    < int >
Card.QUEEN -- >    < int >
Card.KING -- >    < int >
Card.ACE -- >    < int >
Card.CLUB -- >    < int >
Card.DIAMOND -- >    < int >
Card.HEART -- >    < int >
Card.SPADE -- >    < int > 

Suppose....
x and y are card objects
1..   display the rank of x.
IO.println (x.rank ());
note:   this will give an integer representation 

2..   Do a better job of # 1..
x.printRank (); 

3..   Display the suit of x.
x.printSuit (); 

4..   Display both cards,  one per line
x.println ();
y.println (); 

5..   Display the word ``red'' if x is a red card.
boolean xHeart = (x.suit () == Card.HEART);
boolean xDiamond = (y.suit () == Card.DIAMOND);
if (xHeart    | |    xDiamond)
{
IO.println (``red'');

 

After giving us the background information for the Card Class,  CG then proceeded to help us develop the code for the first version of the programming assignment. 

CG finished this class session with this ' Heavyweight Champion of the World' program:

Problem:   The program to read several nonzero numbers and display the maximum. 

class ~ ~ ~ ~ ~

int maxSoFar = IO.read_int ();
int challenger = IO.read_int ();
while (challenger    !   =    0)
{
if (challenger > maxSoFar)
{
maxSoFar = challenger;
}
challenger = read_int ();
}
int max = maxSoFar;
IO.println (``Max value =  ``+ max);