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

 

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

Write a method that works like a vending machine. You are given a single string that lists a bunch of items available in a vending machine, separated by commas. After each comma there will always be a single space before the next item name starts. There will never be a space before the first item name or after the last one. Items are listed in order of their item number, with the first item being item #1. You also pass 'location' into the method, which indicates which location the item you want is in. Return the name of the item at that location. If 'location' is not a valid location number, return "ERROR". Look at the test data for examples. The only string methods you are allowed to use are .length, .charAt, .substring, .equals, and .compareTo. You are not allowed to use arrays, Maps, Lists, or ArrayLists.


quiz2022_03_23_HL_vendingMachine("a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z", 26) → "z"
quiz2022_03_23_HL_vendingMachine("a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z", 2) → "b"
quiz2022_03_23_HL_vendingMachine("a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z", 27) → "ERROR"

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

public String quiz2022_03_23_HL_vendingMachine(String items, int location) { }

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: 240

Copyright Nick Parlante 2017 - privacy