Professional Documents
Culture Documents
Chandigarh University Experiment No 7: Algorithm
Chandigarh University Experiment No 7: Algorithm
EXPERIMENT NO 7
HARDIK LATH
UID :- 18BCS4030
ALGORITHM
import java.io.*;
int players;
int spadecount=0;
int heartcount=0;
int clubcount=0;
int diamondcount=0;
Spades.add("spades of A");
Spades.add("spades of 2");
Spades.add("spades of 3");
Spades.add("spades of 4");
Spades.add("spades of 5");
Spades.add("spades of 6");
Spades.add("spades of 7");
Spades.add("spades of 8");
Spades.add("spades of 9");
Spades.add("spades of 10");
Spades.add("spades of J");
Spades.add("spades of Q");
Spades.add("spades of K");
Hearts.add("hearts of A");
Hearts.add("hearts of 2");
Hearts.add("hearts of 3");
Hearts.add("hearts of 4");
Hearts.add("hearts of 5");
Hearts.add("hearts of 6");
Hearts.add("hearts of 7");
Hearts.add("hearts of 8");
Hearts.add("hearts of 9");
Hearts.add("hearts of 10");
Hearts.add("hearts of J");
Hearts.add("hearts of Q");
Hearts.add("hearts of K");
clubs.add("clubs of A");
clubs.add("clubs of 2");
clubs.add("clubs of 3");
clubs.add("clubs of 4");
clubs.add("clubs of 5");
clubs.add("clubs of 6");
clubs.add("clubs of 7");
clubs.add("clubs of 8");
clubs.add("clubs of 9");
clubs.add("clubs of 10");
clubs.add("clubs of J");
clubs.add("clubs of Q");
clubs.add("clubs of K");
Diamonds.add("diamonds of A");
Diamonds.add("diamonds of 2");
Diamonds.add("diamonds of 3");
Diamonds.add("diamonds of 4");
Diamonds.add("diamonds of 5");
Diamonds.add("diamonds of 6");
Diamonds.add("diamonds of 7");
Diamonds.add("diamonds of 8");
Diamonds.add("diamonds of 9");
Diamonds.add("diamonds of 10");
Diamonds.add("diamonds of J");
Diamonds.add("diamonds of Q");
Diamonds.add("diamonds of K");
Collections.shuffle(Spades);
Collections.shuffle(clubs);
Collections.shuffle(Hearts);
Collections.shuffle(Diamonds);
Deck.addAll(Spades);
Deck.addAll(clubs);
Deck.addAll(Hearts);
Deck.addAll(Diamonds);
Collections.shuffle(Deck);
players=in.nextInt();
int length=Deck.size();
switch (players) {
case 2:{
System.out.println(Deck.get(i));
if (Spades.contains(Deck.get(i))){
spadecount=spadecount+1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i))){
heartcount=heartcount+1;
System.out.println("\n");
spadecount=0;
heartcount=0;
clubcount=0;
diamondcount=0;
System.out.println(Deck.get(i));
if (Spades.contains(Deck.get(i))){
spadecount=spadecount+1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i)))
{ heartcount=heartcount+
1;
}
}
System.out.println("player two has "+spadecount+" spades
"+clubcount+ " clubs" +diamondcount+" diamonds "+heartcount+" hearts");
break;
case 4:{
System.out.println(Deck.get(i));
if (Spades.contains(Deck.get(i))){
spadecount=spadecount+1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i)))
{ heartcount=heartcount+
1;
spadecount=0;
heartcount=0;
clubcount=0;
diamondcount=0;
System.out.println("player one has "+spadecount+" spades
"+clubcount+ " clubs" +diamondcount+" diamonds "+heartcount+" hearts");
System.out.println("\n");
System.out.println(Deck.get(i));
if (Spades.contains(Deck.get(i))){
spadecount=spadecount+1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i)))
{ heartcount=heartcount+
1;
System.out.println("\n");
spadecount=0;
heartcount=0;
clubcount=0;
diamondcount=0;
System.out.println(Deck.get(i));
if (Spades.contains(Deck.get(i))){
spadecount=spadecount+1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i)))
{ heartcount=heartcount+
1;
System.out.println("\n");
spadecount=0;
heartcount=0;
clubcount=0;
diamondcount=0;
{ spadecount=spadecount+
1;
if (clubs.contains(Deck.get(i)))
{ clubcount=clubcount+
1;
if (Diamonds.contains(Deck.get(i)))
{ diamondcount=diamondcount+
1;
if (Hearts.contains(Deck.get(i)))
{ heartcount=heartcount+
1;
break;
}
# OUTPUT
FLOW CHART
6et value of
Pr/nc/pfe:
F’ilfer out black
Pifi›aipie
Add only large
numbers to
’card sum’ unfil
very close to
target
Princ/pie:
Hold off for ma/
card la reach
'larger value’