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

