Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA need HELP PLZ! This is the cpp needed. CardArrayMaster.java: /* Card Array

ID: 3842835 • Letter: J

Question

JAVA need HELP PLZ!

This is the cpp needed.

CardArrayMaster.java:

/* Card Array Master is a generic class usefull for you to test your
* CardArrayList class. At the beginning it is heavily commented out
* but as you get more and more working, you can remove sections
* to test various things out.
*/
import java.util.*;
import java.io.*;

public class CardArrayMaster {

   public static void main(String[] args)
{
PrintStream SO = System.out; // Lazy mode enabled;

// STAGE 1
// Can we add to a master list and print it out?
CardArrayList masterList1 = new CardArrayList();
masterList1.add(new Card());   
masterList1.add(new Card(20));   
masterList1.add(new Card(10,10));
SO.print("Initial list : ");
SO.println(masterList1);   

// STAGE 2
// Can we add a premium card?
// masterList1.add(new PremiumCard(100));   
// SO.print("Premium Card : ");
// SO.println(masterList1);

// STAGE 3
// Can we add cars in the middle?

// masterList1.add(1, new Card(4,4));
// masterList1.add(1, new Card(5,5));
// SO.print("Added internal : ");
// SO.println(masterList1);

// STAGE 4
// can we add more cards and make it expand?

// masterList1.add(new Card(6));
// masterList1.add(new Card(7));
// masterList1.add(new Card(8));
// masterList1.add(new Card(9));
// masterList1.add(new Card(10));
// masterList1.add(new Card(11));
// masterList1.add(new Card(12));
// SO.print("After Expand : ");
// SO.println(masterList1);

// STAGE 5
// Can we Remove the end value
// masterList1.remove();
// SO.print("After Remove : ");
// SO.println(masterList1);

// STAGE 6
// Does remove return the removed value?

// SO.print("Removed value : ");
// SO.println(masterList1.remove() );
// SO.print("List afterward : ");
// SO.println(masterList1);

// STAGE 7
// Did it remove from the middle
// And return the value removed?
// Card tmp = masterList1.remove(2);
// SO.print("Removed value : ");
// SO.println(tmp);
// SO.print("List afterward : ");
// SO.println(masterList1);

// STAGE 8
// Did get work correctly?
// SO.print("Get Values : ");
// SO.println(masterList1.get(2) + " : " + masterList1.get(4) );
// masterList1.get(2).weaken();
// masterList1.get(4).boost();
// SO.print("Altered Values : ");
// SO.println(masterList1.get(2) + " : " + masterList1.get(4) );

// STAGE 9
// IndexOF

// SO.print("Found Success : ");
// SO.println(masterList1.indexOf(new Card(110,110)));
// SO.print("Found Failed : ");
// SO.println(masterList1.indexOf(new Card(99,99)));
// SO.print("Found Failed : ");
// SO.println(masterList1.indexOf(new Card(600,600)));

// STAGE 10
// Does shuffle work?
// SO.print("Before shuffle : ");
// SO.println(masterList1);
// masterList1.shuffle();
// SO.print("Post shuffle 1 : ");
// SO.println(masterList1);
// masterList1.shuffle();
// SO.print("Post shuffle 2 : ");
// SO.println(masterList1);

// STAGE 11
// Does Clear Work?
// masterList1.clear();
// SO.print("After Clear : ");
// SO.println(masterList1);

// STAGE 12
// Create a large list
// And check that sort works.

// for (int i=0; i <100; i++)
// {
// masterList1.add(new Card());
// }
// for (int i=0; i <5; i++)
// {
// masterList1.add(new PremiumCard());
// }

// SO.print("Before Sorted : ");
// SO.println(masterList1);
// masterList1.sort();
// SO.print("Success Sorted : ");
// SO.println(masterList1);

// STAGE 13
// Can we create a second list
// and make a copy of all NON premium cards

// CardArrayList masterList2 = new CardArrayList(1);

// for (int j = 0; j <masterList1.size(); j++)
// {
// if (!(masterList1.get(j) instanceof PremiumCard))
// {
// masterList2.add(masterList1.get(j) );
// }
// }

// SO.print("Success Removed: ");
// SO.println(masterList2);
}
}

