Problem Statement
You have been hired by a gaming company that makes pinball machines. They are currently making a simple and small pinball machine designed for kids' home use. As the company's newest Pinball Engineer, your job is to make sure that the right score is displayed on the machine. Players can get points by hitting bumpers, moving over rollers, or executing a tricky sequence which gets them the jackpot or double jackpot.
Write a function which returns the correct number of points the player has earned so far. The input string, events, consists of characters indicating what has happened:
- 'B' indicates the ball hit a large bumper. This is worth 1,000 points.
- 'b' indicates the ball hit a small bumper. This is worth 250 points.
- 'R' indicates the ball went over a roller. This is worth a measly 50 points.
- 'J' means the player got the jackpot and earns 10,000 points.
- 'D' means the player got the double jackpot and gets 20,000 points.
Definition
- Class:
- Scoreboard
- Method:
- getScore
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getScore(String events)
- (be sure your method is public)
Constraints
- Events will have a length from 0 to 50 characters, inclusive.
- Events will have no characters other than 'B', 'b', 'R', 'J', and 'D'.
Examples
"BBB"
Returns: 3000
Three large bumpers, at 1000 points each, is worth 3000 points.
"BbRJD"
Returns: 31300
One of each scoring: B = 1000, b = 250, R = 50, J = 10000, D = 20000 => Total = 31300
""
Returns: 0
Much sadness, as there was no score at all.
"JJRRBbD"
Returns: 41350
"bbRRBD"
Returns: 21600
"BbRJD"
Returns: 31300
"DDJJJbJRDDDBRbBBJbBRJJbDBRbDRBJBbbRBbRDDBDDJRBBb"
Returns: 323650
"DR"
Returns: 20050
"RbbBJJRbDD"
Returns: 61850
"JbDJBDDJBbbRJJRbBbBJJJRRDBRRRBJDBDbRJbDRBbbDbDJ"
Returns: 300950
"BRRDJBbDJbDBRRBBRb"
Returns: 86000
"JbDRJbJJRRRBDRBbBR"
Returns: 84050
"BDJRDbRDDJBBbBRDDBDDJBRDRBbDJRBBJDBR"
Returns: 281100
"D"
Returns: 20000
"BbRJDRbb"
Returns: 31850
"RRBbb"
Returns: 1600
"BBbDDJBRbRJDRRDBDBDJRbbJbbDBRBbJDD"
Returns: 239050
"BBBBRBJBbBRJJbbJBbRBJJJRJJDBBBDBRJJDJDRJDB"
Returns: 245300
"RDRb"
Returns: 20350
"BRbRbDBRRRRJBJBBbbBBRbDBDDbRJBJBRBDJDRJJRbRB"
Returns: 204350
"JJbBBbRbBbDRBRRRRDbDbbDJbBJ"
Returns: 127300
"RRbDJRBbBRRDBJbDBBJDBBBRbbbRJRJ"
Returns: 139900
"RDDJDBJRRbRDbbDJDBJBbJRbRDJRbJRJJJbBJJDBRBRJJ"
Returns: 308250
"BBDbJRRJRRDRJbBbbbJJDBRDDDbbJJBbJRRJJBJBBDbBRRDRDJ"
Returns: 311800
"BDJDDDJDRJbbBDbJDbJbRBRJJBDbRbDDRBRbRJJJBDJDDDJRDD"
Returns: 448400
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
Returns: 1000000
"JJJJ"
Returns: 40000