



|
|
CS1 Course Site
|
Programming Challenge Archive
Incremental Programming
CardThing -- v2
|
|
|
JavaApplication --
CardThing
// General Information
// ---------------------------------------------------
// File: CardThing.java
// Type: java application file
// Date: Thu Nov 9, 2000
// Name: Kara Becker
// Line: Display an R after the second card in each pair +
of the 50 card pairs if they have the same rank, and displ+
ay an S if they have the same suit.
// Application Description
// ---------------------------------------------------
/*
Display an R after the second card in each pair of the 5+
0 card pairs if they have the same rank, and display an S +
if they have the same suit.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.cards.*;
// Application Class
// ---------------------------------------------------
class CardThing
{
static public void main (String args[])
{
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();
checkRanks(c,d);
checkSuits(c,d);
IO.println();
i = i + 1;
}
}
static private void checkRanks(Card c,Card d)
{
if (c.rank() == d.rank())
{
IO.println(" R");
}
}
static private void checkSuits(Card c,Card d)
{
if (c.suit() == d.suit())
{
IO.println(" S");
}
}
}
// Demo
// ---------------------------------------------------
/*
$ java CardThing
(2,S)(K,S) S
(K,D)(K,H) R
(3,C)(4,D)
(Q,H)(Q,S) R
(7,D)(J,D) S
(2,H)(2,D) R
(7,H)(2,S)
(9,S)(10,C)
(J,C)(J,S) R
(Q,S)(6,H)
(6,H)(7,D)
(6,C)(6,S) R
(A,D)(2,C)
(K,C)(J,H)
(J,S)(10,S) S
(J,S)(10,C)
(9,D)(9,H) R
(5,S)(J,C)
(5,H)(6,H) S
(9,D)(4,C)
(8,C)(8,S) R
(9,D)(10,S)
(Q,H)(2,H) S
(5,C)(6,C) S
(9,D)(A,H)
(6,S)(K,H)
(K,D)(10,H)
(3,C)(4,S)
(5,H)(Q,D)
(J,C)(J,D) R
(2,H)(2,D) R
(7,D)(3,S)
(9,S)(9,C) R
(J,C)(J,S) R
(7,S)(6,H)
(6,C)(7,D)
(7,S)(6,S) S
(A,D)(A,C) R
(K,D)(J,H)
(J,C)(10,S)
(J,S)(J,C) R
(9,D)(5,D) S
(5,C)(J,C) S
(5,H)(6,H) S
(9,D)(4,H)
(8,C)(8,D) R
(9,D)(6,S)
(Q,H)(2,C)
(5,S)(6,C)
(Q,H)(A,H) S
$
*/
|
|
|