



|
|
Byron's CSC212 Web Site
|
Class Notes
Wednesday October 25 , 2000
|
|
|
Notes on Incremantal Programming Challenge (# 4).
Class Notes --
Wednesday October 25 , 2000
CSC212 - October 25, 2000
=========================
CardThing.data
_ _
| Three Club |_
| Queen Heart _|
50 _| _
Pairs | Four Diamond |_
|_Four Heart _|
Read the 50 Cards
Create new directory
/program/cards
___________
| Programs |
|___________|
|
____|_______________________________
| Cards |
|____________________________________|
| | | | | | |
_____________|__ _|_ _|_ _|_ _|_ _|_ _|_
| CardThing.data | | V1|| V2|| V3|| V4|| V5|| V6|
|________________| |___||___||___||___||___||___|
| | |
| | |
_______________|__ | |
| CardThingApp.java | | |
|___________________| | |
| |
__________________|_ ___________|________
| CardThingApp.java | ... | CardThingApp.java | +
|____________________| |____________________| +
ctrl-x, ctrl-w (save as)
V1: Read 50 Card Pairs
The blue.card.Card class
Constructors
------------
new Card (<int>,<String>) -> <Card>
new Card (<String>,<String>) -> <Card>
Methods
-------
<Card>.print()
<Card>.println()
<Card>.rank() -> <int> 1 to 13
<Card>.suit() -> <int>
Constants
---------
Card.JACK --> <int> 11
Card.QUEEN --> <int> 12
Card.KING --> <int> 13
Card.ACE --> <int> 1
Card.CLUB --> <int>
Card.DIAMOND --> <int>
Card.HEART --> <int>
Card.SPADE --> <int>
EX: Card c = new Card(4."spade");
Card d = new Card("jack","club");
Tasks: Suppose
x & y are Card objects
1) Display the rank of x
IO.println (x.rank());
But note, this will give the integer representation
of the rank.
2) Do a better job of #1
x.printRank();
3) Display the suit of x.
x.printSuit();
4) Display both Cards, one per line
x.println();
y.println();
5) Display the word "red" if x is a red card.
boolean xHeart = (x.suit() == Card.Heart);
boolean xDiamond = (x.suit() == Card.DIAMOND);
if (x.heart || x.Diamond) // "or" statement
{
IO.println("red");
}
Code for Part 1 of the programming assignment:
// main method
// c & d are modeling cards
public static 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();
IO.println();
i=i+1
}
} // End of Main Method
javac CardThingApp.java
java CardThingApp <../CardThing.data
(2,club) (6,spade)
(queen,diamond) (8,spade)
...
50 pairs
V2. Write copy of V1 into V2
output: (3,club)(3,spade) [][][][][] R
(3,club)(6,spade)
(3,club)(6,club ) [][][][][] S
checkRanks = R
checkSuit = S
// void = command style
static private void checkRanks(
Small changes in main method
_
checkRank |
|- "Calls"
checkSuit _|
Place after: c.print();
d.print();
checkRanks
checkSuit
V3: Write copy of V2 into V3
Add asterich in either R of S
Check Difference
No Boolean Operators
Nested If
V4: Similar to V3
Place word "Red" or "Black"
V5: Statistics
V6: Delete extra instructions
=========================================================
12345678911234567892123456789312345678941234567895123456
|
|
|