• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Coin Machine Change Java

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part 2
The questions in this part of the assignment will be graded.
Question 1: Coin Machine Program (100 points)
Write your program in a java file called CoinMachine.java. Your program must determine the amount
of change that would be returned by a coin machine given the amount of money dropped into the machine
by a customer (call it the cash) and the cost of the item wanted by the customer (call it the price).
Assume that the change will be composed of toonies, loonies, quarters, dimes, and nickels. Assume also
that:
• The amount of money dropped into the machine by the customer will always be equal to or greater
than the cost of the item.
• Amounts are considered to be integer amounts in cents. For example, $2.75 is represented by the
integer 275.
• Amounts will always be multiples of 5 (i.e. pennies are not considered).
• Your coin machine has an infinite number of each type of coin with which to supply change.
Note that, to be considered correct, your program must provide the user with the most convenient exact
change (i.e. the exact amount with the fewest coins).
Write Java code in the marked area of the provided file to display the following information:
1. The amount received by the coin machine.
2. The cost of the item.
3. The required change.
4. How many of each of the coins will be returned by the coin machine.
Let’s look at three examples:
1. If the program is run with input arguments 400 and 215 (that is the item costs $2.15 and the
customer dropped $4.00 into the machine) then the output should be:
Amount received: 400
Cost of the item: 215
Required change: 185
Change:
toonies x 0
loonie x 1
quarter x 3
dime x 1
nickel x 0
Note that, for instance, a solution of toonie x 0, loonie x 0, quarter x 7, dime x 1, nickel x 0 is not
considered correct.
Note: Toonie = $2, Loonie = $1, Quarter = 25 ¢, Dime = 10 ¢, Nickel = 5 ¢.
2. If the program is run with input arguments 250 and 210 then the output should be:
Amount received: 250
Cost of the item: 210
Required change: 40
Page 3
Change:
toonies x 0
loonie x 0
quarter x 1
dime x 1
nickel x 1
3. If the program is run with input arguments 1000 and 415 then the output should be:
Amount received: 1000
Cost of the item: 410
Required change: 590
Change:
toonies x 2
loonie x 1
quarter x 3
dime x 1
nickel x 1
Be sure to include the specified text on each output line. That is, concatenate a String literal with
the value of a variable.
Input Arguments Note that this program is run by providing input arguments. That is, cash and price
do not have a fixed value. Their values will depend on the input provided when running the program.
For example, once this program is compiled, it can be run by typing the text run CoinMachine 400 215
in the Interactions Pane and pressing Enter. The output of the program must be different than if the
text run CoinMachine 500 150 was entered.
If you are using Eclipse, please read this for help with input arguments:
http://www.cs.colostate.edu/helpdocs/eclipseCommLineArgs.html.
What To Submit
Please put all your files in a folder called Assignment1. Zip the folder (DO NOT RAR it or use other
compression extension like .7z) and submit it on MyCourses. If you use other compression extension like
.rar, .7z etc, you will lose marks. Use only .zip.
Inside your zipped folder, there must be the following files. Do not submit any other files, especially
.class files. Any deviation from these requirements may lead to lost marks.
CoinMachine.java
Confession.txt (optional) In this file, you can tell the TA about any issues you ran into doing
this assignment.

Kindly help me some one (in simple way)
 
Sheriff
Posts: 8064
569
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

How far have you got?
 
Marti Nob
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi bro , I am new in coding, stuck with beginning itself
 
Marshal
Posts: 74004
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I suggest you start by writing down how you would do it in real life, writing on paper, with your computer turned off.
 
Sheriff
Posts: 26773
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marti Nob wrote:Write your program in a java file called CoinMachine.java



Stuck with beginning? This is the beginning... so start by writing a program which doesn't do anything except comply with the requirements stated.
 
Marti Nob
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i understood the logic, i written on the book.

These are my findings:

Amount received: 400 // This is the amount customer put in 4 dollar. but here we need to represent in cents, so 400. 100cents =1dollar, & amount should be always greater than 0,
Cost of the item: 215 // This is the cost of item in cents
Required change: 185 // This is the amount need to return to customer.

Change: // change should be given back based on below coins only. Conditions is the bigger coins give back first and followed next (least coins). (toonies 200> loonie>100>Quarter25>Dime 10> Nickel 5)

toonies x 0 // number represents count of the coin
loonie x 1 // number represents count of the coin
quarter x 3 // number represents count of the coin
dime x 1 // number represents count of the coin
nickel x 0 // number represents count of the coin
 
Marti Nob
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Marti Nob wrote:Write your program in a java file called CoinMachine.java



Stuck with beginning? This is the beginning... so start by writing a program which doesn't do anything except comply with the requirements stated.

Created java file CoinMachine.java & given class name CoinMachine. SRC created. now i am at

public class CoinMachine {

public static void main(String[] args) {
   
}
 
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good. What you've posted won't compile though because you're missing a '{'  '}'. You may have just dropped it by mistake when you cut and pasted the code into the post.

So, make sure you get it to compile. Make sure it runs without any errors. Note that when you run it it won't actually do anything because you have noting inside the main() method. If you want to see it do something you could add this inside of the main() method:

Then get it to compile and run again.
 
Marti Nob
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class CoinMachine {

public static void main(String[] args) {
   
       int cash = 400; // 'Cash' refers amount received by machine
       int price = 100; // 'price' refers cost of the item
    int requiredChange = cash - price; // 'requiredChange' refers total amount to be returned to customer
}
}

Question : The amount of money dropped into the machine by the customer will always be equal to or greater
than the cost of the item. ?  Can anyone help me to the above question
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with the largest denomination, "toonies", and find out how many times the required change is divisible by that. Compute the remaining required change.
 
Campbell Ritchie
Marshal
Posts: 74004
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:. . . how many times the required change is divisible by that. . . ..

Work out the rules for division (they are also to be found in the JLS (=Java® Language Specification)) and see how division works. That might make Carey's step easier to implement.
 
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marti Nob wrote:Question : The amount of money dropped into the machine by the customer will always be equal to or greater
than the cost of the item. ?  Can anyone help me to the above question


That's not a question, that's an assumption that was given with the problem. Are you not sure what it means?

If you're not sure what that means, all it is saying is that if you have an item with a price of 100, the cash amount given is guaranteed to be at least 100, and possibly more. That is, the cash given will never be less than the price of the item being paid for.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic