Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you add on to the following starter code to complete this task ( using Java ) ? You are tasked with writing a simple

Can you add on to the following starter code to complete this task (using Java)?
You are tasked with writing a simple Pokedex program that will get the information from a large list of pokemon stored in a file, save each pokemons information into pokemon objects within an ArrayList object.
Write a test/driver program that imports and processes the information from the pokemon CSV file. Additionally, write a simple, menu driven program that can display all pokemon, or find a specific pokemon by name.
To Do:
Design and implement a Pokemon class
Implement appropriate setters and getters
Implement the toString() method
Optional: implement an overloaded constructor
Starter Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class PokedexAssignment {
static ArrayList mypokedex = new ArrayList<>();
public static void main(String[] args){
// file reading review
// absolute/relative paths
String filepath = "pokedex.csv";
File pokedexFile = new File(filepath);
try {
Scanner fileinput = new Scanner(pokedexFile);
// throw away first line
fileinput.nextLine();
while(fileinput.hasNextLine()== true){
String lineInfo = fileinput.nextLine();
String[] lineInfoSplit = lineInfo.split(",");
/*
0:#
1: Name
2: Type 1
3: Type 2
4: Total
5: HP
6: Attack
7: Defense
8: Sp. Atk
9: Sp. Def
10: Speed
11: Generation
12: Legendary
*/
Pokemon tempPoke = new Pokemon();
tempPoke.setId(Integer.parseInt(lineInfoSplit[0]));
tempPoke.setName(lineInfoSplit[1]);
System.out.println(lineInfo);
mypokedex.add(tempPoke);
}
System.out.println("
Printing out the arraylist contents:");
System.out.println(mypokedex);
} catch (FileNotFoundException e){
System.out.println(e);
}
}
}
public class Pokemon {
private int id;
private String name;
public Pokemon(){
}
public Pokemon(int id, String name){
this.id = id;
this.name = name;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
@Override
public String toString(){
return "Pokemon{"+
"id="+ id +
", name='"+ name +'\''+
'}';
}
}

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

2.3 Define human resource ethics.

Answered: 1 week ago

Question

9 How can training be evaluated?

Answered: 1 week ago