I'm having trouble with this assignment:
Write a class Coins with one constructor that takes a number of cents as a parameter. Supply four public methods, getQuarters, getNickels, getDimes, getPennies, that return the number of corresponding coins that add up to the amount (in the optimal representation with the smallest possible number of coins). Make sure Coins objects are immutable (that is, none of the class's methods changes any fields)
Here is my code so far:
package coins;
import java.util.Scanner;
public class Coins
{
int cents;
public int quarter = 25;
public int dime = 10;
public int nickel = 5;
public int penny = 1;
public static void main(String[] args)
{
Scanner kboard = new Scanner(System.in);
System.out.print("Enter number of cents:");
int cents = kboard.nextInt();
}
public int getQuarters()
{
int quarters = (cents/quarter);
return (quarters);
}
public int getDimes()
{
int dimes = cents - getQuarters()*25/dime;
return(dimes);
}
public int getNickels()
{
int nickels = cents - (getQuarters()*25) - (getDimes()*10) / nickel;
return(nickels);
}
public int getPennies()
{
int pennies = cents - (getQuarters()*25) - (getDimes()*10) - (getNickels()*5) / penny;
return (pennies);
}
System.out.println(cents + " cents equals: ");
System.out.println("Quarters: " + getQuarters());
System.out.println("Dimes: " + getDimes());
System.out.println("Nickles: " + getNickels());
System.out.println("Pennies: " + getPennies());
}
I'm lost, please help. thanks =)