Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with program

807598Oct 25 2006 — edited Oct 25 2006
Here are the instructions:
"Some cash register systems use change machines that automatically dispense coins. This lab will investigate the problem solving and programming behind such machinery. You always want to use the fewest coins possible. You should use integer mathematics to solve this problem.

Provide the number of cents through the constructor. Write a method that calculates the number of each type of coin.

Examples:

35 cents =>
Quarter(s) 1
Dime(s) 1
Nickel(s) 0
Penny(s) 0

41 cents =>
Quarter(s) 1
Dime(s) 1
Nickel(s) 1
Penny(s) 1

Assignment:

1. Follow the same format that was used in Lab Assignment A3.1, Easter, using a driver and a class called Coins.

2. Run the samples from above to check your work.

3. Run the following three samples and copy the sample runs into your class file, print out the code for the class and hand in.

94 cents
59 cents
19 cents

4. Do not worry about singular versus plural endings, i.e. quarter/quarters."

And here is what I have so far...
public class Coin {
 public static void main(String[] args)
 {
   new Coin();
 }
 
 public Coin()
 {
   Scanner Coin = new Scanner(System.int);
   int n;
   
   System.out.print("Enter a number: ");
   
   n = Coin.nextInt();
   
   System.out.print(quarters(n) + " quarter(s), ");
   System.out.print(dimes(n) + " dime(s), ");
   System.out.print(nickels(n) + " nickel(s), and ");
   System.out.println(pennies(n) + " penny(ies).");
 }
 
 private int quarters(int total)
 {
   return total / 25;
 }
 
 private int dimes(int total)
 {
   return total - quarters(total) * 25 / 10;
 }
 
 private int nickels(int total)
 {
   return total - (quarters(total) * 25)
     - (dimes(total) * 10) / 5;
 }
 
 private int pennies(int total)
 {
   return total - (quarters(total) * 25)
     - (dimes(total) * 10)
     - (nickels(total) * 5);
 }
}
I get two errors at " Scanner Coin = new Scanner(System.int);" One saying that a ( is expected, and another saying that an identifier is expected.

Any help?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 22 2006
Added on Oct 25 2006
7 comments
457 views