# [Help] About seminar paper (Java)

• January 3rd, 2013, 04:28 PM
Ghack
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.

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):

http://i46.tinypic.com/1t5yqd.png
• January 3rd, 2013, 04:42 PM
Norm
Re: [Help] About seminar paper (Java)
Please edit your post and fix the formatting of the code. The statements should not all start in the first column. Nested statements should be indented 3-4 spaces to reflect the logic.

Can you explain what problems you are having with the code? Describe what you want the code to do.

Post the program's current output and add some comments to it saying what you want it to be.
• January 3rd, 2013, 05:11 PM
curmudgeon
Re: [Help] About seminar paper (Java)
Cross-posted on the java-forums.org.
• January 4th, 2013, 10:26 AM
Ghack
Re: [Help] About seminar paper (Java)
Quote:

Originally Posted by Norm
Please edit your post and fix the formatting of the code. The statements should not all start in the first column. Nested statements should be indented 3-4 spaces to reflect the logic.

Can you explain what problems you are having with the code? Describe what you want the code to do.

Post the program's current output and add some comments to it saying what you want it to be.

It is itself uncleared like an exercise, i wrote it like it is on book :/
• January 4th, 2013, 10:46 AM
Norm
Re: [Help] About seminar paper (Java)
Can you explain why you posted the code and what you want to do with the code?

Please edit your post and fix the formatting of the code. The statements should not all start in the first column. Nested statements should be indented 3-4 spaces to reflect the logic.

Also posted at http://www.java-forums.org/new-java/...gram-java.html
• January 4th, 2013, 12:00 PM
Ghack
Re: [Help] About seminar paper (Java)
Quote:

Originally Posted by Norm
Can you explain why you posted the code and what you want to do with the code?

Please edit your post and fix the formatting of the code. The statements should not all start in the first column. Nested statements should be indented 3-4 spaces to reflect the logic.

Also posted at [Help] About changing computing program (Java)

I will post later full infos and after that u can watch it :)
• January 4th, 2013, 12:04 PM
copeg
Re: [Help] About seminar paper (Java)
• January 4th, 2013, 03:23 PM
Ghack
Re: [Help] About seminar paper (Java)
I just posted :\$
• January 4th, 2013, 03:28 PM
Norm
Re: [Help] About seminar paper (Java)