This question involves a game with teddy bears. The game starts when I give you some...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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): 1. If n is even, then you may give back exactly n/2 bears. 2. 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). 3. If n is divisible by 5, then you may give back exactly 42 bears. 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 return 42 of the bears, leaving you with 208 bears. --Since 208 is even, you may return half of the bears, 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 (resulting in 10) and return these 10 bears. This leaves you with 42 bears. --You have reached the goal! Write a recursive method to meet this specification: public static boolean bears (int n) // Postcondition: A true return value means that it is possible to win // the bear game by starting with n bears. A false return value means that // it is not possible to win the bear game by starting with n bears. // // // Examples: bear (250) is true (as shown above) bear (42) is true bear (84) is true bear (53) is false bear (41) is false // // To test whether n is even, use the expression (n % 2) == 0). 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): 1. If n is even, then you may give back exactly n/2 bears. 2. 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). 3. If n is divisible by 5, then you may give back exactly 42 bears. 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 return 42 of the bears, leaving you with 208 bears. --Since 208 is even, you may return half of the bears, 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 (resulting in 10) and return these 10 bears. This leaves you with 42 bears. --You have reached the goal! Write a recursive method to meet this specification: public static boolean bears (int n) // Postcondition: A true return value means that it is possible to win // the bear game by starting with n bears. A false return value means that // it is not possible to win the bear game by starting with n bears. // // // Examples: bear (250) is true (as shown above) bear (42) is true bear (84) is true bear (53) is false bear (41) is false // // To test whether n is even, use the expression (n % 2) == 0).
Expert Answer:
Answer rating: 100% (QA)
Code Private Sub Button1Clicksender As Object e As EventArgs Handles Button1Click MsgBoxbearIntTe... View the full answer
Related Book For
Financial Theory and Corporate Policy
ISBN: 978-0321127211
4th edition
Authors: Thomas E. Copeland, J. Fred Weston, Kuldeep Shastri
Posted Date:
Students also viewed these programming questions
-
Is the number of children that a college student currently has independent of the type of college or university being attended? Suppose students were randomly selected from three types of colleges...
-
This question involves a more realistic set of facts and therefore requires a more detailed analysis of cash flows than contained in the chapter. Your company is going to negotiate a lease contract...
-
Is the number of children that a college student currently has independent of the type of college or university being attended? Suppose students were randomly selected from three types of colleges...
-
Four wooden beams, each of length 2a, are nailed together at their midpoints to form the support system shown. Assuming that only vertical forces are exerted at the connections, determine the...
-
Equity Investment, Available-for-Sale, Impairments, IFRS. Repeat E16-21 assuming Gretta Company reports under IFRS.
-
What is the connection between North Koreas missile program and its hunger problem?(World View,p.10)
-
Reconsider Parts (a) through (f) of Problem 2. For each "true" statement, develop a mathematical proof based on the time value of money factor equations from Table 2.6 in Chapter 2. Data from problem...
-
Armada Company has these comparative balance sheet data: Additional information for 2010: 1. Net income was $25,000. 2. Sales on account were $375,000. Sales returns and allowances amounted to...
-
Discuss the opportunities and threats that is associated with the external environment of the company selected
-
Suppose you are a euro-based Italian Investor, and you are Investing 11,200 to buy shares of a British company at 50 per share. The exchange rate is 1.40 per pound. The stock pays a 1 dividend one...
-
Given the conservative vector field, F=(x +3y)i +(6.xy +5)j, evaluate the integral fF-d where C is the path from (1,1), to (4,4).
-
Assume that 1 U.S. dollar can be exchanged for 105 Japanese yen or for 0.80 euro. What is the euro/yen exchange rate?
-
Are all of the steps in the marketing research process always followed in order? Why or why not? Give an example of a situation in which a step might be skipped in the marketing research project.
-
Describe how a risk-free portfolio can be created using stocks and options. How can such a portfolio be used to help estimate a call options value?
-
List three important marketing research codes and provide a brief explanation of what purpose they are intended to serve.
-
What adjustments might be made to the domestic cost of capital for a foreign investment due to exchange rate risk, political risk, and country risk?
-
1. The employment standards act provides for fourteen types of statutory leaves of absence. Identify three of these types of leaves and explain parameters for each (explain in details) 2): "Just...
-
When you weigh yourself on good old terra firma (solid ground), your weight is 142 lb. In an elevator your apparent weight is 121 lb. What are the direction and magnitude of the elevator's...
-
Prove that for any securities X and Y: E(X2)= (E(X))2+VAR( ) If rr,-1, then (X + Y) Ox + . If rxy--I, then (X + Y)-Ox-@y
-
Suppose you are the manager of an investment fund in a two-parameter economy. Given the following forecast: E(Rm) = .16, (Rm) = .20, Rf = .08 (a) Would you recommend investment in a security with...
-
sing simple binomial trees, calculate the value of a combined call and put option with the following characteristics: Underlying asset current value = 2,000. Contraction option = 50% reduction in...
-
A client who is a director of a publicly listed corporation is required by law to refrain from trading that companys stock at certain points of the year when disclosure of financial results are...
-
Consider the pairwise correlations of monthly returns of the following asset classes: Based solely on the information in the preceding table, which equity asset class is most sharply distinguished...
-
Investing the majority of the portfolio on a passive or low active risk basis while a minority of the assets is managed aggressively in smaller portfolios is best described as: A. The coresatellite...
Study smarter with the SolutionInn App