Results 1 to 11 of 11
- 01-03-2013, 09:55 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
[Help] About changing computing program (Java)
Guys, i need help about something in Java. Im a newbie and i don't know nothing about it so i need u're help 'cuz i need that for a seminar paper.
I have to change computing program to programming projects, u can see an example down there:
1. Set the starting value of money.
2. Subtract the maximum number of quarters from money, and print the quantity
of quarters extracted.
3. Subtract the maximum number of dimes from money, and print the quantity of
dimes extracted.
4. Subtract the maximum number of nickels from money, and print the quantity of
nickels extracted.
5. The remainder of money is printed as pennies.
Here is how we might write the ¯rst step in Java:
int dollars = 3;
int cents = 46;
int money = (dollars * 100) + cents;
The second step of the algorithm is cleverly written as follows:
System.out.println("quarters = " + (money / 25));
money = money % 25;
These statements exploit integer division, /, and integer modulo, %.
In the ¯rst statement, money / 25 calculates the maximum number of quarters to
extract from money. There are two important points:
1. The integer division operator, /, calculates integer quotient|the number of
times 25 can be subtracted from money without leaving a negative remainder. In
the example, since money's cell holds 346, the quotient is 13, because a maximum
of 13 quarters (13*25 = 325) can be wholly subtracted from 346 without leaving
a negative remainder. Here are additional examples for intuition:
² 14 / 3 computes to 4 (and the remainder, 2, is forgotten)
² 6 / 3 computes to 2 (and there is no remainder)
² 4 / 5 computes to 0, because 5 cannot be wholly subtracted from 4
2. The calculation of the division, money / 25, does not alter the value in money's
cell, which remains 346|only an assignment statement can change the value in
money's cell.
The second statement, money = money % 25, deals with the second point just men-
tioned: Since we have calculated and printed that 13 whole quarters can be extracted
from the amount of money, we must reset the value in money's cell to the remainder.
This can be done either of two ways:
1. By the statement,
money = money - ((money / 25) * 25);
which calculates the monetary value of the extracted quarters and subtracts
this from money.
2. By the more elegant statement,
money = money % 25;
whose modulo operator, %, calculates the integer remainder of dividing money
by 25 and assigns it to money. In this example, the remainder from performing
346/25 is of course 21. Here are additional examples of computing remainders:
² 14 % 3 computes to 2
² 6 % 3 computes to 0
² 4 % 5 computes to 4
The combination of the integer quotient and remainder operations calculates the
correct quantity of quarters.
Java Code:/** MakeChange calculates the change for the amounts in variables * dollars and cents. */ public class MakeChange f public static void main(String[] args) f int dollars = 3; int cents = 46; int money = (dollars * 100) + cents; System.out.println("quarters = " + (money / 25)); money = money % 25; System.out.println("dimes = " + (money / 10)); money = money % 10; System.out.println("nickels = " + (money / 5)); money = money % 5; System.out.println("pennies = " + money); } }
So, the semniar paper is this: Rebuild the change-making program, so that it uses a
model that is this specification (watch the photo below):

Last edited by Ghack; 01-04-2013 at 09:21 PM.
-
Re: [Help] About changing computing program (Java)
I see no image in your post above and no specific answerable question. What exactly do you need help with? The more specific your question, usually the better our answers will be.
- 01-03-2013, 11:27 PM #3
Re: [Help] About changing computing program (Java)
Also posted at [Help] About seminar paper (Java)
If you don't understand my response, don't ignore it, ask a question.
- 01-04-2013, 04:23 PM #4
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Re: [Help] About changing computing program (Java)
There is the photo, look at it
- 01-04-2013, 04:48 PM #5
Re: [Help] About changing computing program (Java)
Do you have any specific questions about your program? Please ask them.
If you don't understand my response, don't ignore it, ask a question.
- 01-04-2013, 09:22 PM #6
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Re: [Help] About changing computing program (Java)
See that thing up there :/
- 01-04-2013, 09:28 PM #7
Re: [Help] About changing computing program (Java)
Where are your questions?
If you don't understand my response, don't ignore it, ask a question.
- 01-05-2013, 04:11 AM #8
Member
- Join Date
- Dec 2012
- Posts
- 42
- Rep Power
- 0
Re: [Help] About changing computing program (Java)
It sounds like your asking the people here to do your homework for you? unfortunatly thats not how it works, if your having trouble with a specific part of your homework and you have a legitimate question the people here are more than happy to help. First you have to try and do this on your own, and then ask questions about specific probems your having, otherwise you will not find much help here.
- 01-05-2013, 01:56 PM #9
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
-
Re: [Help] About changing computing program (Java)
You still haven't asked a question. Please know that no one is going to do your work for you. If you've tried a solution and it's not working, then please by all means show your code, show your errors, and ask your questions. If all you want is for someone to solve this for you, then please go elsewhere (though you'll likely get the same response on any programming forum).
- 01-05-2013, 02:11 PM #11
Re: [Help] About changing computing program (Java)
Assuming that the double negative wasn't intended, here's where you can change that: The Java™ Tutorials
Now, since this thread is going nowhere rather rapidly, I'm closing it. Feel free to start another thread when you can ask an answerable question on the lines of this web page: How to ask questions the smart way
db
THREAD CLOSEDWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
[SOLVED] Changing the look of butons in program
By linux1man in forum AWT / SwingReplies: 8Last Post: 03-14-2009, 06:04 PM -
Computing prime numbers in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:39 PM -
distributed computing in java
By pushpik in forum Advanced JavaReplies: 0Last Post: 03-31-2008, 06:50 PM


LinkBack URL
About LinkBacks


Bookmarks