Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do not answer if you cannot read the full question. I keep posting this question but no one is using my java code in

Please do not answer if you cannot read the full question. I keep posting this question but no one is using my java code in their response. I don't care about just getting the correct answer. I want to understand what is wrong with my code and how I would edit my code to work properly. Again, PLEASE DO NOT ANSWER IF YOU CANNOT UNDERSTAND THE REQUIREMENTS! I do not want to use someone else's code as that would be plagiarism.

Please modify MY CODE in java (attached at the bottom) to match the sample output as seen below. I am having trouble when I run my code. Thank you very much.

image text in transcribed

image text in transcribed

MY CODE (4 Classes):

Stack.java:

public interface Stack { /** * Adds a new entry to the top of this stack. * * @param item An object to be added to the stack. * @throws IllegalStateException- if the element cannot be added at this time due to capacity restrictions */ public void push(T item) throws IllegalStateException; /** * Removes and returns this stack's top entry. * * @return The object at the top of the stack. * @return null if the stack is empty */ public T pop(); /** * Retrieves this stack's top entry. * * @return The object at the top of the stack. * @return null if the stack is empty */ public T peek(); /** * Detects whether this stack is empty. * * @return True if the stack is empty. */ public boolean isEmpty(); /** * Retrieves the number of entries in this stack. * * @return number of entries. */ 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; } }

LinkedStack.java:

public class LinkedStack implements Stack { private Node head; private Node temp; @Override public void push(T item) throws IllegalStateException { if (head == null) { head = new Node(item, null); } else { Node vtx = new Node(head.data, head.next); vtx.next = head; head = vtx; } } @Override public T pop() { if (isEmpty()) { return null; } else { temp = head; head = head.next; return (T) temp; } } @Override public T peek() { if (isEmpty()) { return null; } else { return (T) head.next; } } @Override public boolean isEmpty() { return false; } @Override public int length() { return 0; } private class Node { T data; Node next; public Node(T data, Node next) { this.next = next; this.data = data; } } } 

Pokemon.java:

public class Pokemon { private String name; private int attack; private int defense; public Pokemon(String s, int parseInt, int parseInt1) { } 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; } } 
Sample Output: Round \#: 1 Player: Pokemon { name='Mime Jr.', attack=25, defense =45} Computer: Pokemon { name = 'Smeargle', attack =20, defense =35} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \#: 2 Player: Pokemon { name = 'Conkeldurr', attack =140, defense =95. Computer: Pokemon { name = 'Throh', attack =100, defense =85} \#\#\#\#\# fight! \#\#\#\#\#\# Player wins this round. Round \#: 3 Player: Pokemon { name = 'Skorupi ', attack =50, defense =90} Computer: Pokemon { name = 'Chikorita', attack =49, defense =65.. \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \#: 4 Player: Pokemon { name= 'Entei', attack=115, defense=85 Computer: Pokemon { name = 'Steelix', attack =85, defense =200} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \#: 5 Player: Pokemon { name= 'Clefable', attack=70, defense =73} Computer: Pokemon { name = 'Omanyte', attack =40, defense =100} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \#: 6 Player: Pokemon { name='Gallade', attack =125, defense =65} Computer: Pokemon { name='Sandslash', attack =100, defense =110} \#\#\#\# fight! \#\#\#\#\# Player wins this round. Round \#: 7 Player: Pokemon { name='Gliscor', attack= =95, defense =125} Computer: Pokemon { name='Slowbro', attack =75, defense =110} \#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \#: 8 Player: Pokemon { name='AltariaMega Altaria', attack =110, defense =110} Computer: Pokemon { name='Eelektross', attack =115, defense =80} \#\#\#\#\# fight! \#\#\#\#\#\# Player wins this round. Round \#: 10 Player: Pokemon { name='Sealeo', attack =60, defense =70} Computer: Pokemon { name='Gardevoir', attack =65, defense =65} \#\#\#\#\# fight! \#\#\#\#\#\# Computer wins this round. Round \# : 9 Clayer: Pokemon { name=' Ledian', attack =35, defense =50} \#\#\#\#\# fight! \#\#\#\#\#\# It's a tie

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions