Presentation is loading. Please wait.

Presentation is loading. Please wait.

C HANGES (P ROG 600 – 58 T ) AP Computer Science 2010 By: Chia-Hsuan Wu.

Similar presentations


Presentation on theme: "C HANGES (P ROG 600 – 58 T ) AP Computer Science 2010 By: Chia-Hsuan Wu."— Presentation transcript:

1 C HANGES (P ROG 600 – 58 T ) AP Computer Science 2010 By: Chia-Hsuan Wu

2 S O, 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 received from 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 G ETTING R EADY … 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 C ONTACTING T OWER … 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 T AKING O FF … 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 I N T HE A IR …H OLY COW ! Y OU 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 H INT 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 No Check if DL is >= 25 YES Check if DL >= 50 YES No Print quarter = 1. Then DL – 25 Check if DL is >=10 YesNo Hint 2: Solution on the next page

9 P ROBLEM S OLVED. R EADY TO LAND. S OLUTION : Great job! That sure took a while. Alright here is my solution: http://sites.google.com/site/prog60058t/ http://sites.google.com/site/prog60058t/ Remember : it is not the only solution.

10 C ONGRATULATIONS ! S UCCESSFUL L ANDED ! 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 END THANK YOU FOR YOUR TIME.


Download ppt "C HANGES (P ROG 600 – 58 T ) AP Computer Science 2010 By: Chia-Hsuan Wu."

Similar presentations


Ads by Google