OVERVIEW This program primarily focuses on the implementation of a ArrayList type interface and the necessary methods to implement the ArrayList. It also includes polymorphism and class comparison. INSTRUCTIONS Your deliverable will be to turn in three files. The files will be named Card.java, PremiumCard.java and the last file will be called CardArrayList.java. You will need support files CardSorter.java from the course web site. For this assignment, any use of a data control structure other than a simple Arrary or String will result in no credit. I am aware that this assignment could be done quite simply by the implementation of an ArrayList but the point of the assignment is to do it without the standard implementation to get a feel for how they work "under the hood" COLLECTABLE CARD While the primary goal of this assignment will be the implementation and use of a custom ArrayList. The particular implementation we will use will focus on the idea of a simple collectable card game. For our card game, we will assume that every card has two values expressed as integers. Each card will have power and a toughness rating. These numbers need to be a minimum of 1 and a maximum of 1000. Cards then have a calculated cost attribute that comes from the formula below. cost IV1.5 power 0.9 toughness Rounded up to the nearest integer.

Explanation / Answer

I used the Tester program provided in the question. Just uncommented all the statements to make it work. Output is shown at the end of all the java files.

PROGRAM CODE:

Card.java

package cardlist;

import java.util.Random;

public class Card implements Comparable<Card>{
  
   private int power;
   private int toughness;
   private int cost;
   private Random random;
  
   public Card() {
       random = new Random();
       power = random.nextInt(1000) + 1;
       toughness = random.nextInt(1000) + 1;
   }
  
   public Card(int x) {
       if(x<=1000 && x>=1)
       {
           this.power = x;
           this.toughness = x;
           calculateCost();
       }
       else throw new IndexOutOfBoundsException("Invalid input");
   }

  
   public Card(int power, int toughness) {
       this.power = power;
       this.toughness = toughness;
       calculateCost();
   }

   public int getPower() {
       return power;
   }

  
   public int getToughness() {
       return toughness;
   }

   private void calculateCost()
   {
       cost = (int)(Math.sqrt(1.5*power + 0.9*toughness));
   }
  
   public int getCost()
   {
       return cost;
   }
  
   public void weaken()
   {
       power = (int) (power - power*0.1 );
       toughness = (int) (toughness - toughness*0.1 );
       calculateCost();
   }
  
   public void boost()
   {
       power = (int) (power + power*0.1 );
       toughness = (int) (toughness + toughness*0.1 );
       calculateCost();
   }
   @Override
   public boolean equals(Object obj) {
       if(obj instanceof Card)
       {
           Card card = (Card)obj;
           if(card.getCost() == this.cost && card.getPower() == this.power && card.getToughness() == this.toughness)
           {
               return true;
           }
           else return false;
       }
       else return false;
   }
  
   @Override
   public String toString() {
       return "[" + power + "/" + toughness + "]";
   }

   @Override
   public int compareTo(Card o) {
       if(o == null)
           return -1;
       if(this.equals(o))
           return 0;
       else if(cost == o.getCost())
       {
           if(power == o.getPower())
               return 0;
           else if(power < o.getPower())
               return -1;
           else
               return 1;
       }
       else if(cost > o.getCost())
           return 1;
       else return -1;
  
   }

  
}

PremiumCard.java

package cardlist;

public class PremiumCard extends Card{

   public PremiumCard(int x) throws Exception {
       super(x);
   }
  
   public PremiumCard(int p, int t) {
       super(p, t);
   }
  
   public PremiumCard() {
       super();
   }
  
   @Override
   public String toString() {
       // TODO Auto-generated method stub
       return "{{" + getPower() + "/" + getToughness() + "}}";
   }
}

CardArrayList.java

package cardlist;

import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

public class CardArrayList {
  
   private Card cards[];
   private int size;
   private Random random;
  
   public CardArrayList(int x) {
       random = new Random();
       if(x>=1)
       {
           cards = new Card[x];
           size = 0;
       }
       else throw new IndexOutOfBoundsException("Invalid Input");
   }
  
   public CardArrayList() {
       random = new Random();
       clear();
   }
  
   public int size()
   {
       return size;
   }
  
