Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please make the java files 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 files that follow the below steps. PLEASE as soon as possible.

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago