Allison takes a trip to a “Cent Store” where all items cost less than one dollar and she purchases one
item. Ask for the cost of the item in cents. Remember that the cost will be less than one dollar.
Display the minimum number of coins needed to make change for Allison’s purchase from one dollar.
Also display the number of each type of coin. (Possible coins are pennies, nickels, dimes, and
quarters.)
import java.util.Scanner;
public class CentStore {
//Scanner sc=new Scanner(System.in);
int i;
float quarter,lef,dimes,nickels,pennies;
public int recursion(float i){
if(i<=1){
System.out.println("The cost of the item in dollor be:"+i+"$");
/* computer the number of quarters and how much is left over */
quarter = i/25;
i= i % 25;
/* computer the number of dimes and how much is left over */
dimes = i / 10;
i = i % 10;
/* computer the number of nickels and how much is left over */
nickels = i / 5;
i = i % 5;
/* whatever is left over is the number of pennies */
pennies = i;
System.out.println("Number of quarter coin:"+quarter);
System.out.println("Number of dimes coin:"+dimes);
System.out.println("Number of dimes coin:"+nickels);
System.out.println("Number of dimes coin:"+pennies);
}else{
recursion(i);
}
return 0;
}
public static void main(String[] args){
CentStore cs = new CentStore();
Scanner sc=new Scanner(System.in);
System.out.println("Please enter the cost of the item in dollor");
float i=sc.nextFloat();
System.out.println("The spended amount:"+i+"$");
cs.recursion(i);
}
}
Comments
Leave a comment