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

 

calculateCost


Write a method that iterates through an array of item names and updates the total cost. Pricing rules: Each "shirt" costs 5 Each "pants" costs 7 All other items cost 10 You should update a variable named cost.


calculateCost(["shirt", "shirt", "dress", "blanket", "pants", "shirt"]) → 42
calculateCost(["pants", "pants", "pants"]) → 21
calculateCost(["shirt", "pants", "hat"]) → 22

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

public int calculateCost(String[] items) { }

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

Copyright Nick Parlante 2017 - privacy