Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My Ship Sails is a great kids card game. Read this to understand the rule to pla

ID: 3683079 • Letter: M

Question

My Ship Sails is a great kids card game. Read this to understand the rule to play. The mission of the game is to collect 7 cards of the same suit" you choose. You can sail out your ship if you have 7 cards of the same suit. The card numbers are unrelated in this game You need to pass one unnecessary card to your neighboring player, like a clockwise turn agreed by all players. So, others do in the same way at the same time In this assignment, you are going to play with other 4 family members and you are to pass out your unnecessary card to player 1, and then player 1 passes one card to player 2, and so on. That means that you are player 0 and you will be passed the 7th card from player 4 You can see all of your 7 card set. You are given a choice to pick one card among 7 to pass out player 1. The players 1 through 4 will do the same thing with some intellectual ability in that each of them will choose the most unlikely card i.e., the minimum number of occurrences of suit) to pass to the next player. My son played with my implementation for one hour to finally give up... Can you win? The implementation needs to show which card is passed among the players (as a hint). Also typing ? will show all the players' cards (as a cheating). The game ends if any of 5 players won by collecting the seven cards of the same suits. Your implementation must show the hands of other players in the game end. Implementing this game is not hard if this is done properly in our learned object-oriented way: note that a card is a structure of number and suit, a player has a vector of card, and the game has a vector of cards as well as a vector of players. See the next example game session. For instance, SJ means "Jack of Spades." My implementation having a full set of comments is less than 150 lines. Good luck (a) H3 (b) SU (c) H9 (d) C6 (e) D3 (f) HAg) He Which one to replace? b Hint: player 3 passed H4 to player 4 (a) H3 (b) H(C) H9(d) C6 (e D3 (f) HAg) S7 Which one to replace? s Wrong input! Which one to replace? d Hint: player 0 passed C6 to player 1 Hint: player 1 passed C6 to player 2 Hin player 2 passea co t player 3 Hint: player 3 passed 510 to player 4 Hint: player 4 passed SK to player 0 (a) H3 b) H8 (c) H(d) 57 (e D3 (f) HAg) SK Which one to replace? d

Explanation / Answer

