Question: Please only respond if you have successfully ran the code after correcting the error. The previous responses have not corrected the error as seen below
Please only respond if you have successfully ran the code after correcting the error. The previous responses have not corrected the error as seen below (although thank you for your help).
This code seems correct but throws the following error:

My code below:
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); Queue player = new ArrayQueue(); Queue computer = new ArrayQueue(); for (int i = 0; i computerCard.getDefense()) { System.out.println("You win!"); playerScore += 2; player.enqueue(playerCard); player.enqueue(computerCard); } else if (computerCard.getDefense() > playerCard.getAttack()) { System.out.println("Computer wins!"); computerScore += 2; computer.enqueue(playerCard); computer.enqueue(computerCard); } } System.out.println("Your score: " + playerScore); System.out.println("Computer score: " + computerScore); } static List readCSV(String filename) { File file = new File(filename); List pokemonList = new ArrayList(); try { Scanner scan = new Scanner(file); // skip the header if (scan.hasNextLine()) { 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 ArrayQueueimplements Queue { private final int DEFAULT_CAPACITY = 7; private T[] queue; private int front, back, count = 0; // 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 == queue.length) { throw new IllegalStateException("Queue is full"); } queue[back] = it; back = (back + 1) % queue.length; count++; } @Override public T dequeue() { if (isEmpty()) { return null; } else { T item = queue[front % queue.length]; queue[front % queue.length] = null; front++; count--; return item; } } @Override public T frontValue() { if (isEmpty()) { return null; } else { return queue[front % queue.length]; } } @Override public boolean isEmpty() { return count == 0; } @Override public int length() { return count; } @Override public String toString() { StringBuilder output = new StringBuilder(); int i = front; while (i
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(); String toString(); int size(); }
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() { return "Pokemon{name: " + name + ", attack: " + attack + ", defense: " + defense + "}"; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
