Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Chandigarh university

EXPERIMENT NO 7

HARDIK LATH

UID :- 18BCS4030

ALGORITHM

1. First, fill the array with the values in order.

2. Go through the array and exchange each element

with the randomly chosen element in the range

from itself to the end.

3 It is possible that an element will be swap

with itself, but there is no problem with that.


# SOURCE CODE
import java.util.*;
import java.util.Scanner;

import java.io.*;

public class Deck {

public static void main(String args[])

int players;

int spadecount=0;

int heartcount=0;

int clubcount=0;

int diamondcount=0;

Scanner in =new Scanner(System.in);

ArrayList<String> Spades = new ArrayList<String>();

ArrayList<String> Hearts = new ArrayList<String>();

ArrayList<String> Deck = new ArrayList<String>();

ArrayList<String> Diamonds = new ArrayList<String>();

ArrayList<String> clubs = new ArrayList<String>();

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);

System.out.println("enter the no of players :");

players=in.nextInt();

int length=Deck.size();

switch (players) {

case 2:{

System.out.println("players one cards :");

for (int i=0;i<26;i++) {

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 one has "+spadecount+" spades


"+clubcount+ " clubs" +diamondcount+" diamonds "+heartcount+" hearts");

System.out.println("\n");

System.out.println("player two's cards :");

spadecount=0;

heartcount=0;

clubcount=0;

diamondcount=0;

for (int i=26;i<52;i++) {

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("player one cards :");

for (int i=0;i<13;i++) {

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("player two's cards :");

for (int i=13;i<26;i++) {

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");

System.out.println("\n");

System.out.println("player three's cards :");

spadecount=0;

heartcount=0;

clubcount=0;
diamondcount=0;

for (int i=26;i<39;i++) {

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 three has "+spadecount+" spades


"+clubcount+ " clubs" +diamondcount+" diamonds "+heartcount+" hearts");

System.out.println("\n");

System.out.println("player four's cards:");

spadecount=0;

heartcount=0;

clubcount=0;

diamondcount=0;

for (int i=39;i<52;i++) {


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 four has "+spadecount+" spades


"+clubcount+ " clubs" +diamondcount+" diamonds "+heartcount+" hearts");

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’

You might also like