Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can not figure out what is wrong with my Java code private char suit; private int value; //+PlayingCard (s;char, v;int) public playingCard(char s, int v){

Can not figure out what is wrong with my Java code

private char suit; private int value; //+PlayingCard (s;char, v;int) public playingCard(char s, int v){ suit = s; value = v; } //get suit public char getSuit() { return suit; } //get value public int getValue() { return value; } //setSuit// public void setSuit(char s) { suit = s; } //set Value public void setValue(int v){ value = v; } //toString()String)//

public String toString() {

char suit_type = getSuit();

int val = this.getValue();

String str = "";

if (val == 11)

str += "( " + "J, " + suit_type + " )";

else if (val == 12)

str = "( " + "Q, " + suit_type + " )";

else if (val == 13)

str = "( " + "K, " + suit_type + " )";

else if (val == 14)

str = "( " + "A, " + suit_type + " )";

else

str = Integer.toString(val);

return "(this.suit,str)"; } //isMatch (p:playingCard): boolean// public boolean isMatch(playingCard p) {

if (this.getSuit() == p.getSuit() || this.getValue() == p.getValue())

return true;

else

return false; } //Driver Class // String (chrSuit) and assign, "SHDC" //Generate two random numbers between 0 and 51 (randnum1, randnum2

// INPUT: Declare and populate Arraylist with 52 card objects // For int i increments from 0 to 3 // For int x, increments from 2 to 14 // declare a PlayingCard object and initialize its properties through args constructor //PlayingCard singleCard = new PlayingCard(chrSuit.charAt(i), x) //ArrayList.add(singleCard) //add card to ArrayList //End inner For-loop //End outer For-loop public void PlayingCard (ArrayList){ public void main(String[] args) { String [] chrSuit = {"S,H,D,C"}; String [] values = {"A", "2", "3","4", "5", "6", "7", "8", "9", "10","11", "12", "13"}; Random num1 = new Random(); Random num2 = new Random();

for (int i= 0; i< 3; i++) { for (int x =2; x >14; x++){ PlayingCard singleCard = new PlayingCard(chrSuit.charAt(i),x); ArrayList.add(singleCard); } } PlayingCard value = ArrayList.get(num1); PlayingCard value1 = ArrayList.get(num2); boolean binCardsMatch = valueisMatch(value1); if (binCardsMatch) { output:value.toString() = " and" + value1.toString() + "match"; }else output:value.toString() = " and" + value1.toString() + "don't match"; } }

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

There are several issues in your Java code Lets address them step by step 1 Constructor Method Your ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus Early Transcendentals

Authors: James Stewart

7th edition

538497904, 978-0538497909

More Books

Students also viewed these Programming questions

Question

please dont use chat gpt 2 5 4 . Question in Chemical Engineering

Answered: 1 week ago

Question

What are the current computer software platforms and trends?

Answered: 1 week ago