Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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

Step: 3

blur-text-image

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago