Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
image text in transcribed
Page Objective: To give you more practice working with arithmetic operators, and methods in the Math and Random classes. Part A: Sarah made the rookle 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 S1) 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 (250 + 1-20 + 1-10 + 0-53*1 == 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! 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 Pog Part B: The Fibonacci sequence is a sequence of numbers in which each term is the sum of the two that precedeit: 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 f1=1, f2=1, fp=2, f3, fs=5, and in general the nth term fo=fot+fna Interestingly we can find the nth term, for using a formula: (son - (1-r)") fn= V5 where that mysterious looking o symbol (the Greek letter Phi) is a constant called the Golden Rectangle, with a value of (1+5) : 2 For example, if n=6, then f = (1.6186 - (1-1.618)9/ 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 in. Sample Output: Minimum : 1 Maximum n: 10 Computing f5 15 is 5 Minimum n: 3 Maximum n: 8 Computing 17 17 is 13 Instructions: 1. Create a new Java class in your Lab3 Blue, FiboMaker 2. Customize the multiline comment in Fibo Maker as before. 2. 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 Moth and Random classes 6. Be sure and test your program multiple times using the values specified in the sample output section Checklist (not to hand in): Auto-layout applied? (command-shift-I or ctrl-shift-1) Comment block filled in? (Name, Date, Description) README filled in (with the algorithm for part A) Descriptive identifier names chosen? (a, e, se, and st will get a 0 for sure) Redundant parentheses removed? -- e.g., a = (b*c) + (de); or worse a = (bc) + (d'e)); Both should be written ab'c + d'e; Spelling/spacing checked? Your output should match mine. Appropriate blank lines in the code to aid legibility? (e.g., 1 blank line separating input, processing and output) Defined variables for any calculation? (Don't just print the formula in the System.out.println statement) Uploaded project? (even if you've demoed, you still need to upload project) Uploaded separate screenshot of output? Read this checklist

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions