Question
Part 4: Implementing PokemonGame.java (3 points) (creating and testing) (Pair programming allowed) You will complete the method public void startJourney() in PokemonGame.java. This section will
Part 4: Implementing PokemonGame.java (3 points) (creating and testing) (Pair programming allowed)
You will complete the method public void startJourney() in PokemonGame.java. This section will walk you through the code you need to add, marked with TODO in the starter code.
4.1 Implement and call the two helper methods:
public static Berry getUserBerry(Scanner myScanner)
This method should do the following:
- Prompt the user to type in what berry they would like to use by using the prompt string in the PROMPT_MSG_BERRY variable.
- if the Berry they have entered is not one of the Berries we recognize, print an error message. See PROMPT_MSG_BERRY_WRONG_INPUT and go to step 1. .
- If the user types skip, return a new Berry object with an empty string for the berryName and 0 for both the patienceInc and speedDec.
- Call useBerry to determine whether the Berry exists in the backpack.
- If they do not have that berry in their backpack print You don't have any [Berry type] left!" and go to step 1.
- If they do, return the Berry object from your useBerry method call.
You can test this method interactively once you have the complete startYourJourney method working. There are no required tests to write here.
public static Pokeball getUserPokeball(Scanner myScanner)
This method should do the following:
- Prompt the user to type in what pokeball they would like to use by using the prompt string in the PROMPT_MSG_POKEBALL variable.
- If the Pokeball they have entered is not one of the Pokeballs we recognize, print out PROMPT_MSG_POKEBALL_WRONG_INPUT go to step 1.
- Call useBall to determine whether the Pokeball exists in the backpack.
- If they do not have that pokeball in their backpack print You don't have any [PokeBall type] left!" and go to step 1.
- If they do, return the PokeBall object from your useBall method call.
You can test this method interactively once you have the complete startYourJourney method working. There are no required tests to write here
import java.util.Scanner; import java.util.ArrayList; public class PokemonGame { * Defined variables to use in the game * Do not modify any of these. private static String[] pokeballNames = {"pokeball", "superball", "ultraball"}; private static int[] pokeballPerformance = {0, 10, 30}; private static String[] berryNames = {"Razz Berry", "Nanap Berry", "Golden Razz Berry"}; private static final int RAZZ_BERRY_PATIENCE_INC = 10; private static final int RAZZ_BERRY_SPEED_DEC = 0; private static final int NANAP_BERRY_PATIENCE_INC = 0; private static final int NANAP_BERRY_SPEED_DEC = 10; private static final int GOLDEN_RAZZ_BERRY_PATIENCE_INC = 30; private static final int GOLDEN_RAZZ_BERRY_SPEED_DEC = 30; private static String[] pokemonNames = {"Pikachu", "Bulbasaur", "Charmander", "Squirtle", "Mew"}; private static string[] pokemonSounds = {"pikapika", "bulb", "char", "squir", "mew"}; private static String[] pokemon Types = {"electric", "grass", "fire", "water", "psychic"}; private static int[] pokemonPatienceStats = {60, 50, 50, 50, 15); private static int[] pokemon SpeedStats = {25, 5, 20, 10, 50}; //the amount of patience the WildPokemon decreases on escape from a pokeball private static final int PATIENCE_DEC_EACH_ESCAPE = 5; private static final String PROMPT_MSG_START = "You will encounter different pokemons. In" + "You can throw different poke balls to catch them. In" "You can use Razz Berry or Golden Razz Berry to increase the catch rate. " + "You can use Nanap Berry to make the ball hit more easily. " + "Up to one berry per throw. Use the berry before your ball throw. "; private static final String PROMPT_MSG_BERRY = "Which berry do you want to use?" "Type skip if you are confident." 11 + + "(Razz Berry, Nanap Berry, Golden Razz Berry, skip)"; private static final String PROMPT_MSG_BERRY_WRONG_INPUT = "Your berry input was not recognized. "Choose one from the following four options: "Razz Berry, Nanap Berry, Golden Razz Berry, skip"; private static final String PROMPT_MSG_POKEBALL = "Which pokeball do you want to use? (pokeball, superball, ultraball)"; private static final String PROMPT_MSG_POKEBALL_WRONG_INPUT = "Your pokeball input was not recognized. "Choose one from the following four options: " + "pokeball, superball, ultraball"; private static final String PROMPT_MSG_CHECK_CAUGHT_POKEMONS = "Now let's check who're your pals now! "; + * These are the number of Berries and Pokeballs the user starts with You can change them if you want private static final int START_BERRY_COUNT = 2; private static final int START_POKEBALL_COUNT = 4; private static Backpack myBackpack; private static Pokedex myPokedex; get a Berry from the user, as defined in the assignment pdf @param myScanner: reference to where user input will come from @return : a Berry object that the user will use later on side effects: removes a berry from the backpack, if a user uses one. If so, it should also decrement the appropriate berry count. */ public static Berry getUserBerry(Scanner myScanner){ // TODO return null; } get a Pokeball from the user, as defined in the assignment pdf @param myScanner: reference to where user input will come from * @return a Pokeball object that the user will use later on * side effects: removes a Pokeball from the backpack. Decrement the appropriate pokeball count. public static Pokeball getUserPokeball(Scanner myscanner){ // TODO return null; ; } public static void startYour Journey) { ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started