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

 

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

Write a method that accepts a string of 10 1's and 0's. The 1's indicate that a pin remains, while the 0's indicate that a pin has been knocked down. Each character in the string corresponds to the location of a bowling pin. The pins are numbered from 1 to 10 with the first character representing pin 1 which is the pin closest to the bowler. Each row of pins has one more pin than the row before it, so row two contains two pins numbered 2 and 3. Row three contains three pins numbered 4, 5, and 6. The last row has pins numbered 7, 8, 9, and 10. The pin numbers correspond to the character number in the string starting with pin number 1. Note that pins 7 and 10 are in the opposite back corners of the pin configuration, while pin 1 is closest to the bowler. In our special version of bowling, if you bowl and leave only these three pins (pins 1, 7, and 10) we will call it a "triad" and award it a score of 30. If you knock down all the pins on the first try, it is called a strike. Your goal is to translate the string of 1's and 0's in these three possible statements: "Strike!" if no pins remain standing. "triad" if only pins 1, 7, and 10 remain standing. "go for the spare, # remaining." in all other cases, where # is replaced by the number of pins that remain standing. A spare is when you knock down all the remaining pins on your second shot.


pinny("0010101011") → "go for the spare, 5 remaining."
pinny("0000000000") → "Strike!"
pinny("0000000101") → "go for the spare, 2 remaining."

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

public String pinny(String pins) { }

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

Copyright Nick Parlante 2017 - privacy