



|
|
CS1 Course Site
|
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )
Wednesday October 25 , 2000
|
|
The blue.cards.Card class
Constructors
new Card (< int >, < string >) -- > < card >
new Card (< string >, < string >) -- > < card >
Methods
< Card > .print ()
< Card > .println ()
< Card > .rank () -- > < int >
< Card > .suit () -- > < int >
Constants - i.e. Math.PI
Card.JACK -- > < int >
Card.QUEEN -- > < int >
Card.KING -- > < int >
Card.ACE -- > < int >
Card.CLUB -- > < int >
Card.DIAMOND -- > < int >
Card.HART -- > < int >
Card.SPADE -- > < int >
Ex
Card c = new Card (4, ``Spade'');
Card d = new Card ( ``jack'', '' club'');
Suppose
x and y are Card objects.
- Display the rank of x
IO.println (x.printRank ()); But note this will give the integer representation of the rank.
- Do a botter job of number one.
x.printRank ();
- Display the suit of x
x.printSuit ();
- Display both cards, one per line
x.println ();
y.println ();
- Display the word ``red'' if x is a red card.
boolean xHeart = (x.suit () == Card.HEART);
boolean xDiamond = (x.suit () == Card.DIAMOND);
if (xHeart | | xDiamond)
{
IO.println ( ``red'');
}
Code for part one of the assignment
public static void main (----)
{
Card c;
Card d;
int i = 1;
while (i < = 50)
{
String cRank = IO.readString ();
String cSuit = IO.readString ();
c = new Card (cRank, cSuit);
String dRank = IO.readString ();
String dSuit = IO.readString ();
d = new Card (dRank, dSuit);
c.print ();
d.print ();
IO.println ();
i = i + +; (i + 1)
}
}
java CardThing < .. /CardThing.data
The program to read several non-zero integers and display the maximum.
< PROGRAM > -- >
int maxSoFar = IO.read_int ();
int challenger = IO.read_int ();
while (challenger! = 0)
{
if (challenger > maxSoFar)
{
maxSoFar = challenger;
}
challenger = IO.read_int ();
}
int max = maxSoFar;
IO.println ( ``Max value = ``+ max);
|
|