1 / 11

Changes (Prog600 – 58t)

Welcome to Flight #600 – 58t. Changes (Prog600 – 58t). AP Computer Science 2010 By: Chia-Hsuan Wu. So, here is your mission.

uta-winters
Télécharger la présentation

Changes (Prog600 – 58t)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to Flight #600 – 58t Changes (Prog600 – 58t) AP Computer Science 2010 By: Chia-Hsuan Wu

  2. So, here is your mission • Write a class that will direct a cashier on how much change to give customer. The program should have two inputs: The amount of the purchase and the amount receivedfrom the customer and a call to the calculate method. The class methods will determine and output the number of dollars, quarters, dimes, nickels and pennies need to make the correct change for the transaction. The class will also print out a table of each type of coin/currency to return to the customer. Be sure to use lookup tables for the values of your coins and the monetary denominations.

  3. Getting Ready… • Start by importing these two: • - import java.io.*; • - import java.util.Scanner; • Then the usual: • public class Prog60058t • { public static void main (String [] args) • { } • } • create a scanner so user can input amount. Scanner i = new Scanner (System.in);

  4. Contacting Tower… • Print a line of text “Enter purchase price “ then create a value (double) for the user to enter System.out.print (“Enter purchase price “); double x = i.nextDouble (); • Repeat the action above and print “Enter amount given “ and assign a value to it. • Then from print out (different lines): • “++++++++++++++++” • “Correct change “ • “++++++++++++++++”

  5. Taking Off… • Then create another value that calculate the difference of y and x (price and given). double TT = y – x; • Convert it into int. int EST = (int)TT; • EST is the amount of ONE DOLLAR BILL you’ll be giving. So print out the amount of ones System.out.println (“Ones = “ + EST); • Then create another value called “Left” to calculate the decimal value of TT double Left = TT – EST; //Decimal • Then create another value DL that will times Left to 100. (so we don’t have to deal with ugly decimal numbers!) double DL = (Left*100);

  6. In The Air…Holy cow! You forgot the flight instructions. (gotta figure it out!) • Create If statement to determine the number of each coin. • First of all, check if DL is >= to 25. (if DL is >= 25 that means you will need to hand out quarters.) • YOU MUST CHECK ALL POSSIBILITIES

  7. Hint 1: • I check if DL >= 25 • If yes then check if DL >= 77 and 50 • If no then check if DL >= 10 • If yes then divide DL by 10 and make it in int. And that’s the number of dimes • If no then same thing with nickels and pennies.

  8. Hint 2: Check if DL is >= 25 No YES Check if DL is >=10 Print quarter = 1. Then DL – 25 Check if DL >= 50 Yes No No YES I’m sure you can figure out the rest Solution on the next page

  9. Problem Solved. Ready to land. Solution: • Great job! That sure took a while. • Alright here is my solution: http://sites.google.com/site/prog60058t/ • Remember : it is not the only solution.

  10. Congratulations!Successful Landed! • Final part of this program is to print out the total amount • So… System.out.println (“Total Amount = “ + TT); • Don’t forget to try the program before you finished • It should look like this: • Enter purchase price 10.01 • Enter amount given 20.00 • ++++++++++++++ • Correct Change • ++++++++++++++ • Ones = 9 • Quarters = 3 • Dimes = 2 • Nickels = 0 • Pennies = 4.0 • Total Amount = 9.99

  11. THE ENDthank you for your time.

More Related