Question: String[] arr = new String[3]; public static void main(String args[]){ classname n = new classname(); arr[0] = bob; arr[1] = Lisa; arr[2] = Rob; n.applesEaten(bob,5)

String[] arr = new String[3]; public static void main(String args[]){ classname n = new classname(); arr[0] = "bob"; arr[1] = "Lisa"; arr[2] = "Rob"; n.applesEaten(bob,5) n.applesEaten(bob,9) n.applesEaten(bob,5) n.applesEaten(Lisa,3) n.applesEaten(Lisa,5) n.applesEaten(Rob,7) } public int applesEaten(String name, int apples){ //because this method was called 3 times for bob and bob ate 5+9+5 apples, //this method should return 19. and 8 for Lisa, 7 for Rob. }

I tried using a single for-loop that traverses through arr array, however, the loop adds everyone's apple, how do I make it so that this method can return the different amount of apples for different names? (Only with ARRAY)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!