// Didn't get the time to write the commands Hope you understand the code.

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gamec;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
*
* @author Shivakumar
*/
public class Gamec {
  
static Gamec b=new Gamec();

static char[] ch={'a','b','c','d','e','f','g'};
static String[] p1={"SJ","S5","SJ","CQ","D7","H10","SA"};
static String[] p2={"S4","D8","D4","S2","D9","S3","SJ"};
static String[] p3={"C2","D3","SJ","D4","SJ","D5","S6"};
static String[] p4={"H4","S4","D5","D4","S6","C6","C2"};
static String[] p0={"C4","C3","C5","C6","SJ","D3","D6"};
static String game=null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
  
Scanner sc=new Scanner(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  
while(!"over".equals(game))
{
System.out.println("");
for(int i=0;i<p0.length;i++)
{
System.out.print("("+ch[i]+")"+p0[i]+" ");
}
System.out.println(" Which one to replace?");
char choice=sc.next().charAt(0);
if(choice=='?')
{
System.out.print(" Player 1:");
for(int i=0;i<p1.length;i++)
{
System.out.print(p1[i]+" ");
}
System.out.print(" Player 2:");
for(int i=0;i<p1.length;i++)
{
System.out.print(p2[i]+" ");
}
System.out.print(" Player 3:");
for(int i=0;i<p1.length;i++)
{
System.out.print(p3[i]+" ");
}
System.out.print(" Player 4:");
for(int i=0;i<p1.length;i++)
{
System.out.print(p4[i]+" ");
}
  
}
for(int i=0;i<p0.length;i++)
{
if(choice==ch[i])
{
p0[i]=b.player1(p0[i]);
String s=p1.toString();
String temp=null;
for(int j=0;j<7;j++)
{
temp=temp+Character.toString(p0[j].charAt(0));
}
if(temp.equals("CCCCCCC")|| temp.equals("DDDDDDD") || temp.equals("SSSSSSS") || temp.equals("HHHHHHH"))
{
game="over";
System.out.println("I won the game:");
  
}
  
  
}
  
}
}
}
public String player1(String rep)
{
String s=p1.toString();
String temp=null;
for(int i=0;i<7;i++)
{
temp=temp+Character.toString(p1[i].charAt(0));
}
if(temp.equals("CCCCCCC")|| temp.equals("DDDDDDD") || temp.equals("SSSSSSS") || temp.equals("HHHHHHH"))
{
game="over";
System.out.println("Player 1 won the game:");
return "";
}
int count1=temp.split("c").length-1;
int count2=temp.split("S").length-1;
int count3=temp.split("D").length-1;
int count4=temp.split("H").length-1;
  
if(count1>count2 && count1>count3)
{
System.out.println("player1 has passed"+p1[count4]);
p1[count4]=b.player2(p1[count4]);
return p1[count4];
}
else{
System.out.println("player1 has passed"+p2[count1]);
p1[count1]=b.player2(p1[count1]);
return p1[count1];
}
  

}

public String player2(String rep)
{
String s=p2.toString();
String temp=null;
for(int i=0;i<7;i++)
{
temp=temp+Character.toString(p2[i].charAt(0));
}
if(temp.equals("CCCCCCC")|| temp.equals("DDDDDDD") || temp.equals("SSSSSSS") || temp.equals("HHHHHHH"))
{
game="over";
System.out.println("player 2 won the game");
return "";
}
int count1=temp.split("c").length-1;
int count2=temp.split("S").length-1;
int count3=temp.split("D").length-1;
int count4=temp.split("H").length-1;
if(count1>count2 && count1>count3)
{
System.out.println("player2 has passed"+p2[count4]);
p2[count4]=b.player3(p2[count4]);
return p2[count4];
}
else
{
System.out.println("player2 has passed"+p2[count1]);
p2[count1]=b.player3(p2[count1]);
return p2[count1];
}
  

}
public String player3(String rep)
{
String s=p3.toString();
String temp=null;
for(int i=0;i<7;i++)
{
temp=temp+Character.toString(p3[i].charAt(0));
}
if(temp.equals("CCCCCCC")|| temp.equals("DDDDDDD") || temp.equals("SSSSSSS") || temp.equals("HHHHHHH"))
{
game="over";
System.out.println("Player 3 won the game:");
return "";
}
int count1=temp.split("c").length-1;
int count2=temp.split("S").length-1;
int count3=temp.split("D").length-1;
int count4=temp.split("H").length-1;
if(count1>count2 && count1>count3)
{
System.out.println("player3 has passed"+p3[count3]);
p3[count4]=b.player3(p3[count4]);
return p3[count4];
}
else
{
System.out.println("player3 has passed"+p3[count1]);
p3[count1]=b.player4(p3[count1]);
return p3[count1];
}

}
public String player4(String rep)
{
String s=p4.toString();
String temp=null;
for(int i=0;i<7;i++)
{
temp=temp+Character.toString(p4[i].charAt(0));
}
if(temp.equals("CCCCCCC")|| temp.equals("DDDDDDD") || temp.equals("SSSSSSS") || temp.equals("HHHHHHH"))
{
game="over";
System.out.println("Player 4 won the game:");
return "";
}
int count1=temp.split("c").length-1;
int count2=temp.split("S").length-1;
int count3=temp.split("D").length-1;
int count4=temp.split("H").length-1;
if(count1>count2 && count1>count3)
{
System.out.println("player4 has passed"+p4[count4]);
p4[count4]=rep;
return p4[count4];
}
else
{
System.out.println("player4 has passed"+p4[count1]);
p4[count1]=rep;
return p4[count1];
}

}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote