Can someone teach me how to write this Paragraph Entry as a boolean expression?
Note: I am a beginner Programmer but love the hobby and I'm wanting to get a degree in computer science so I'm not to experienced so if anyone has tips that may benefit me as a beginner that'd be awesome. But here is the question.
Chicago's Wrigley Field is a baseball field with a vine-covered wall 开发者_高级运维in the outfield, that has a railing above the wall. A ball that hits the wall and does not leave the playing field is sometimes still in play and sometimes a dou- ble according to the following rules: A ball striking the railing and rebounding onto the playing field is still in play. A ball that lodges in the screen that is attached to the bleacher wall is a double. A ball that lodges in vines on the bleacher wall is a double. A ball entering the vines on the bleacher wall and rebounding onto the playing field is still in play. A ball that hits the wall is ruled a double IF (condition), else the ball is still in play.
Rewrite this as a single Boolean condition of the form??
I almost clueless!
I don't want to solve the whole thing for you else you don't have a chance to learn, but let me help you get started.
Try to break it down into a flow chart that decides if the ball is a double or still in play. Each branch in the flowchart is a boolean condition.
A ball that hits the wall and does not leave the playing field is sometimes still in play and sometimes a dou- ble according to the following rules:
Break them down:
- A ball striking the railing and rebounding onto the playing field is still in play.
- A ball that lodges in the screen that is attached to the bleacher wall is a double.
- A ball that lodges in vines on the bleacher wall is a double.
- A ball entering the vines on the bleacher wall and rebounding onto the playing field is still in play.
- A ball that hits the wall is ruled a double IF (condition), else the ball is still in play.
Test each condition in sequence and accumulate the result in a single boolean variable.
Wrigley is known for its ivy covered brick outfield wall. So the single boolean condition is FALSE
Others have made good suggestions, another approach (depending on how you think) is to look at it from a natural language perspective. Your original problem statement is:
A ball striking the railing and rebounding onto the playing field is still in play. A ball that lodges in the screen that is attached to the bleacher wall is a double. A ball that lodges in vines on the bleacher wall is a double. A ball entering the vines on the bleacher wall and rebounding onto the playing field is still in play. A ball that hits the wall is ruled a double IF (condition), else the ball is still in play.
Begin looking at the final statement:
A ball that hits the wall is ruled a double IF (condition), else the ball is still in play.
So for the condition you need to answer "of the original problem statement, which say when the ball is ruled a double?" So extract the rules that say when it is a double:
A ball that lodges in the screen that is attached to the bleacher wall is a double. A ball that lodges in vines on the bleacher wall is a double.
So you can make the statement A ball is a double if
- it lodges in the screen that is attached to the bleacher wall
- it lodges in the vines on the bleacher wall
So we can answer the original question:
A ball is a double if it lodges in the screen that is attached to the bleacher wall or it lodges in the vines on the bleacher wall otherwise it is still in play
Note the bold words match constructs available in java (and any other programming language), where "otherwise" can be read else, so you can now translate the above sentence directly to a programming statement.
As you are trying to learn a suggestion is can you use the above approach to do the inverse as an exercise i.e. write a condition that tests if the ball is still in play, otherwise it is a double.
精彩评论