



|
|
CS1 Course Site
|
Programming Challenge Archive
Incremental Programming
CardThing -- v4
|
|
|
JavaApplication --
CardThing
// General Information
// ---------------------------------------------------
// File: CardThing.java
// Type: java application file
// Date: Thu Nov 9, 2000
// Name: Kara Becker
// Line: Display the word RED after the second card in ea+
ch pair of the 50 card pairs if both cards in the pair are+
red and display the word BLACK if both cards in the pair +
are black.
// Application Description
// ---------------------------------------------------
/*
Display the word RED after the second card in each pair +
of the 50 card pairs if both cards in the pair are red and+
display the word BLACK if both cards in the pair are blac+
k.
*/
// 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);
checkDiff(c,d);
checkRed(c,d);
checkBlack(c,d);
IO.println();
i = i + 1;
}
}
static private void checkRanks(Card c,Card d)
{
if (c.rank() == d.rank())
{
IO.print(" R");
}
}
static private void checkSuits(Card c,Card d)
{
if (c.suit() == d.suit())
{
IO.print(" S");
}
}
static private void checkDiff(Card c,Card d)
{
if (c.suit() != d.suit())
{
if (c.rank() != d.rank())
{
IO.print(" *");
}
}
}
static private void checkColors(Card c,Card d)
{
checkRed(c,d);
checkBlack(c,d);
}
static private void checkRed(Card c,Card d)
{
if ((c.suit() == Card.DIAMOND || c.suit() == Card.HEART) +
&& (d.suit() == Card.DIAMOND || d.suit() == Card.HEART))
{
IO.println(" RED");
}
}
static private void checkBlack(Card c,Card d)
{
if ((c.suit() == Card.SPADE || d.suit() == Card.CLUB) && +
(c.suit() == Card.SPADE || c.suit() == Card.CLUB))
{
IO.println(" BLACK");
}
}
}
// Demo
// ---------------------------------------------------
/*
*/
|
|
|