• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modified Cash Register.  RSS feed

 
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a slightly modified cash register. The user will enter the amount of the item, the payment received, calculate the change/refund, and then allow the user to choose the preferred bills.



I will try to clarify the code, to make things a little easier to interpret. in the refund method, I have set up a 2-d array to exist and function as an excel sheet. The refund amount is passed to the method and compared to each bill of the array. Once the refund is determined to be greater than a bill, the user is prompted to enter the preferred bill type. This is where my problem is...I would like the program to then calculate the number of bills and keep a tally of those bills in the 2nd column and then determine the new refund amount at which point the user will be prompted again to determine the desired bill.
Then print out the array of bills that are not equal to 0.

Is this the wrong approach to be taking for this type of program.
 
Bartender
Posts: 1838
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than a 2d array, I would probably personally use a Map of dollar value to how many bills were involved. But that doesn't change the concept.
I don't see anything much wrong with your proposed approach. Let us know how it goes.


A quick test of the program as it is resulted in this:
*****CASH REGISTER*****
Item Amount: 4
Amount Received: 10
Change: $1 - 6

Hmmm - rather than six $1 notes, I would prefer a 5 and a 1.
If you had to make change for somebody, how would YOU start counting out the money?

 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an indenting problem with the do statement. I would probably use curly braces, but at least indent:



And unless I'm mistaken, your method will refund everything in ones.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stefans, thank you for your response. Unfortunately, I am not yet familiar with mapping, so I will have to save that for another time. I have since changed a few things in the code. The result you got ($1 - 6) was one of the problems I was having in the code. The new code is working out a little better; however, I am still running into some counter issues. I want to avoid as much redundancy as possible. As you can see below, the layout is what it is, can't do a lot with console, but the counter is not responding correctly to the $5 return amount. When it was $15 and I wanted $5 bills, it should have broke from the loop and printed the data, but it asked me again.




Result:
*****CASH REGISTER*****
Item Amount: 85
Amount Received: 200
Amount Due: $115
What type of bills:
100
Amount Due: $15
What type of bills:
5
Amount Due: $5
What type of bills:
5
Bill Count
$100 -- 1
$10 -- 1
$5 -- 1
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:There is an indenting problem with the do statement. I would probably use curly braces, but at least indent:

And unless I'm mistaken, your method will refund everything in ones.


Yes, you are correct Knute, it was refunding in ones. I think I have fixed that.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should have broke from the loop and printed the data, but it asked me again.


There's a for loop inside the do loop and I don't see a break command, so tell me what is the for loop going to do?
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if I were to add a break, I don't see how that would explain this output:

*****CASH REGISTER*****
Item Amount: 125
Amount Received: 140
Amount Due: $15
What type of bills:
5
Amount Due: $5
What type of bills:
5
Bill Count
$10 -- 1
$5 -- 1

I believe what is happening is that the row of the array only moves one more in the for loop, instead of to the point in the array where the preferred bill value is entered by the input. For example, the case above stops at 10 and asks what type of bill, but I entered 5, the problem is the row of the array is valued at 10, not 5. So it has calculated for 10, and not the 5 I want. Do you know how I might change this?

Also, do you know how i might eliminate redundancies in the code and output?
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way I can see to get the program to work is to change the question to "How many ns do you want?", with n being the denomination you are on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!