Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

3. Define the roles individuals play in a group

Answered: 1 week ago