Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***NEWEST POST*** I posted this question not too long ago but I want to specifically know how to write the methods in Collection.java. Specifically the

***NEWEST POST*** I posted this question not too long ago but I want to specifically know how to write the methods in Collection.java. Specifically the showCertainCards, restoreAllCards, battle, and toString methods please. I have noted everything else in the previous solution that was given to me last time I posted this question.

BEFORE READING: I know this question has already been discussed in another post but I want to know how to complete Collection.java and Driver.java . I do not need Card.java answered because that solution was already posted. I will leave it included in the problem for context.

Card.java This file defines a Card 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 Card class must have these variables: hitPoints the hit points, or HP, of the Card as a whole number pokemonName the name of the Pokmon on the Card (example: Pikachu) pokemonType the type of the Pokmon on the Card. This variable must be of type PokemonType. attack the name of the attack on the Card (example: Quick Attack) condition Trading cards have a condition category ranging from 40 (inclusive) to 100 (inclusive). Ensure that condition is always a whole number in the appropriate range. Once condition is initialized, it should print o Card condition: Mint if the score is from [90, 100]

Card condition: Excellent if the score is from [80, 89] o Card condition: Very Good if the score is from [70, 79] o Card condition: Good if the score is from [60, 69] o Card condition: Fine if the score is from [50, 59] points o Card condition: Damaged if the score is from [40, 49] points. If the condition is not within the appropriate range, then set it to 80 and print the correct statement. This should only be printed when condition is first initialized (i.e. on construction). Constructor(s): A constructor that takes in the hitPoints, pokemonName, pokemonType, attack, and condition A constructor that takes in hitPoints, pokemonName, and pokemonType. In this case, attack should be assumed to be Hyperbeam and condition should be assumed to be 80. A constructor that takes in no arguments. In this case, hitPoints should be 120, name should be Ditto, pokemonType should be NORMAL, attack should be Imposter, and condition should be 89. NOTE: the constructor parameters should be in the order listed above. Methods: All methods should have the proper visibility to be used where it is specified, they are used. isRestorable o This method returns true if the Cards condition is between [50, 89], and false otherwise. toString o This method will return a String representation of a Card. o The string must be formatted as follows (note the string is all in one line): <{value1},{value2},{value3},{value4},{value5},{value6}> {valueN} should be displayed in the following order: hitPoints, pokemonName, pokemonType, attack, condition, isRestorable() o The method String.format should be used to accomplish this. Getters and setters only as necessary Any helper methods that you may need; ensure that these methods are not accessible outside of this class.

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

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.

PokemonType.java This file defines a PokemonType enumeration. The only possible values it can have are NORMAL, FIRE, WATER, GRASS, or GROUND.

Driver.java This file is used to test your code. You do not need to turn this in. Methods: main o Create a Collection object with an empty array of at least 3 cards. Maybe its your collection?! o Create 3 Card objects and add them to the Collection using addCard(). Remember you created 3 different constructors, so it may be a good idea to use a different constructor for each card. o Remove 1 Card object from the Collection using sellCard(). o Print out the Collection object. o Call showCertainCards() with a condition category that will filter out certain cards. o Call restoreAllCards() on the Card objects in Collection. o Battle with 1 Card from the Collection using battle()

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions