SlideShare a Scribd company logo
ArrayListOfObjects
Assignment 4:
100 points
due Thurs, Feb 23rd.
Adapt your ArrayOfPokemon code from assignment 2 to use the new Pokemon objects.
When adding a Pokemon, instead of making the user enter all the information, make a menu for
them to pick from the nine (or more) implemented species: (Bulbasaur, Ivysaur, Venusaur,
Charmander, Charmaleon, Charizard, Squirtle, Wartortle, Blastoise).The only thing the user must
choose is the species of Pokemon and if it gets a name.
If they want a name, then the program should ask them to enter one.
Then call the constructor for the chosen Pokemon. For example: Pokemon p = new Bulbasaur();
or Pokemon p = new Squirtle(sName);
Change the Array from assignment 2 to a Java API ArrayList.
For examples on using an ArrayList, see the uploaded sample code ArrayListDemo.java and
slide 40 of ICS211_Lecture09_ListsAndContainers.pdf on Laulima -> Resources -> Week 5.
Also see the Java API website for ArrayList for available methods.
The allowed number of stored Pokemon should still be limited to 6. Don't let the ArrayList keep
growing though it can!
Assignment 2 code is here,Please help me change it to match Assignment 4's requirement.
This is the Pokemon.java code.import java.util.*; //scannerpublic class PokeArray{static final int
SIZE = 6;public static void main(String[] args){Scanner userIn = new
Scanner(System.in);String inString = new String("");boolean endLoop = false;Pokemon[]
arrPoke = new Pokemon[SIZE];int nextIndex = 0; //points to index for next insert//loop until
stopping condition is givenwhile(endLoop != true){//menu textSystem.out.println("Please enter
the number of your choice:");System.out.println("1. Add a Pokemon");System.out.println("2.
Print all Pokemon");System.out.println("0. Exit the program");System.out.print("What
would you like to do? ");//read in from user as a String -- much less errors can happen!inString
= userIn.nextLine();//take off any spaces on the stringinString = inString.trim();//just switch on
the String no need to convert to intswitch(inString){case "0": endLoop =
true;System.out.println("Good bye!");break;case "1": //do stuff to make a new
PokemonarrPoke[nextIndex] = PokeArray.makePokemon();nextIndex = (nextIndex + 1)%
SIZE; //makes value run from 0-5 alwaysbreak;case "2": //print out all the
PokemonPokeArray.printArray(arrPoke);break;default: //not a valid menu
entrySystem.out.println(" ****Invalid menu choice.**** Please enter a 0, 1, or 2
");break;}}}//close main method/** makePokemon asks user for data for a new Pokemon
object and instantiates it** @return a Pokemon to insert into the array*/public static Pokemon
makePokemon(){Scanner userIn = new Scanner(System.in);Pokemon newPoke;//Data for new
Pokemon constructorString inName = new String("");String inNick = new String("");String
inNum = new String("");//have to convert to an intString inType1 = new String("");String
inType2 = new String("");int iNum = 0;boolean dataGood = false;//keep taking input until user
enters valid inputwhile(dataGood == false){//this can be used later when Pokemon exception is
made tootry{System.out.println("Enter the Pokemon's name:");inName =
userIn.nextLine();inName = inName.trim();System.out.println("Enter a nickname, or just enter
if none:");inNick = userIn.nextLine();inNick = inNick.trim();System.out.println("Enter the
Pokemon's number:");inNum = userIn.nextLine();inNum = inNum.trim();iNum =
Integer.parseInt(inNum); //parse into an intSystem.out.println("Enter the Pokemon's
type:");inType1 = userIn.nextLine();inType1 = inType1.trim();System.out.println("Enter the
Pokemon's second type, if none just enter:");inType2 = userIn.nextLine();inType2 =
inType2.trim();dataGood = true;}catch(NumberFormatException nfe){System.out.println("You
didn't enter a valid number, try again");}}if(inNick.length() > 0){//call 5 parameter
constructornewPoke = new Pokemon(inName, inNick, iNum, inType1, inType2);}else{//call
constructor without nicknamenewPoke = new Pokemon(inName, iNum, inType1,
inType2);}return newPoke;}/** printArray prints array of Pokemon* @param pArray an array
of Pokemon Objects*/public static void printArray(Pokemon[] pArray){for(int i = 0; i < SIZE;
i++){if(pArray[i] != null){//don't print the indicies that are not
filledSystem.out.println("Pokemon "+ i + ": ");
System.out.println(pArray[i].toString());}}}//end printArray method}
Solution
/*The main difference between Assignment2 and Assignment4 is implementation of ArrayList
and Inheritance*/
import java.util.*; //scanner
public class PokeArray{
static final int SIZE = 6;
public static void main(String[] args){
Scanner userIn = new Scanner(System.in);
String inString = new String("");
boolean endLoop = false;
ArrayList pokeList=new ArrayList(SIZE);
//loop until stopping condition is given
while(endLoop != true){
//menu text
System.out.println("Please enter the number of your choice:");
System.out.println("1. Add a Pokemon");
System.out.println("2. Print all Pokemon");
System.out.println("0. Exit the program");
System.out.print("What would you like to do? ");
//read in from user as a String -- much less errors can happen!
inString = userIn.nextLine();
//take off any spaces on the string
inString = inString.trim();
//just switch on the String no need to convert to int
switch(inString){
case "0": endLoop = true;
System.out.println("Good bye!");
break;
case "1": //do stuff to make a new Pokemon
pokeList.add(PokeArray.makePokemon());
break;
case "2": //print out all the Pokemon
PokeArray.printArray(pokeList);
break;
default: //not a valid menu entry
System.out.println(" ****Invalid menu choice.**** Please enter a 0, 1, or 2 ");
break;
}
}
}//close main method
/*
* makePokemon asks user for data for a new Pokemon object and instantiates it
*
* @return a Pokemon to insert into the array
*/
public static Pokemon makePokemon(){
Scanner userIn = new Scanner(System.in);
Pokemon newPoke;
//Data for new Pokemon constructor
String inName = new String("");
String inNick = new String("");
int iNum = 0;
boolean dataGood = false;
//keep taking input until user enters valid input
//this can be used later when Pokemon exception is made too
try{
System.out.println("Enter the Pokemon's name:");
inName = userIn.nextLine();
inName = inName.trim();
System.out.println("Enter a nickname, or just enter if none:");
inNick = userIn.nextLine();
inNick = inNick.trim();
if(inNick.length() > 0){//call 5 parameter constructor
if(inName=="Bulbasaur")
newPoke = new Bulbasaur(inNick);
else if(inName=="Ivysaur")
newPoke = new Ivysaur(inNick);
else if(inName=="Venusaur")
newPoke = new Venusaur(inNick);
else if(inName=="Charmander")
newPoke = new Charmander(inNick);
else if(inName=="Charmaleon")
newPoke = new Charmaleon(inNick);
else if(inName=="Charizard")
newPoke = new Charizard(inNick);
else if(inName=="Squirtle")
newPoke = new Squirtle(inNick);
else if(inName=="Wartotle")
newPoke = new Wartotle(inNick);
else if(inName=="Blastoise")
newPoke = new Blastoise(inNick);
else throw new Exception ();
}
else{//call constructor without nickname
if(inName=="Bulbasaur")
newPoke = new Bulbasaur();
else if(inName=="Ivysaur")
newPoke = new Ivysaur();
else if(inName=="Venusaur")
newPoke = new Venusaur();
else if(inName=="Charmander")
newPoke = new Charmander();
else if(inName=="Charmaleon")
newPoke = new Charmaleon();
else if(inName=="Charizard")
newPoke = new Charizard();
else if(inName=="Squirtle")
newPoke = new Squirtle();
else if(inName=="Wartotle")
newPoke = new Wartotle();
else if(inName=="Blastoise")
newPoke = new Blastoise();
else throw new Exception ();
}
}catch(Exception e){
System.out.println("Pokemon not found!! ");
}
return newPoke;
}
/*
* printArray prints array of Pokemon
* @param pArray an array of Pokemon Objects
*/
public static void printArray(ArrayList pArray){
Iterator itr=pArray.iterator();
//traversing elements of ArrayList object
while(itr.hasNext()){
Pokemon st=(Pokemon)itr.next();
System.out.println(st.toString());
}
}//end printArray method
}
Pokemon.java
import java.util.Random;
import java.text.*; //imports decimal format
public class Pokemon{
/** instance variables **/
/* the actual kind of Pokemon */
private String name;
/* optional user-defined name */
private String nickName;
/* official Pokemon number for Pokedex */
private int number;
/* required type of Pokemon */
private String type1;
/* optional second type */
private String type2;
/* interally calculated Hit Points */
private int HP;
/* internally calculated Combat Power */
private int CP;
/* main constructor with nickName and two types
* @param name official Pokemon name for this kind of Pokemon
* @param nickName user-given name or name if none
* @param number official Pokedex number for this Pokemon
* @param type1 the Pokemon type
* @param type2 second type if Pokemon has one, otherwise empty string
*/
public Pokemon(String name, String nickName, int number, String type1, String type2){
this.name = name;
this.nickName = nickName;
this.type1 = type1;
this.type2 = type2;
this.number = number;
initHPCP();
}
/* constructor with no nickname and two types
* calls other constructor with nickName set to name
* @param name the official Pokemon name for this kind of Pokemon
* @param number official Pokedex number for this Pokemon
* @param type1 the Pokemon type
* @param type2 second type if Pokemon has one
*/
/*
* private method for initializing HP and CP from constructors
*/
private void initHPCP(){
//generate random numbers
Random randGen = new Random();
int newHP;
int newCP;
double multiplier;
double CPrangeMin = 1.00;
double CPrangeMax = 3.00;
newHP = randGen.nextInt(141) + 10; //integer between 10 and 150 inclusive
this.HP = newHP;
multiplier = CPrangeMin + (CPrangeMax - CPrangeMin)*randGen.nextDouble();
this.CP = (int)(newHP*multiplier);
}
/*
* Returns Pokemon information as a formatted String
* @return String representing Pokemon object data
*/
public String toString( ){
DecimalFormat df = new DecimalFormat("000");
String s="";
s = "Name: " + this.name + " ";
if(this.name.compareTo(this.nickName) != 0){
s = s + "Nickname: " + this.nickName + " ";
}
s = s + "Number: " + df.format(this.number) + " ";
s = s + "Type: " + this.type1;
if(this.type2.length() > 0){
s = s + " | " + this.type2;
}
s = s+ " ";
s = s + "HP: " + this.HP + " ";
s = s + "CP: " + this.CP + " ";
return s;
}
/*
* updates a Pokemon's HP and CP
* CP only updated if random multiplier increases it
* otherwise it stays the same
*/
public void powerUp(){
Random randGen = new Random();
int newHP;
double multiplier;
double CPrangeMin = 1.00;
double CPrangeMax = 3.00;
this.HP = (int)(this.HP + 1.15 + (0.2*this.HP));//set HP using formula
multiplier = CPrangeMin + (CPrangeMax - CPrangeMin)*randGen.nextDouble();
if((this.HP * multiplier) > this.CP){
this.CP = (int)(this.HP * multiplier);
}
}
/** Get Methods **/
public String getName(){
return this.name;
}
public String getNickName(){
return this.nickName;
}
public String getType1(){
return this.type1;
}
public String getType2(){
return this.type2;
}
public int getNumber(){
return this.number;
}
public int getHP(){
return this.HP;
}
public int getCP() {
return this.CP;
}
/*
* only Nickname is user-settable
* @param String the new nickname for this Pokemon
*/
public void setNickName(String newNickName){
this.nickName = newNickName;
}
}
public class Bulbasaur extends Pokemon{
Bulbasaur()
{
super("Bulbasaur","Bulbasaur",1,"Grass","");
}
Bulbasaur(String sName)
{
super("Bulbasaur",sName,1,"Grass","");
}
}
public class Ivysaur extends Pokemon{
Ivysaur()
{
super("Ivysaur","Ivysaur",2,"Grass","");
}
Ivysaur(String sName)
{
super("Ivysaur",sName,2,"Grass","");
}
}
public class Venusaur extends Pokemon{
Venusaur()
{
super("Venusaur","Venusaur",3,"Grass","");
}
Venusaur(String sName)
{
super("Venusaur",sName,3,"Grass","");
}
}
public class Charmander extends Pokemon{
Charmander()
{
super("Charmander","Charmander",4,"Fire","");
}
Charmander(String sName)
{
super("Charmander",sName,4,"Fire","");
}
}
public class Charmaleon extends Pokemon{
Charmaleon()
{
super("Charmaleon","Charmaleon",5,"Fire","");
}
Charmaleon(String sName)
{
super("Charmaleon",sName,5,"Fire","");
}
}
public class Charizard extends Pokemon{
Charizard()
{
super("Charizard","Charizard",6,"Fire","");
}
Charizard(String sName)
{
super("Charizard",sName,6,"Fire","");
}
}
public class Squirtle extends Pokemon{
Squirtle()
{
super("Squirtle","Squirtle",7,"Water","");
}
Squirtle(String sName)
{
super("Squirtle",sName,7,"Water","");
}
}
public class Wartotle extends Pokemon{
Wartotle()
{
super("Wartotle","Wartotle",8,"Water","");
}
Wartotle(String sName)
{
super("Wartotle",sName,8,"Water","");
}
}
public class Blastoise extends Pokemon{
Blastoise()
{
super("Blastoise","Blastoise",9,"Water","");
}
Blastoise(String sName)
{
super("Blastoise",sName,9,"Water","");
}
}

More Related Content

Similar to ArrayListOfObjectsAssignment 4100 pointsdue Thurs, Feb 23rd..pdf

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
shahidqamar17
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
Here are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdfHere are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdf
aggarwalshoppe14
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
arracollection
 
Tested on Eclipse and both class should be in same packageimport.pdf
Tested on Eclipse and both class should be in same packageimport.pdfTested on Eclipse and both class should be in same packageimport.pdf
Tested on Eclipse and both class should be in same packageimport.pdf
anuradhasilks
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
aggarwalshoppe14
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
fathimalinks
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
Ankitchhabra28
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
aggarwalshoppe14
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
raju957290
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
feelingspaldi
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
alanfhall8953
 
SeriesTester.classpathSeriesTester.project SeriesT.docx
SeriesTester.classpathSeriesTester.project  SeriesT.docxSeriesTester.classpathSeriesTester.project  SeriesT.docx
SeriesTester.classpathSeriesTester.project SeriesT.docx
lesleyryder69361
 

Similar to ArrayListOfObjectsAssignment 4100 pointsdue Thurs, Feb 23rd..pdf (20)

Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
question.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdfquestion.(player, entity ,field and base.java codes are given)Stop.pdf
question.(player, entity ,field and base.java codes are given)Stop.pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Here are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdfHere are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdf
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
 
Tested on Eclipse and both class should be in same packageimport.pdf
Tested on Eclipse and both class should be in same packageimport.pdfTested on Eclipse and both class should be in same packageimport.pdf
Tested on Eclipse and both class should be in same packageimport.pdf
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdfPLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
SeriesTester.classpathSeriesTester.project SeriesT.docx
SeriesTester.classpathSeriesTester.project  SeriesT.docxSeriesTester.classpathSeriesTester.project  SeriesT.docx
SeriesTester.classpathSeriesTester.project SeriesT.docx
 

More from fathimahardwareelect

Which one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdfWhich one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdf
fathimahardwareelect
 
Which of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdfWhich of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdf
fathimahardwareelect
 
What is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdfWhat is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdf
fathimahardwareelect
 
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdfWhat mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
fathimahardwareelect
 
using the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdfusing the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdf
fathimahardwareelect
 
True or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdfTrue or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdf
fathimahardwareelect
 
True or False. If H is a subgroup of the group G then H is one of it.pdf
True or False.  If H is a subgroup of the group G then H is one of it.pdfTrue or False.  If H is a subgroup of the group G then H is one of it.pdf
True or False. If H is a subgroup of the group G then H is one of it.pdf
fathimahardwareelect
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
fathimahardwareelect
 
Immunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdfImmunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdf
fathimahardwareelect
 
Question 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdfQuestion 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdf
fathimahardwareelect
 
Question 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdfQuestion 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdf
fathimahardwareelect
 
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdfQuestion 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
fathimahardwareelect
 
List and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdfList and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdf
fathimahardwareelect
 
Please write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdfPlease write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdf
fathimahardwareelect
 
Please help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdfPlease help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdf
fathimahardwareelect
 
Negligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdfNegligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdf
fathimahardwareelect
 
Incuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdfIncuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdf
fathimahardwareelect
 
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdfIdentify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
fathimahardwareelect
 
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdfHow many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
fathimahardwareelect
 
How does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdfHow does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdf
fathimahardwareelect
 

More from fathimahardwareelect (20)

Which one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdfWhich one of the following is NOT a social trend that is currently af.pdf
Which one of the following is NOT a social trend that is currently af.pdf
 
Which of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdfWhich of the following is normally a major activity of materials man.pdf
Which of the following is normally a major activity of materials man.pdf
 
What is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdfWhat is the role of civil society in promoting democracySolutio.pdf
What is the role of civil society in promoting democracySolutio.pdf
 
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdfWhat mechanism causes plant ion-uptake to acidify soilSolution.pdf
What mechanism causes plant ion-uptake to acidify soilSolution.pdf
 
using the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdfusing the knowledge about experiments that are related to plant g.pdf
using the knowledge about experiments that are related to plant g.pdf
 
True or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdfTrue or False Justify your answer.The concept of flooding is alwa.pdf
True or False Justify your answer.The concept of flooding is alwa.pdf
 
True or False. If H is a subgroup of the group G then H is one of it.pdf
True or False.  If H is a subgroup of the group G then H is one of it.pdfTrue or False.  If H is a subgroup of the group G then H is one of it.pdf
True or False. If H is a subgroup of the group G then H is one of it.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
Immunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdfImmunizations that the elderly need to receive on a yearly basis inc.pdf
Immunizations that the elderly need to receive on a yearly basis inc.pdf
 
Question 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdfQuestion 11 Scarcity means O people need to use marginal analysis to .pdf
Question 11 Scarcity means O people need to use marginal analysis to .pdf
 
Question 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdfQuestion 2 Sba Do you know something about the Statement Of Financ.pdf
Question 2 Sba Do you know something about the Statement Of Financ.pdf
 
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdfQuestion 1. give the CC++ code that defines an empty 5 element arra.pdf
Question 1. give the CC++ code that defines an empty 5 element arra.pdf
 
List and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdfList and explain all the components of company culture.Jackson, S..pdf
List and explain all the components of company culture.Jackson, S..pdf
 
Please write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdfPlease write 5-6 setences about each emotional intelligence capabili.pdf
Please write 5-6 setences about each emotional intelligence capabili.pdf
 
Please help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdfPlease help me find my errors. I am lost as I know what the problem.pdf
Please help me find my errors. I am lost as I know what the problem.pdf
 
Negligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdfNegligence and intentional torts are subject to civil litigation as .pdf
Negligence and intentional torts are subject to civil litigation as .pdf
 
Incuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdfIncuded within the major CPI basket groups are various government-cha.pdf
Incuded within the major CPI basket groups are various government-cha.pdf
 
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdfIdentify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
Identify major groupings within the Lophotrochozoa and Ecdy gg g soz.pdf
 
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdfHow many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
How many grams of solid NaCN have to be added to 1.4 L of water to d.pdf
 
How does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdfHow does Warhol add to the semiotic statement of the readymadeS.pdf
How does Warhol add to the semiotic statement of the readymadeS.pdf
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

ArrayListOfObjectsAssignment 4100 pointsdue Thurs, Feb 23rd..pdf

  • 1. ArrayListOfObjects Assignment 4: 100 points due Thurs, Feb 23rd. Adapt your ArrayOfPokemon code from assignment 2 to use the new Pokemon objects. When adding a Pokemon, instead of making the user enter all the information, make a menu for them to pick from the nine (or more) implemented species: (Bulbasaur, Ivysaur, Venusaur, Charmander, Charmaleon, Charizard, Squirtle, Wartortle, Blastoise).The only thing the user must choose is the species of Pokemon and if it gets a name. If they want a name, then the program should ask them to enter one. Then call the constructor for the chosen Pokemon. For example: Pokemon p = new Bulbasaur(); or Pokemon p = new Squirtle(sName); Change the Array from assignment 2 to a Java API ArrayList. For examples on using an ArrayList, see the uploaded sample code ArrayListDemo.java and slide 40 of ICS211_Lecture09_ListsAndContainers.pdf on Laulima -> Resources -> Week 5. Also see the Java API website for ArrayList for available methods. The allowed number of stored Pokemon should still be limited to 6. Don't let the ArrayList keep growing though it can! Assignment 2 code is here,Please help me change it to match Assignment 4's requirement. This is the Pokemon.java code.import java.util.*; //scannerpublic class PokeArray{static final int SIZE = 6;public static void main(String[] args){Scanner userIn = new Scanner(System.in);String inString = new String("");boolean endLoop = false;Pokemon[] arrPoke = new Pokemon[SIZE];int nextIndex = 0; //points to index for next insert//loop until stopping condition is givenwhile(endLoop != true){//menu textSystem.out.println("Please enter the number of your choice:");System.out.println("1. Add a Pokemon");System.out.println("2. Print all Pokemon");System.out.println("0. Exit the program");System.out.print("What would you like to do? ");//read in from user as a String -- much less errors can happen!inString = userIn.nextLine();//take off any spaces on the stringinString = inString.trim();//just switch on the String no need to convert to intswitch(inString){case "0": endLoop = true;System.out.println("Good bye!");break;case "1": //do stuff to make a new PokemonarrPoke[nextIndex] = PokeArray.makePokemon();nextIndex = (nextIndex + 1)% SIZE; //makes value run from 0-5 alwaysbreak;case "2": //print out all the PokemonPokeArray.printArray(arrPoke);break;default: //not a valid menu entrySystem.out.println(" ****Invalid menu choice.**** Please enter a 0, 1, or 2 ");break;}}}//close main method/** makePokemon asks user for data for a new Pokemon
  • 2. object and instantiates it** @return a Pokemon to insert into the array*/public static Pokemon makePokemon(){Scanner userIn = new Scanner(System.in);Pokemon newPoke;//Data for new Pokemon constructorString inName = new String("");String inNick = new String("");String inNum = new String("");//have to convert to an intString inType1 = new String("");String inType2 = new String("");int iNum = 0;boolean dataGood = false;//keep taking input until user enters valid inputwhile(dataGood == false){//this can be used later when Pokemon exception is made tootry{System.out.println("Enter the Pokemon's name:");inName = userIn.nextLine();inName = inName.trim();System.out.println("Enter a nickname, or just enter if none:");inNick = userIn.nextLine();inNick = inNick.trim();System.out.println("Enter the Pokemon's number:");inNum = userIn.nextLine();inNum = inNum.trim();iNum = Integer.parseInt(inNum); //parse into an intSystem.out.println("Enter the Pokemon's type:");inType1 = userIn.nextLine();inType1 = inType1.trim();System.out.println("Enter the Pokemon's second type, if none just enter:");inType2 = userIn.nextLine();inType2 = inType2.trim();dataGood = true;}catch(NumberFormatException nfe){System.out.println("You didn't enter a valid number, try again");}}if(inNick.length() > 0){//call 5 parameter constructornewPoke = new Pokemon(inName, inNick, iNum, inType1, inType2);}else{//call constructor without nicknamenewPoke = new Pokemon(inName, iNum, inType1, inType2);}return newPoke;}/** printArray prints array of Pokemon* @param pArray an array of Pokemon Objects*/public static void printArray(Pokemon[] pArray){for(int i = 0; i < SIZE; i++){if(pArray[i] != null){//don't print the indicies that are not filledSystem.out.println("Pokemon "+ i + ": "); System.out.println(pArray[i].toString());}}}//end printArray method} Solution /*The main difference between Assignment2 and Assignment4 is implementation of ArrayList and Inheritance*/ import java.util.*; //scanner public class PokeArray{ static final int SIZE = 6; public static void main(String[] args){
  • 3. Scanner userIn = new Scanner(System.in); String inString = new String(""); boolean endLoop = false; ArrayList pokeList=new ArrayList(SIZE); //loop until stopping condition is given while(endLoop != true){ //menu text System.out.println("Please enter the number of your choice:"); System.out.println("1. Add a Pokemon"); System.out.println("2. Print all Pokemon"); System.out.println("0. Exit the program"); System.out.print("What would you like to do? "); //read in from user as a String -- much less errors can happen! inString = userIn.nextLine(); //take off any spaces on the string inString = inString.trim(); //just switch on the String no need to convert to int switch(inString){ case "0": endLoop = true; System.out.println("Good bye!"); break; case "1": //do stuff to make a new Pokemon pokeList.add(PokeArray.makePokemon()); break; case "2": //print out all the Pokemon PokeArray.printArray(pokeList); break; default: //not a valid menu entry System.out.println(" ****Invalid menu choice.**** Please enter a 0, 1, or 2 "); break;
  • 4. } } }//close main method /* * makePokemon asks user for data for a new Pokemon object and instantiates it * * @return a Pokemon to insert into the array */ public static Pokemon makePokemon(){ Scanner userIn = new Scanner(System.in); Pokemon newPoke; //Data for new Pokemon constructor String inName = new String(""); String inNick = new String(""); int iNum = 0; boolean dataGood = false; //keep taking input until user enters valid input //this can be used later when Pokemon exception is made too try{ System.out.println("Enter the Pokemon's name:"); inName = userIn.nextLine(); inName = inName.trim(); System.out.println("Enter a nickname, or just enter if none:"); inNick = userIn.nextLine(); inNick = inNick.trim(); if(inNick.length() > 0){//call 5 parameter constructor if(inName=="Bulbasaur") newPoke = new Bulbasaur(inNick); else if(inName=="Ivysaur") newPoke = new Ivysaur(inNick); else if(inName=="Venusaur")
  • 5. newPoke = new Venusaur(inNick); else if(inName=="Charmander") newPoke = new Charmander(inNick); else if(inName=="Charmaleon") newPoke = new Charmaleon(inNick); else if(inName=="Charizard") newPoke = new Charizard(inNick); else if(inName=="Squirtle") newPoke = new Squirtle(inNick); else if(inName=="Wartotle") newPoke = new Wartotle(inNick); else if(inName=="Blastoise") newPoke = new Blastoise(inNick); else throw new Exception (); } else{//call constructor without nickname if(inName=="Bulbasaur") newPoke = new Bulbasaur(); else if(inName=="Ivysaur") newPoke = new Ivysaur(); else if(inName=="Venusaur") newPoke = new Venusaur(); else if(inName=="Charmander") newPoke = new Charmander(); else if(inName=="Charmaleon") newPoke = new Charmaleon(); else if(inName=="Charizard") newPoke = new Charizard(); else if(inName=="Squirtle") newPoke = new Squirtle(); else if(inName=="Wartotle") newPoke = new Wartotle(); else if(inName=="Blastoise") newPoke = new Blastoise(); else throw new Exception (); }
  • 6. }catch(Exception e){ System.out.println("Pokemon not found!! "); } return newPoke; } /* * printArray prints array of Pokemon * @param pArray an array of Pokemon Objects */ public static void printArray(ArrayList pArray){ Iterator itr=pArray.iterator(); //traversing elements of ArrayList object while(itr.hasNext()){ Pokemon st=(Pokemon)itr.next(); System.out.println(st.toString()); } }//end printArray method } Pokemon.java import java.util.Random; import java.text.*; //imports decimal format public class Pokemon{ /** instance variables **/ /* the actual kind of Pokemon */ private String name; /* optional user-defined name */ private String nickName; /* official Pokemon number for Pokedex */ private int number;
  • 7. /* required type of Pokemon */ private String type1; /* optional second type */ private String type2; /* interally calculated Hit Points */ private int HP; /* internally calculated Combat Power */ private int CP; /* main constructor with nickName and two types * @param name official Pokemon name for this kind of Pokemon * @param nickName user-given name or name if none * @param number official Pokedex number for this Pokemon * @param type1 the Pokemon type * @param type2 second type if Pokemon has one, otherwise empty string */ public Pokemon(String name, String nickName, int number, String type1, String type2){ this.name = name; this.nickName = nickName; this.type1 = type1; this.type2 = type2; this.number = number; initHPCP(); } /* constructor with no nickname and two types * calls other constructor with nickName set to name * @param name the official Pokemon name for this kind of Pokemon * @param number official Pokedex number for this Pokemon * @param type1 the Pokemon type * @param type2 second type if Pokemon has one */ /*
  • 8. * private method for initializing HP and CP from constructors */ private void initHPCP(){ //generate random numbers Random randGen = new Random(); int newHP; int newCP; double multiplier; double CPrangeMin = 1.00; double CPrangeMax = 3.00; newHP = randGen.nextInt(141) + 10; //integer between 10 and 150 inclusive this.HP = newHP; multiplier = CPrangeMin + (CPrangeMax - CPrangeMin)*randGen.nextDouble(); this.CP = (int)(newHP*multiplier); } /* * Returns Pokemon information as a formatted String * @return String representing Pokemon object data */ public String toString( ){ DecimalFormat df = new DecimalFormat("000"); String s=""; s = "Name: " + this.name + " "; if(this.name.compareTo(this.nickName) != 0){ s = s + "Nickname: " + this.nickName + " "; } s = s + "Number: " + df.format(this.number) + " "; s = s + "Type: " + this.type1; if(this.type2.length() > 0){ s = s + " | " + this.type2; } s = s+ " ";
  • 9. s = s + "HP: " + this.HP + " "; s = s + "CP: " + this.CP + " "; return s; } /* * updates a Pokemon's HP and CP * CP only updated if random multiplier increases it * otherwise it stays the same */ public void powerUp(){ Random randGen = new Random(); int newHP; double multiplier; double CPrangeMin = 1.00; double CPrangeMax = 3.00; this.HP = (int)(this.HP + 1.15 + (0.2*this.HP));//set HP using formula multiplier = CPrangeMin + (CPrangeMax - CPrangeMin)*randGen.nextDouble(); if((this.HP * multiplier) > this.CP){ this.CP = (int)(this.HP * multiplier); } } /** Get Methods **/ public String getName(){ return this.name; } public String getNickName(){ return this.nickName; } public String getType1(){ return this.type1; }
  • 10. public String getType2(){ return this.type2; } public int getNumber(){ return this.number; } public int getHP(){ return this.HP; } public int getCP() { return this.CP; } /* * only Nickname is user-settable * @param String the new nickname for this Pokemon */ public void setNickName(String newNickName){ this.nickName = newNickName; } } public class Bulbasaur extends Pokemon{ Bulbasaur() { super("Bulbasaur","Bulbasaur",1,"Grass",""); } Bulbasaur(String sName) { super("Bulbasaur",sName,1,"Grass",""); } } public class Ivysaur extends Pokemon{ Ivysaur() { super("Ivysaur","Ivysaur",2,"Grass",""); }
  • 11. Ivysaur(String sName) { super("Ivysaur",sName,2,"Grass",""); } } public class Venusaur extends Pokemon{ Venusaur() { super("Venusaur","Venusaur",3,"Grass",""); } Venusaur(String sName) { super("Venusaur",sName,3,"Grass",""); } } public class Charmander extends Pokemon{ Charmander() { super("Charmander","Charmander",4,"Fire",""); } Charmander(String sName) { super("Charmander",sName,4,"Fire",""); } } public class Charmaleon extends Pokemon{ Charmaleon() { super("Charmaleon","Charmaleon",5,"Fire",""); } Charmaleon(String sName) { super("Charmaleon",sName,5,"Fire",""); } } public class Charizard extends Pokemon{
  • 12. Charizard() { super("Charizard","Charizard",6,"Fire",""); } Charizard(String sName) { super("Charizard",sName,6,"Fire",""); } } public class Squirtle extends Pokemon{ Squirtle() { super("Squirtle","Squirtle",7,"Water",""); } Squirtle(String sName) { super("Squirtle",sName,7,"Water",""); } } public class Wartotle extends Pokemon{ Wartotle() { super("Wartotle","Wartotle",8,"Water",""); } Wartotle(String sName) { super("Wartotle",sName,8,"Water",""); } } public class Blastoise extends Pokemon{ Blastoise() { super("Blastoise","Blastoise",9,"Water",""); } Blastoise(String sName) {