Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: To give you more practice working with arithmetic operators, and methods in the Math and Random classes. Part A: Sarah made the rookie mistake

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Objective: To give you more practice working with arithmetic operators, and methods in the Math and Random classes. Part A: Sarah made the rookie mistake of walking into Titan Bakery with a $200 bill, and nothing smaller. She has bought some delicious bagels, biscuits, muffins and rolls, and now the cashier needs to make change. The cashier has $50's, $20's, $10's, $5's and $1's and will naturally dispense the $50's first, the $20's second, and so on. In this program, you will a) ask the user how much Sarah spent on food (between 0-200), and then b) print out how many of each denomination ($50, $20, $10, $5 and $1) should be dispensed. For example, if Sarah spent $67 on food, the change, $133, would be administered as 2 $50's, 1 $20,1 $10,0 $5's, and 3 $1's (2-50 + 1-20 + 1-10 + 0*5 + 381 133). Hint: think about how many $50's go into $133, and then how much will be left over. Instructions: 1. Add a Java class, Change, to a Bluej project, Lab3. 2. Customize the multiline comment at the top of Change, and the README. 3. Write an algorithm, just in English, describing step by step how you will solve this problem. List the steps in the README. 4. Implement your algorithm in Change, adding the steps of the algorithm to your code, as we did in the last lab 5. Make sure you indentation is consistent, and your spacing is as well. Choose good, descriptive identifier names. 6. Test your algorithm using a variety of inputs (making sure, of course, that you know what the output should be!) Instructions: 1. Add a Java class, Change, to a BlueJ project, Lab3. 2. Customize the multiline comment at the top of Change, and the README. 3. Write an algorithm, just in English, describing step by step how you will solve this problem. List the steps in the README. 4. Implement your algorithm in Change, adding the steps of the algorithm to your code, as we did in the last lab 5. Make sure you indentation is consistent, and your spacing is as well. Choose good, descriptive identifier names. 6. Test your algorithm using a variety of inputs (making sure, of course, that you know what the output should be!) Sample Output (user input is in bold): Titan Bakery bill: $67 Change: $133 # 50's: 2 # 20's: 1 # 10's: 1 # 5's: 0 # 1's: 3 Part B: The Fibonacci sequence is a sequence of numbers in which each term is the sum of the two that precede it: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ... So, 2 = 1 + 1;3 = 1 + 2; 5 = 2 + 3; etc. We number these, so fq=1, f2=1, f3=2, fa=3, fs=5, and in general the nth term fn = fn-1 + fn-2 Interestingly we can find the nth term, fn, using a formula: (on - (1-9)") fn= 15 where that mysterious looking a symbol (the Greek letter Phi) is a constant called the Golden Rectangle, with a value of p= (1+/32 For example, if n-6, then fo = (1.6180 - (1-1,618))/ V5 - 7.9999999988 (which is quite close to 8) Now that we are experts on the Fibonacci sequence (except maybe how to spell it ), let's write a program to calculate it. To add excitement, instead of asking the user for n, we will ask the user for a minimum and a maximum value for n; your program will generate a random number for n between minimum and maximum, inclusive, and use that to calculate fn. Sample Output: Minimum n: 1 Maximum n: 10 Computing 15 f5 is 5 Now that we are experts on the Fibonacci sequence (except maybe how to spell it), let's write a program to calculate it. To add excitement, instead of asking the user for n, we will ask the user for a minimum and a maximum value for n; your program will generate a random number for n between minimum and maximum, inclusive, and use that to calculate fn. Sample Output: Minimum n: 1 Maximum n: 10 Computing f5 f5 is 5 Minimum n: 3 Maximum n: 8 Computing f7 f7 is 13 Instructions: 1. Create a new Java class in your Lab3 BlueJ, FiboMaker 2. Customize the multiline comment in FiboMaker as before. 3. Be sure and comment your code properly 4. Since we use phi repeatedly, it is better to calculate it just once, and store it in a constant 5. Your program will need to use the Math and Random classes. 6. Be sure and test your program multiple times

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

09 Administer internal and external privacy policies. Knowledge of:

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago