Using "this" operator but method does not reassign values

Program sets strings to a random index of the array list. The issue is that when the randomizeSlotsStrings method is called, it does not reassign the string values, it just returns null.

private String slot1,slot2,slot3;  public static ArrayList<String> slots = new ArrayList<String>(5);  public static void initSlots(){         slots.add("BAR");         slots.add("WILD");         slots.add("7RED");         slots.add("7WHITE");         slots.add("CHERRY"); }  public String getSlots(){         this.slot1 = slot1;         this.slot2 = slot2;         this.slot3 = slot3;          return slot1 + slot2 + slot3; }  public void randomizeSlotStrings() {     slot1 =  slots.get((int)Math.random(5));     slot2 =  slots.get((int)Math.random(5));     slot3 =  slots.get((int)Math.random(5)); }   public static void main(){    initSlots();    randomizeSlots();    system.out.println(getSlot()); } 

Expected output examples> "BAR","WILD","7RED" Actual output > null, null, null

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.