   public void add(Card x)
   {
       if(!isRoom())
           expand();
      
       cards[size++] = x;
      
   }
  
   public Card remove()
   {
       Card card = cards[size-1];
       size--;
       return card;
   }
  
   public Card remove(int j)
   {
       if(j<0 || j>size-1)
           throw new ArrayIndexOutOfBoundsException("Index value is out of bounds");
       else
       {
           Card card = cards[j];
           for(int i=j; i<size-1; i++)
               cards[i] = cards[i+1];
           size--;
           return card;
       }
   }
  
   public Card get(int x)
   {
       if(x<0 || x>size-1)
           throw new ArrayIndexOutOfBoundsException("Index value is out of bounds");
       else
           return cards[x];
   }
  
   public int indexOf(Card card)
   {
       for(int i=0; i<size; i++)
       {
           if(cards[i].equals(card))
               return i;
       }
       return -1;
   }
  
   public void add(int l, Card x)
   {
       if(l>0 && l<cards.length)
       {
           if(!isRoom())
               expand();
           if(l<size-1)
           {
               for(int i=size; i>l; i--)
               {
                   cards[i] = cards[i-1];
               }
               cards[l] = x;
           }
           else
           {
               cards[l] = x;
           }
           size++;
       }
       else
           throw new ArrayIndexOutOfBoundsException("Index value is out of bounds");
   }
  
   private void swap(int a, int b)
   {
       Card x = cards[a];
       cards[a] = cards[b];
       cards[b] = x;
   }
  
   public void sort() {
       for(int i=0; i<size; i++)
       {
           for(int j=i; j<size; j++)
           {
               if(cards[i].compareTo(cards[j]) == -1)
                   swap(i, j);
           }
       }
   }
  
   public void shuffle()
   {
       int i = 0, times = size*5;
       while(i<times)
       {
           int a = random.nextInt(size);
           int b = random.nextInt(size);
           swap(a, b);
           i++;
       }
      
   }
  
   private boolean isRoom()
   {
       return size<cards.length;
   }
  
   private void expand()
   {
       Card newCards[] = new Card[cards.length*2];
       for(int i=0; i<cards.length; i++)
           newCards[i] = cards[i];
       cards = newCards;
   }
  
   public void clear()
   {
       size = 0;
       cards = new Card[10];
   }
  
   @Override
   public String toString() {
       String result = "[0: ";
       for(int i=0; i<size; i++)
       {
           result += cards[i];
           if(i<size-1)
               result += ",";
       }
       result += " :" + size + "]";
       return result;
   }
}

OUTPUT:

Initial list : [0: [378/91],[20/20],[10/10] :3]
Premium Card : [0: [378/91],[20/20],[10/10],{{100/100}} :4]
Added internal : [0: [378/91],[5/5],[4/4],[20/20],[10/10],{{100/100}} :6]
After Expand : [0: [378/91],[5/5],[4/4],[20/20],[10/10],{{100/100}},[6/6],[7/7],[8/8],[9/9],[10/10],[11/11],[12/12] :13]
After Remove : [0: [378/91],[5/5],[4/4],[20/20],[10/10],{{100/100}},[6/6],[7/7],[8/8],[9/9],[10/10],[11/11] :12]
Removed value : [11/11]
List afterward : [0: [378/91],[5/5],[4/4],[20/20],[10/10],{{100/100}},[6/6],[7/7],[8/8],[9/9],[10/10] :11]
Removed value : [4/4]
List afterward : [0: [378/91],[5/5],[20/20],[10/10],{{100/100}},[6/6],[7/7],[8/8],[9/9],[10/10] :10]
Get Values : [20/20] : {{100/100}}
Altered Values : [18/18] : {{110/110}}
Found Success : 4
Found Failed : -1
Found Failed : -1
Before shuffle : [0: [378/91],[5/5],[18/18],[10/10],{{110/110}},[6/6],[7/7],[8/8],[9/9],[10/10] :10]
Post shuffle 1 : [0: [18/18],[10/10],[9/9],[8/8],[378/91],[6/6],[7/7],{{110/110}},[10/10],[5/5] :10]
Post shuffle 2 : [0: [9/9],[8/8],[378/91],[18/18],[6/6],[10/10],[5/5],{{110/110}},[10/10],[7/7] :10]
After Clear : [0: :0]
Before Sorted : [0: [553/674],[13/97],[472/125],[926/164],[378/668],[112/326],[211/706],[664/144],[825/755],[339/165],[539/570],[663/602],[745/263],[778/732],[112/643],[653/805],[547/621],[771/467],[376/667],[560/406],[823/26],[505/515],[10/120],[198/745],[752/977],[806/885],[410/173],[262/468],[347/951],[368/822],[680/588],[908/742],[396/369],[758/399],[994/557],[895/850],[731/476],[995/410],[319/716],[967/892],[828/395],[450/611],[655/820],[63/436],[76/51],[338/624],[804/486],[869/619],[117/286],[732/587],[938/965],[188/967],[492/663],[116/946],[90/69],[733/73],[860/596],[727/307],[148/414],[395/786],[151/157],[842/511],[965/716],[506/175],[801/115],[839/436],[418/459],[154/67],[685/881],[294/15],[284/155],[75/882],[935/48],[61/400],[942/848],[626/183],[658/816],[415/659],[992/870],[496/6],[457/904],[127/765],[343/266],[337/523],[592/394],[682/265],[316/945],[472/850],[447/407],[582/361],[524/710],[437/822],[205/227],[983/283],[29/714],[395/291],[423/39],[295/214],[473/357],[630/598],{{428/69}},{{200/55}},{{745/364}},{{566/393}},{{122/317}} :105]
Success Sorted : [0: [995/410],[994/557],[992/870],[983/283],[967/892],[965/716],[942/848],[938/965],[935/48],[926/164],[908/742],[895/850],[869/619],[860/596],[842/511],[839/436],[828/395],[825/755],[823/26],[806/885],[804/486],[801/115],[778/732],[771/467],[758/399],[752/977],[745/263],{{745/364}},[733/73],[732/587],[731/476],[727/307],[685/881],[682/265],[680/588],[664/144],[663/602],[658/816],[655/820],[653/805],[630/598],[626/183],[592/394],[582/361],{{566/393}},[560/406],[553/674],[547/621],[539/570],[524/710],[506/175],[505/515],[496/6],[492/663],[473/357],[472/850],[472/125],[457/904],[450/611],[447/407],[437/822],{{428/69}},[423/39],[418/459],[415/659],[410/173],[396/369],[395/786],[395/291],[378/668],[376/667],[368/822],[347/951],[343/266],[339/165],[338/624],[337/523],[319/716],[316/945],[295/214],[294/15],[284/155],[262/468],[211/706],[205/227],{{200/55}},[198/745],[188/967],[154/67],[151/157],[148/414],[127/765],{{122/317}},[117/286],[116/946],[112/643],[112/326],[90/69],[76/51],[75/882],[63/436],[61/400],[29/714],[13/97],[10/120] :105]
Success Removed: [0: [995/410],[994/557],[992/870],[983/283],[967/892],[965/716],[942/848],[938/965],[935/48],[926/164],[908/742],[895/850],[869/619],[860/596],[842/511],[839/436],[828/395],[825/755],[823/26],[806/885],[804/486],[801/115],[778/732],[771/467],[758/399],[752/977],[745/263],[733/73],[732/587],[731/476],[727/307],[685/881],[682/265],[680/588],[664/144],[663/602],[658/816],[655/820],[653/805],[630/598],[626/183],[592/394],[582/361],[560/406],[553/674],[547/621],[539/570],[524/710],[506/175],[505/515],[496/6],[492/663],[473/357],[472/850],[472/125],[457/904],[450/611],[447/407],[437/822],[423/39],[418/459],[415/659],[410/173],[396/369],[395/786],[395/291],[378/668],[376/667],[368/822],[347/951],[343/266],[339/165],[338/624],[337/523],[319/716],[316/945],[295/214],[294/15],[284/155],[262/468],[211/706],[205/227],[198/745],[188/967],[154/67],[151/157],[148/414],[127/765],[117/286],[116/946],[112/643],[112/326],[90/69],[76/51],[75/882],[63/436],[61/400],[29/714],[13/97],[10/120] :100]