Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Create an interactive program that manages an array of your Assignment 1 Pokemon objects There should be a main method that has an interactive text-based

Create an interactive program that manages an array of your Assignment 1 Pokemon objects

There should be a main method that has an interactive text-based menu that allows the user to choose to add Pokemon to their list (a regular indexed array of Pokemon, Pokemon[]) or print their list (array) of Pokemon

The array should be declared and maintained in the main method.

There should be two static methods (described below).

One will interact with the user to make a Pokemon object.

The other method will take in an array of Pokemon as a parameter and print it to the screen.

Main Method

Write a driver (main method) program for your Pokemon class called PokeArray.java

The array should be declared in the main method. NOT like the ArraysAndMethods.java example code

Menu

Please see the sample code included in this repo: MenuExample.java

So many students get stuck on the menu, I've made you one to work from. The important part of this assignment is working with the array of objects and static methods.

The program should display the following interactive menu to the user:

1. Add a Pokemon 2. Print all Pokemon 0. Exit the program What would you like to do? _ 

The menu should keep on looping until the user enters 0.

If the user enters a 1:

There should be a call to a static method named makePokemon that handles making a new Pokemon object (see makePokemon section).

The Pokemon returned from the makePokemon method should be stored in the next available array index (see Array Management section).

If the user enters a 2:

There should be a call to a static method named printArray (see printArray section).

Menu input must be validated. If an invalid entry is given, the program should not crash! A suitable error message should be displayed followed by the menu again. The provided sample code does this already!

makePokemon static method

This method should take no parameters and should return a single Pokemon object

Method header example:

public static Pokemon makePokemon() {

Inside this method, a set of questions should be asked in order to gather the data needed construct a new Pokemon Object such as:

What is the Pokemon's species?

Does the Pokemon have a name Y/N?

(if Y) What is the Pokemon's name?

(if N) Send an empty String as the name

What is the Pokemon's Pokedex number?

What is the Pokemon's Type?

What is the Pokemon's Second Type? (if it has one)

Note to those who did not take ICS 111 from me: I strongly suggest using the Scanner.nextLine() method to read in everything, then parse the number into an int.

The Scanner class methods: nextInt(), next(), and nextDouble() cause problems because they leave a newline (from the user pressing enter) in the read buffer. If you use these, you must make an second call to Scanner.next() or they don't work correctly. If nextInt() or nextDouble() are used and they don't work correctly, I will take off points.

Assume the user's input will be correct Pokemon species/name/number/etc for now.

We're going to work on Exceptions in a later assignment.

However, your program must not crash if the user doesn't enter an integer for the number. You must convert the user-entered number into an int correctly and handle re-asking for it within the makePokemon method if a non-number is entered (the constructor will not accept a string).

If the Pokemon does not have a second type, send an empty string as the type2 parameter.

When all the required arguments are gotten from the user, a Pokemon object should be constructed and returned:

return new Pokemon(species, name, number, type1, type2);

Array Management

The array of Pokemon objects should be declared and maintained in the main method.

This array must be of size 6.

Declare size as a static constant at the top of the code.

The array should only keep the last 6 Pokemon entered.

If the user enters a 7th Pokemon, the first Pokemon that was stored (array[0]) should be overwritten by the 7th (new) one.

If a 8th Pokemon is added, the second one that was entered (array[1]) should be overwritten by the new (8th) Pokemon, and so on.

Hint: use the mod % operator to calculate the next index to be used.

The user should be able to keep entering new Pokemon forever, but the array should only store the 6 newest.

printArray static method

This method should take the array of Pokemon in as a parameter (see ArraysAndMethods.java on Laulima Resources under Week 3)

Method header example:

public static void printArray(Pokemon[] pArray) {

It should loop through the array

At each filled index it should print the word "Pokemon" followed by the array index + 1. Then there should be a newline followed by the String returned from a call that Pokemon's toString() method

Unfilled indices should not print anything

You should check for this by checking to see if the array index is != null

output example:

Pokemon 1: Species: Bulbasaur Number: 001 Type: Grass | Poison HP: 145 CP: 425 Pokemon 2: Species: Squirtle Name: Sammy Number: 007 Type: Water HP: 21 CP: 52 

Testing

There is no easy way to do jUnit testing for methods that take user input (like makePokemon), so we're not going to use jUnit for this assignment. Please use CheckStyle to make sure your indenting and commenting is in the correct format.

Your program should not be crashable. I and your peer reviewer will thoroughly test to make sure incorrect inputs do not cause a program crash. Make sure that your program has understandable error messages if the input is incorrect.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions