id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > fruitSpoiled
prev  |  next  |  chance

Each kind of fruit has a "shelf-life" which indicates how many days it takes the fruit to spoil. Fruit with a shelf-life of 6 days is good for 6 days, but will be considered spoiled on the 7th day. Write a method that accepts two arrays of positive integers with the same length. The first array, maxAgeFruit, contains an integer for each type of fruit indicating the maximum number of days the fruit can be on hand before it spoils. The second array, actualAgeFruit, indicates how many days old the corrisponding fruit actually is in a fruit basket. This method checkes to see if ANY of the fruit has spoiled in the basket. Return true if ANY of the fruit has spoiled. Return false if ALL of the fruit is still good. For example, in the call: fruitSpoiled({4,6,7},{3,6,2}) The 4 indicates that the first type of fruit is good for 4 days. The 3 indicates that this type of fruit is actually only 3 days old right now, so it is still good. The sixes indicate that the second kind of fruit is good for 6 days and the actual fruit of this type that is in the basket is currently 6 days old. This fruit will not be good tomorrow, but it is still good today. The last type of fruit is good for 7 days, but that type of fruit in our basket is only 2 days old, so it is also still good. We will return false, indicating that all the fruit in the basket is still good.


fruitSpoiled([4, 11, 12, 3, 6, 10], [3, 11, 8, 0, 6, 9]) → false
fruitSpoiled([6, 12, 14, 3, 15], [5, 2, 1, 1, 16]) → true
fruitSpoiled([4, 4, 4, 4, 4], [4, 3, 4, 1, 2]) → false

...Save, Compile, Run (ctrl-enter)

public boolean fruitSpoiled(int[] maxAgeFruit, int[] actualAgeFruit) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 210

Copyright Nick Parlante 2017 - privacy