



|
|
P Dunn's Super CS1 Site
|
Programming Challenge Archive
Incremental Programming
version 3 of Card Thing
|
|
Java Application --
CardThingApp
// General Information
// ---------------------------------------------------
// File: CardThingApp.java
// Type: java application file
// Date: Wed Nov 1, 2000
// Name: Patrick Dunn
// Line: V3 - reads 50 card pair representations
// from the input file and displays them
// along with displaying if they are ranks
// or suits are the same if not display a *
// Application Description
// ---------------------------------------------------
/*
V3 of this program will place an * after the second
card if the ranks nor the suits are the same
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.cards.*;
// Application Class
// ---------------------------------------------------
class CardThingApp
{
static public void main (String args[])
{
Card c; // card 1
Card d; // card 2
int counter = 1; // init counter
while(counter <= 50)
{
// read in the card rank and suit
String cRank = IO.readString();
String cSuit = IO.readString();
// create a new card object
c = new Card(cRank,cSuit);
// read in the card rank and suit
String dRank = IO.readString();
String dSuit = IO.readString();
// create a new card object
d = new Card(dRank,dSuit);
// display the objects
c.print();
d.print();
// call the commands to check the suits and
// ranks and display the R or S if they are
// the same
checkRanks(c,d);
checkSuits(c,d);
// call the command to check the suits and
// ranks and display an * if neither are
// the same
checkDiff(c,d);
IO.println();
// increment the counter
counter++;
}
}
static private void checkRanks(Card one,Card two)
{
// check to see if the the ranks are the same
if(one.rank() == two.rank())
{
IO.print(" R");
}
}
static private void checkSuits(Card one,Card two)
{
// check to see if the suits are the same
if(one.suit() == two.suit())
{
IO.print(" S");
}
}
static private void checkDiff(Card one,Card two)
{
// check to see if the ranks nor suits are the same
// if so, display an *
if(one.rank() != two.rank())
{
if(one.suit() != two.suit())
{
IO.print(" *");
}
}
}
}
// Demo
// ---------------------------------------------------
/*
[patdunn@k6 v3]$ java CardThingApp < ../CardThing.data
(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
[patdunn@k6 v3]$
*/
|
|
|