Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE PROVIDE COMPLETE ANSWER ALSO PLEASE DO NOT COPY FROM OTHER EXPERTS **Question** Collection.java This file defines a Collection object. Variables: All variables must not

PLEASE PROVIDE COMPLETE ANSWER

ALSO PLEASE DO NOT COPY FROM OTHER EXPERTS

**Question**

Collection.java This file defines a Collection object. Variables: All variables must not be allowed to be directly modified outside the class in which they are declared, unless otherwise stated in the description of the variable. The Collection class must have these variables: binder a value that represents the Cards stored in the Collection, represented by an array of Card objects o NOTE: Treat this array like a binder of empty sleeves that can hold cards. If you take a Card out of the sleeve, there is no need to move all the other Cards forward one sleeve to ensure a space is not empty. You should also think about how we represent the absence of an object when we have reference types. There must be a value in the reference, but what value for reference types is suitable to represent empty? cardsOwned the number of Cards that this Collection holds, initially always 0. Constructor(s): A constructor that takes in binder. Dont forget to initialize the cardsOwned variable based on the number of cards in the binder. A constructor that takes in no parameters but initializes binder to an array of size 4 with no Card objects and cardsOwned to 0. NOTE: The constructor parameters should be in the order listed above. Assume that constructor inputs will be valid (i.e., binder will not be null). Methods: All methods should have the proper visibility to be used where it is specified, they are used. addCard o Given an index represented by an integer and a card represented by a Card parameter, add that Card to the index in the binder array and print out the Card that was previously at that index in the following format: Replaced: {oldCard} and return the Card object that was previously in that slot. If there is not a Card already at the index, print out the Card being inserted in the following format Inserted: {card} and return null. o Note that you can print out a Card directly since we implemented the toString method above. In the following weeks, we will go more in-depth as to why this is the case! o If the index is invalid or the Card passed in is null, return null and print out Cannot add a card to this spot. o Update cardsOwned if there was not already a Card there. sellCard o Given an index, sell the Card that is found there and print out on a new line Sold: {card}. Remove and return the Card object that was sold. o If the index is invalid or there is not a Card at that index, print out on a new line There was no card to sell! and return null. o Update cardsOwned if a Card was removed.

showCertainCards o Given a numerical condition, display all Cards with a condition greater than the value passed in. o Print each Card on a new line. o HINT: As youre writing this method you will likely run into an exception. Consider what it is and how you can check for it. restoreAllCards o Restore all the cards that are restorable. o To restore a Card, add a random integer from [1, 10] to the current condition. o Print each Card that was restored on a new line in the format Restored to {newCondition}: {card}. Note that you must print out the card information before updating the Cards condition (i.e., the card should be printed with the old condition). o If no cards were restored, print out on a new line There were no cards to restore. battle o Given an index, battle using the Card at the index in the binder array by subtracting a random integer [1, 10] from the Cards current condition (remember that the condition has a minimum value of 40, so if subtracting the random integer makes it fall below this number, simply set condition to 40). o Print out the following statement on a new line using the data from the Card you just used in battle. o Your print statement should have the following format: Used: {card}. o If the index is invalid or the Card passed in is null, print out Cannot battle with a card at this spot. toString o This method will return a String representation of a Collection. o If there are no cards in the Collection, then the string must be formatted as follows: I own no cards!. o Otherwise, the string must be formatted as follows: I own {cardsOwned} cards. {card1} {card2} {card3} ... Note that you must print out all cards in the binder in the specified format. We are only showing until a hypothetical third card as an example. o The method String.format will be useful. Getters and setters only as necessary Any helper methods that you may need; ensure that these methods are not accessible outside of this class.

===========================================

The below is code that is connected to the question above

public enum PokemonType { NORMAL, FIRE, WATER, GRASS, GROUND }

======================================

public class Card { private int hitPoints; private String pokemonName; private PokemonType pokemonType; private String attack; private int condition; public Card(int hitPoints, String pokemonName, PokemonType pokemonType, String attack, int condition) { this.hitPoints = hitPoints; this.pokemonName = pokemonName; this.pokemonType = pokemonType; this.attack = attack; setCondition(condition); } public Card(int hitPoints, String pokemonName, PokemonType pokemonType) { this(hitPoints, pokemonName, pokemonType, "Hyperbeam", 80); } public Card() { this(120, "Ditto", PokemonType.NORMAL, "Imposter", 89); } void setCondition(int condition) { if (condition >= 40 && condition <= 100) { this.condition = condition; if (condition >= 90) { System.out.println("Card condition: Mint"); } else if (condition >= 80) { System.out.println("Card condition: Excellent"); } else if (condition >= 70) { System.out.println("Card condition: Very Good"); } else if (condition >= 60) { System.out.println("Card condition: Good"); } else if (condition >= 50) { System.out.println("Card condition: Fine"); } else { System.out.println("Card condition: Damaged"); } } else { this.condition = 80; System.out.println("Condition not within appropriate range, set to 80 (Excellent)"); } } public boolean isRestorable() { return condition >= 50 && condition <= 89; } @Override public String toString() { return String.format("<%d,%s,%s,%s,%d,%b>", hitPoints, pokemonName, pokemonType, attack, condition, isRestorable()); } public int getHitPoints() { return hitPoints; } public void setHitPoints(int hitPoints) { this.hitPoints = hitPoints; } public String getPokemonName() { return pokemonName; } public void setPokemonName(String pokemonName) { this.pokemonName = pokemonName; } public PokemonType getPokemonType() { return pokemonType; } public void setPokemonType(PokemonType pokemonType) { this.pokemonType = pokemonType; } public String getAttack() { return attack; } public void setAttack(String attack) { this.attack = attack; } public int getCondition() { return condition; } public void setConditionFromOutside(int condition) { setCondition(condition); } }

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

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

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

=+ What is their expected negotiating style?

Answered: 1 week ago

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago