Is there a data structure like a class that doesn't need to be defined as a class in it's own file?

Is there a data structure like a class that doesn't need to be defined as a class in it's own file?

I am new to java, and I am trying to make a complex program with ArrayLists of objects. Within the classes of these objects, I would like to categorize my variables to better organize my program and to make ArrayLists easier. For example, I want to create the class Equipment which includes such factors as Attack, Durability, Charge, etc. I want to make a variable number of Charges, so normally I would make ArrayLists of each factor: chargename, charge, chargemax, etc. and simply add one to each factor every time I add another charge. However, I recall once seeing a data structure that one could create like a class without having to make a whole new file to define it, so I could simply make one ArrayList that included each variable I need. Does such a data structure exist, as I may be mistaken and cannot find any traces of this online, and how does it function exactly, as I recall it is defined upon creation with a block where variables are declared?

View Answers

May 3, 2012 at 12:25 PM

import java.util.*;
class Equipment 
{
    String attack;
    double durability;
    double charge;

      Equipment(String attack,double durability,double charge){
          this.attack=attack;
          this.durability=durability;
          this.charge=charge;
      }
      public String getAttack(){
          return attack;
      }

       public double getDurability(){
          return durability;
      }

       public double getCharge(){
          return charge;
      }

    public static void main(String[] args) 
    {
        ArrayList<Equipment> list=new ArrayList<Equipment>();
        list.add(new Equipment("A",2,1000));
        list.add(new Equipment("B",4,2000));

        for(Equipment e: list){
        System.out.println(e.getAttack()+"\t"+e.getDurability()+"\t"+e.getCharge());
        }
    }
}









Related Tutorials/Questions & Answers:
Is there a data structure like a class that doesn't need to be defined as a class in it's own file?
class with in its own objects?
Advertisements
user defined date class
user defined date class
USER DEFINED CLASS
compiling .class files
user defined subclass of throwable class - Java Beginners
Class files for Jfreechart - JSP-Servlet
Class
class
Can a abstract class be defined without any abstract methods?
How do I decompile Java class files?
class
Java Nested Class
Using a user defined non-packaged servlet class in jsp. - JSP-Servlet
python for data science cognitive class
Java writer class
Class in Java
Why we need reload application after class change?
PHP Class Object
Use of Local Inner class
ModuleNotFoundError: No module named 'data-class-detection'
How to convert many class files into one exe file?
How to convert many class files into one exe file?
inner class
Class
Super class of an Exception class
objective c extending a class with a class
objective c extending a class with a class
need help for writting code in struts action class for check boxes and radio buttons - Struts
Unable to get data from class - Development process
Inner class
Explain final class, abstract class and super class.
abstract class
Nested class
Java class in JSP
class ai
Using Abstract Class
Wrapper Class
Class Loader
Class Loader
Sending large data to Action Class error. Struts code - Struts
tensorflow class
class distance
class name
Abstract Class in Java
file class
which class is super class to all classes
class loaders
class file

Ads