Question: Please make the java programs that follow the below steps. PLEASE as soon as possible. ---------------------------------------------- card.java ---------------------------------------------- import java.util.Random; public class Card implements Comparable

Please make the java programs that follow the below steps. PLEASE as soon as possible.

Please make the java programs that follow the below steps. PLEASE assoon as possible. ---------------------------------------------- card.java ---------------------------------------------- import java.util.Random; public class Card implementsComparable{ private int power; private int toughness; private int cost; private Random----------------------------------------------

card.java

----------------------------------------------

import java.util.Random;

public class Card implements Comparable{ 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=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.getCost()) return 1; else return -1; }

}

CS145-PROGRAMMING ASSIGNMENT #8 MORE WITH CARDS OVERVIEW This program focuses on heaps and using the GUI INSTRUCTIONS Turn in Card.java, CardHeap.java and your main file. You are allowed to reuse your Card.java from a prior assignment with any necessary changes that you want to add IMPLEMENTATION DETAILS: You will reuse your Card.java file and you will write the GUI form and the CardHeap.java files to implement the necessary behavior THE PROGRAM In this assignment, you will implement a simple GUI program that will randomly add/remove cards that are the same as the ones we used in assignment #7 to a heap (Note that we will be ignoring the premium cards, although they should still work.). Your program should look like the following At the beginning CS 145 GUI Assignment-Your Name Here Last Removed Add Cloar CS145-PROGRAMMING ASSIGNMENT #8 MORE WITH CARDS OVERVIEW This program focuses on heaps and using the GUI INSTRUCTIONS Turn in Card.java, CardHeap.java and your main file. You are allowed to reuse your Card.java from a prior assignment with any necessary changes that you want to add IMPLEMENTATION DETAILS: You will reuse your Card.java file and you will write the GUI form and the CardHeap.java files to implement the necessary behavior THE PROGRAM In this assignment, you will implement a simple GUI program that will randomly add/remove cards that are the same as the ones we used in assignment #7 to a heap (Note that we will be ignoring the premium cards, although they should still work.). Your program should look like the following At the beginning CS 145 GUI Assignment-Your Name Here Last Removed Add Cloar

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!