



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 4
Version 2 of Incremental Programming
|
|
|
This programming assignment utilized the programming methodology of
incremental programming
. Each version, from 1 to 6, builds the program a little closer to the desired product.
JavaApplication - Programming Assignment # 4 --
Incremental Programming - v2
// General Information
// ---------------------------------------------------
// File: CardThing.java
// Type: java application file
// Date: Wed Nov 8, 2000
// Name: Jeffrey R. Norkoli
// Line: Programming Assignment #04
// Application Description
// ---------------------------------------------------
/*
Read 50 pairs of cards. Display each card's rank and
suit. Place the letter R five spaces after the second
card if the ranks of the two cards are the same and the+
letter S five spaces after the second card on the line
if the suits of the two cards are the same. This is
Version 2 of 6.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.cards.Card;
// 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)
{
// Check for identical ranks and print R if true.
if (c.rank() == d.rank())
{
IO.print(" R");
}
}
static private void checkSuits(Card c, Card d)
{
// Check for identical suits and print S if true.
if (c.suit() == d.suit())
{
IO.print(" S");
}
}
}
// Demo
// ---------------------------------------------------
/*
$ javac CardThing.java
$ java CardThing <../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
$
*/
|
|
|