Question: Java program here I am stump with trying to fix this program we given. Basically I need to convert it from using a linkedlist and

Java program here I am stump with trying to fix this program we given. Basically I need to convert it from using a linkedlist and have it run by using a stack.

Thanks for the help

Program

import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Random;

class Player{ String playerCards[]=new String[5]; }

public class Cards {

public static void main(String[] args) throws FileNotFoundException,IOException{ int choice; do{ BufferedReader in=new BufferedReader(new FileReader("")); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); LinkedList card=new LinkedList<>(); String str; while((str=in.readLine())!=null){//reading card from file card.add(str); } Random ran=new Random(); LinkedList suffledCard=new LinkedList<>(); while(card.size()!=0){//suffling the card suffledCard.add(card.remove(ran.nextInt(card.size()))); } System.out.println("Enter the number of player"); int n=Integer.parseInt(br.readLine()); Cards c=new Cards(); LinkedList players=new LinkedList<>(); for(int i=1;i<=n;i++){ //dealing the cards to player Player p=new Player(); for(int j=0;j<5;j++){ p.playerCards[j]=suffledCard.removeFirst(); } players.add(p); } //displaying cards of player int i=1; for(Player p:players){ System.out.println("Player "+(i++)); for(int j=0;j<5;j++){ System.out.print(p.playerCards[j]+" "); } System.out.println(" "); } System.out.println("Do you wish to continue?? Enter 1 for YES and 2 for NO"); choice=Integer.parseInt(br.readLine()); }while(choice==1); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!