Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please do the following in JAVA. Lab 8c [40 points]: A Teddy Bear Picnic This question involves a game with teddy bears. The game starts

Please do the following in JAVA.image text in transcribed

Lab 8c [40 points]: A Teddy Bear Picnic This question involves a game with teddy bears. The game starts when I give you some bears. You can then give back some bears, but you must follow these rules (where n is the number of bears that you have): If n is even, then you may give back exactly n/2 bears. If n is divisible by 3 or 4, then you may multiply the last two digits of n and give back this many bears. (By the way, the last digit of n is n%10, and the next-to-last digit is ((n%100)/10). If n is divisible by 5, then you may give back exactly 42 bears. 1. 2. 3. The goal of the game is to end up with EXACTLY 42 bears. For example, suppose that you start with 250 bears. Then you could make these moves: --Start with 250 bears -Since 250 is divisible by 5, you may ret eaving you with 208 bears ince 208 even, you may return half of the --S leaving you with 104 bears. -Since 104 is even, you may return half of the bears, leaving you with 52 bears. -Since 52 is divisible by 4, you may multiply the last two digits (re ulting in 10) and return these 10 bears. Thi leaves you with 42 bears -Y u have reached the goal! 13 Write a recursive method to meet this specification: public static bo lean bears (int n) possible to win value means that // Postcondition: A true return value means that it is // the bear game by starting with n bears. A false return // it is not possible to win the bear game by starting with n be a r 3 . / Examples: / bear (250) is true (as shown above) / bear (42) is true bear (84) is true / bear (53) is false /I bear (41) is false Hint: To test whether n is even, use the expression ((n % 2)-0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions