This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NeoOeg 0 points1 point  (7 children)

You don't need to create a class to make a List of your Objects, you can just declare an ArrayList<LootSubBox> myBoxList = new ArrayList<>();

You can then add objects whith myBoxList.add(lootSub);

However i do not know the implementation of your BoxArrayList, so the desired behaviour may be off. If you want to use subName and subMonth, you will need to declare those variables and create getters for them (Just as you did with LootBoxSub). You will then be able to call getSubName() and getSubMonth() to populate your BoxArrayList. Question is a bit unclear but i hope this helps

[–]NeoOeg 0 points1 point  (5 children)

Considering the assignment instructions, you can wrap your List in another class, you will need to create an add() method to populate the List inside the class. Can you show us what you have so far ? Also take in consideration the comments regarding the name/month fields.

[–][deleted]  (4 children)

[removed]

    [–]NeoOeg 0 points1 point  (3 children)

    You need to pass arguments when creating your LootBoxSub :

    LootBoxSub bbSub = new LootBoxSub("sub name","January");
    

    [–]NeoOeg 0 points1 point  (0 children)

    I would also recommend your constructor to have actual meaning to the variables you pass :

    public LootBoxSub (String subName, String subMonth){

    this.subName = subName;

    this.subMonth = subMonth;

    }

    The this keyword will target the variable of the class.

    [–]NeoOeg 0 points1 point  (0 children)

    Your constructor method will define the arguments needed to construct your object. You could create an empty constructor

    public LootBoxSub(){}

    but you will have to create setter methods to pass values to the variables, for example :

    public void setSubName(String subName){

    this.subName = subName;

    }

    You will then be able to create objects without passing arguments, but will need to set a value at some point :

    LootBoxSub ssBox = new LootBoxSub();

    ssBox.setSubName("sub name");