Question: REWRITE THIS CODE, USE COMPLETELY DIFFERENT LOGIC AND MAKE IT LOOK DIFFERENT WITH THE SAME USAGE. WILL KNOW IF YOU USED CHATGPT. please need help
REWRITE THIS CODE, USE COMPLETELY DIFFERENT LOGIC AND MAKE IT LOOK DIFFERENT WITH THE SAME USAGE. WILL KNOW IF YOU USED CHATGPT.
please need help with this will give thumbs up!!
///////////////////////////
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 PokemonCardGame { public static void main(String[] args) { List allCards = readCSV("C:\\Users\ ishu\\CSCDS2022\\CSC211\\Assigment03\\src\\pokemon.csv"); Collections.shuffle(allCards); Stack player = new LinkedStack<>(); Stack computer = new LinkedStack<>(); for (int i = 0; i < 10; i++) { player.push(allCards.get(i)); } for (int i = 10; i < 20; i++) { computer.push ( allCards.get ( i ) ); } for( int i = 0; i<10; i++){ int count = i +1; System.out.println(" Round:"+count); if(player.peek().getAttack() > computer.peek().getDefense()){ System.out.println(" Player wins"); System.out.println("Player :"+ player.peek().toString()); System.out.println("Computer :"+ computer.peek().toString()); player.pop(); computer.pop(); } else if (player.peek().getAttack() < computer.peek().getDefense()) { System.out.println("Computer wins "); System.out.println( " Player : " + player.peek().toString()); System.out.println("Computer :"+ computer.peek().toString()); player.pop(); computer.pop(); } else { System.out.println ( " TIE " ); System.out.println ( "Player :" + player.peek ().toString () ); System.out.println ( "Computer :" + computer.peek ().toString () ); player.pop (); computer.pop (); } }} 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(","); 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; } } //////////////////////////////////////////////////
public class LinkedStackimplements 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 Head = new Node(item,head); Head.next = head; head = Head; } } @Override public T pop() { temp = head; head = head.next; return temp.data; } @Override public T peek() { return head.data; } @Override public boolean isEmpty() { return false; } @Override public int length() { return 0; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("["); Node current = head; while (current != null) { sb.append(current.data.toString()); if (current.next != null) { sb.append(", "); } current = current.next; } sb.append("]"); return sb.toString(); } private class Node { T data; Node next; public Node(T data, Node next) { this.next = next; this.data = data; } } }
/////////////////////////////////////////
public class Pokemon { int Attack, Defense; String Data; public Pokemon( String data, int attack, int defense ){ this.Data = data; this.Attack = attack; this.Defense = defense; } public int getAttack() { return Attack; } public int getDefense() { return Defense; } @Override public String toString() { return "Pokemon{" + "attack=" + Attack + ", defense=" + Defense + ", data='" + Data + '\'' + '}'; } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
