Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Rep Power

    Default Video Game Character ArrayList Help?

    Hey guys, so currently I have this ArrayList set up.
    I was wondering if there would be anyway to set up a prompt which asks the user to choose the element they would like to use, as you see the characters each have a unique element. After choosing which one, would there be a way to create a user input to change the default name that is currently there, or even just have no data in the name part of the object and just have the user input one.

    Also, Is there a way to use a search function such as to be something like "Search for ATTACK of 20 or more?".

    Thank you in advance and I would really appreciate your help <3

    package arraylistca;

    import java.util.ArrayList;
    import java.util.Scanner;

    public class ArrayListCa {

    public static void main(String args[]){

    Scanner input = new Scanner(;

    //Create objects of Hero class
    Hero s1 = new Hero("Damian", 1,50,50,"Light");
    Hero s2 = new Hero("Walter", 1,40,60,"Water");
    Hero s3 = new Hero("Nathan", 1,20,80,"Air");
    Hero s4 = new Hero("Bella", 1,90,10,"Fire");
    Hero s5 = new Hero("Tyson", 1,10,90,"Eath");
    Hero s6 = new Hero("Lucas", 1,50,50,"Darkness");
    Hero s7 = new Hero("Amelia", 1,100,0,"Aether");
    Hero s8 = new Hero("Seth", 1,0,100,"Time");

    //Create an ArrayList of objects Hero
    ArrayList<Hero> aListHeroes = new ArrayList<Hero>();

    //add Objects of Hero to ArrayList

    //display ArrayList objects
    System.out.println("Heroes Stats");
    for(Hero stats : aListHeroes){
    System.out.println("Name: " + stats.getName()
    + ", Level: " +stats.getLevel()
    + ", Attack: " +stats.getAttack()
    + ", Defense: " +stats.getDefense()
    + ", Element: " +stats.getElement());


    class Hero{

    String name;
    int level;
    int attack;
    int defense;
    String element;

    public Hero(String name, int level, int attack, int defense, String element){ = name;
    this.level = level;
    this.attack = attack;
    this.defense = defense;
    this.element = element;

    public String getName(){

    public int getLevel(){
    return this.level;

    public int getAttack(){
    return this.attack;

    public int getDefense(){
    return this.defense;

    public String getElement(){
    return this.element;

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Colorado Springs, CO
    Rep Power

    Default Re: Video Game Character ArrayList Help?

    In the Hero class you will need to create some new methods for doing what you want. For example a change hero class for which you will pass any values (the name) that you would like to change for that particular hero. You can also create your search for attack class where you would pass a value to seach for and create a loop checking all of your heroes for that specific attack. Hope this helps get you started.
    Sincerely, Joshua Green
    Please REP if I help :)

Similar Threads

  1. Passing ArrayList<Character> to a grid of JButtons
    By jumpgirl in forum New To Java
    Replies: 10
    Last Post: 03-18-2012, 01:12 PM
  2. Replies: 12
    Last Post: 07-07-2011, 08:49 PM
  3. Replies: 4
    Last Post: 06-02-2011, 10:15 PM
  4. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 12:36 PM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts