package cards;
import java.util.ArrayList;
import java.util.Scanner;
public class GamePlay {
static int counter = 0;
private static int cardNumber[] =
{1,2,3,4,5,6,7,8,9,10,11,12,13};
private static char suitName[] = { 'c', 'd', 'h', 's' };
public static void main(String[] args) throws CardException,
DeckException, HandException
{
Scanner kb = new Scanner(System.in);
System.out.println("How many Players? ");
int numHands = kb.nextInt();
int cards = 0;
if (numHands > 0) {
cards = 52 / numHands;
System.out.println("Each player gets " + cards + " cards\n");
} else {
System.out.println("OOPS you entered an invalid number try again!
");
}
Hand hand;
Card c;
ArrayList<Hand> hands = new ArrayList<Hand>();
for (int i = 0; i < numHands; i++) {
hand = new Hand(cards);
for (int j = 0; j < cards; j++) {
c = getANewCard();
hand.getCard(c);
}
hands.add(hand);
}
play(hands);
}
private static void play(ArrayList<Hand> hands) throws
CardException, HandException
{
Card hand = new Card(1, 'd');
int i = 0;
int playerNum = 0;
while (i < hands.size() * hands.get(0).handSize)
{
playerNum = i % hands.size();
hand = hands.get(playerNum).giveCard();
System.out.println("Player " + (playerNum + 1) + " plays the
"
+ hand.toString());
if(hand.getCardName().equals("Ace")){
System.out.println("Player " + (playerNum + 1 ) + " wins! ");
break;
}
i++;
} }
public static Card getANewCard() throws CardException
{
counter++;
return new Card(cardNumber[counter%13], suitName[counter%4]);
}
}
In this file of code i was wondering why there are certain things in place.
static int counter = 0;
private static int cardNumber[] =
{1,2,3,4,5,6,7,8,9,10,11,12,13};
private static char suitName[] = { 'c', 'd', 'h', 's' };
What is the use of declaring these lines of code?
Then what does this line of code do in this program?
public static Card getANewCard() throws CardException
{
counter++;
return new Card(cardNumber[counter%13], suitName[counter%4]);
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...
import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private ArrayList<String> words; private HashSet<String> foundWords = new HashSet<String>(); public FindWordInMaze(char[][] grid) { this.grid = grid; this.words = new ArrayList<>(); // add dictionary words words.add("START"); words.add("NOTE"); words.add("SAND"); words.add("STONED"); Collections.sort(words); } public void findWords() { for(int i=0; i<grid.length; i++) { for(int j=0; j<grid[i].length; j++) { findWordsFromLocation(i, j); } } for(String w: foundWords) { System.out.println(w); } } private boolean isValidIndex(int i, int j, boolean visited[][]) { return...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...
public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...
Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver { public static String solve(char[][] grid) { // TODO /* * 1. Construct a graph using grid * 2. Use BFS to find shortest path from start to finish * 3. Return the sequence of moves to get from start to finish */ // Hardcoded solution to toyTest return...
departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore { private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee; } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...
need help with code it won't compile. import java.util.ArrayList; /** * Counts the ranks of cards in a hand. * * @author (your name) * @version (a version number or a date) */ public class CountRank { // instance variables - replace the example below with your own private int rankCount[]; private Hand hand; private int count; /** * Constructor for objects of class CountRank */ public CountRank(Hand h) { // initialise instance variables hand = h; rankCount = new...
import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice { private static final int[] arr = new int[100000]; public static void main(String[] args) { for(int i=0; i<100000; i++) arr[i] = i; //TODO comment out this line LinkedList<Integer> list = new LinkedList<Integer>(); //TODO uncomment this line //List<Integer> list = new ArrayList<Integer>(); //TODO change the rest of the...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...