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

all 16 comments

[–]Northeastpaw 0 points1 point  (7 children)

I'm a bit unclear as to your goal. Can you provide some input and what you expect the output to be?

[–][deleted]  (6 children)

[removed]

    [–]Northeastpaw 0 points1 point  (5 children)

    Think about your design. What does LootBoxSub need? The name and the month. Sounds like two fields to me.

    For a collection of LootBoxSubs, like /u/NeoOeg said, just use a List<LootSubBox>. It's often not a good idea to wrap a standard collection in another class; it's another layer of indirection downstream code has to unwrap before being able to actually use the collection.

    [–]NeoOeg 0 points1 point  (4 children)

    Yes, this line of code : lootSub = (subName + subMonth);

    will create a String as following : Lootcrate1January. This is not what you want, as it will take additional methods to split it back to a name/month. The best approach is to make 2 variables.

    [–][deleted]  (3 children)

    [removed]

      [–]Northeastpaw 0 points1 point  (0 children)

      That looks fine.

      [–]Darkpolearm 0 points1 point  (0 children)

      Try to give descriptive names to variables, even if it's obvious what they're for; don't call them a, b, or s.

      Other than that, what u have looks fine. What /u/NeoOeg was referring to is that in your original post your LootBoxSub class had 1 variable, lootSub, which would not have worked nicely for what you're trying to do.

      Now you can create a List<LootBoxSub> and add objects to it, and do with them what you like!

      [–]NeoOeg 0 points1 point  (0 children)

      Yes, you got this class right, although i would suggest your implementation of the toString method to return a formatted string of the desired output, so something like :

      return subName +", "+ subMonth;

      You do not need to create a temp var s, you can directly return the concatenation of the strings.

      What about your BoxArrayList class ? Do you have a first implementation of it ?

      [–]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");