Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read carefully and answer following question using supplied starter code. Please modify the starter code. Please do not use different code. Be sure to

Please read carefully and answer following question using supplied starter code. Please modify the starter code. Please do not use different code. Be sure to match output to the attached sample output as seen below. Ensure that the code runs properly. Please leave comments explaining programming. Thank you!!!

Question: Implement your own version of the queue ADT using a circular array. Implement all necessary public methods according to the interface. Additionally, override the toString method. Design and implement a simple pokemon card game.In the game, the player gets 10 random cards and the computer/opponent gets random 10 cards - which are then stored in queues.

Each card's information should be imported from the pokemon.csv file.

In each round, the player and computer's front card in the queue will be compared.

If the player's pokemon's attack value is greater than the computer's pokemon's defense value, then player wins. Otherwise, the computer/opponent wins.

The winner of the round will "win" both cards, so the two cards are inserted back into the winner's queue.

The game should ask for how many rounds to play or end as soon as one of the player's card queue is empty.

SAMPLE CODE:

Queue.java:

public interface Queue { /** * Place an element at the rear of the queue. * * @param it The element being enqueued. * @throws IllegalStateException- if the element cannot be added at this time due to capacity restrictions */ public void enqueue(E it) throws IllegalStateException;; /** * Remove and return element at the front of the queue. * * @return The element at the front of the queue. * @return null if the queue is empty */ public E dequeue(); /** * @return The front element. * @return null if the queue is empty */ public E frontValue(); /** * Detects whether this queue is empty. * * @return True if the queue is empty. * @return False if the queue has one or more items in it. */ public boolean isEmpty(); /** * @return The number of elements in the queue. */ public int length(); }

Main.java:

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { List allCards = readCSV("pokemon.csv"); Collections.shuffle(allCards); Stack player = new LinkedStack(); Stack computer = new LinkedStack(); for (int i = 0; i = Computer.getDefense()) { System.out.println("Player wins this round. "); } else if (Player.getAttack() == Computer.getDefense()) { System.out.println("It's a tie! "); } else { System.out.println("Computer wins this round. "); } } } static List readCSV(String filename) { File file = new File(filename); List pokemonList = new ArrayList(); try { Scanner scan = new Scanner(file); scan.nextLine(); while (scan.hasNextLine()) { String[] info = scan.nextLine().split(","); // #,Name,Type 1,Type 2,Total,HP,Attack,Defense,Sp. Atk,Sp. Def,Speed,Generation,Legendary Pokemon poke = new Pokemon(info[1], Integer.parseInt(info[6]),Integer.parseInt(info[7])); pokemonList.add(poke); } } catch (FileNotFoundException e) { System.out.println("File not found!"); e.printStackTrace(); } return pokemonList; } }

ArrayQueue.java:

public class ArrayQueue implements Queue { private final int DEFAULT_CAPACITY = 7; private T[] queue; private int front, back, count; // front of the queue is left // back of the queue is right public ArrayQueue() { queue = (T[])(new Object[DEFAULT_CAPACITY]); } public ArrayQueue(int size) { queue = (T[])(new Object[size]); } /* What is the big o runtime efficiency/complexity of enqueue in a circular array queue? */ @Override public void enqueue(T it) throws IllegalStateException { if (count  

Pokemon.java

public class Pokemon { private String name; private int attack, defense; public Pokemon(String name, int attack, int defense) { this.name = name; this.attack = attack; this.defense = defense; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAttack() { return attack; } public void setAttack(int attack) { this.attack = attack; } public int getDefense() { return defense; } public void setDefense(int defense) { this.defense = defense; } public String toString() { } }

pokemon.csv:

https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

SAMPLE OUTPUT (please match):

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Welcome to the pokemon battle ground. How many rounds will this battle be? Round \#: 1 Player: Pokemon:nane='Electabuzz', attack=83, defense=57\} Computer: Pokenon { nane='Latias', attack =80, defense =90} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Player has 9 cards left. Computer has 11 cards left. Player has 9 cards left. Computer has 11 cards left. Computer wins! Do you want another battle? (1 for yes, any other input will exit the battle.): Main (3) Round \#: 1 Player: Pokenon\{nane='Electabuzz', attack =83, defense =57} Computer: Pokemon { name='Latias', attack=80, defense =90} \#\#\#\#\#\# fight! \#\#\#\#\#\#\# Computer wins this round. Player has 9 cards left. Computer has 11 cards left. Player has 9 cards left. Computer has 11 cards left. Computer wins! Do you want another battle? ( 1 for yes, any other input will exit the battle.): Welcone to the pokenon battle ground. How many rounds will this battle be? Round \#: 2 Player: Pokenon\{nane = 'Plusle ' P, attack =50, defense =4} Conputer: Pokenontnane='Combee', at tack=30, defense =42} H\#\#\#\#\# fight! \#A#\#\# Player wins this round. Player has 12 cards left. Computer has 8 cands left. Round \#: 3 Player: Pokenon\{nane='Kakuna', attack =25, defense =50} Computer: Pokenon\{name='Floatzel', attack=105, defense =55} \#\#\#\#\#\# Fight! \#\#\#\#\#\# Conputer ains this round. Player has 11 cards left. Conputer has 9 cards left. Round \#: 4 PLayer: Pokenon \{nane= 'Dewgong', attack=70, defense=80 } Conputer: Pokemon { name='Absol', attack=130, defense=60\} \#H fight! \#\#\#\# Player wins this round. Player has 12 cards left. Computer has 8 cards left. Round \#: 5 PLayer: Pokenon\{name='Rhydon', at tack =130, defense =120} Conputer: Pokenon:\{nane = ' Timburr', attack =80, defense =55 \} \#\#\#\#\#\# fight! \#\#\#\#\#\# Player wins this round. Player has 13 cards left. Computer has 7 cards left. Round \#: 26 PLayer: Pokenon\{nane='Ariados', attack =90, defense=70\} Conputer: Pokenon \{name='Drifblim', attack =80, defense =44} Player wins this round. blayer has 20 cards left. Round \#: 26 PLayer: Pokemon\{nane=' Ariados', attack=90, defense =70} Computer: Pokemon \{name='Drifblim', attack=80, defense=44\} \#\#\#\#\#\# fight! \#\#\#\#\#\# Player wins this round. Player has 20 cards left. Computer has 0 cards left. Player has 20 cards left. Computer has 0 cards left. Player vins! Do you want another battle? (1 for yes, any other input will exit the battle.): Welcome to the pokemon battle ground. How many nounds will this battle be? Main (3) Pedyer has 1 cards lett. Computer has 19 cards left. Round \#: 85 Player: Pokemon { name = 'Swablu', attack =40, defense =60} Computer: Pokenon { nane = 'Manectric', attack =75, defense =60} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Player has 0 cards left. Computer has 20 cards left. Player has cards left. Computer has 20 cards left. Computer wins! Do you want another battle? (1 for yes, any other input will exit the battle.): Process finished with exit code

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

1. Are my sources credible?

Answered: 1 week ago

Question

3. Are my sources accurate?

Answered: 1 week ago

Question

1. Is it a topic you are interested in and know something about?

Answered: 1 week ago