In: Computer Science
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money from 0 to 99 cents. The program then calculates and displays the number of coins from each denomination: quarters (25 cents), dimes (10 cents), nickels (5 cents), and cents. For example, if the user enters 93, your program should display There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents Note: You must use integer division and modular division to find the digits.
import java.util.Scanner;
public class Change{
public static void main(String[] args) {
int amount=0,d=0,q=0,n=0,p=0,di=0;
System.out.printf("Enter amount: ");
Scanner sc = new Scanner(System.in);
amount=sc.nextInt();
if(amount==0){
System.out.printf("no change");
return;
}
//finding dollors
if(amount>=100){
d=amount/100;
amount=amount%100;
}
//finding quarters
if(amount>=25){
q=amount/25;
amount=amount%25;
}
//findigng dimes
if(amount>=10){
di=amount/10;
amount=amount%10;
}
//finding nickels
if(amount>=5){
n=amount/5;
amount=amount%5;
}
p=amount;
if(d==1)
System.out.printf("%d dollor\n",d);
else if(d!=0)
System.out.printf("%d dollors\n",d);
if(q==1)
System.out.printf("%d quarter\n",q);
else if (q!=0)
System.out.printf("%d quarters\n",q);
if(di==1)
System.out.printf("%d dime\n",di);
else if (di!=0)
System.out.printf("%d dimes\n",di);
if(n==1)
System.out.printf("%d nickel\n",n);
else if (n!=0)
System.out.printf("%d nickels\n",n);
if(p==1)
System.out.printf("%d penny\n",p);
else if (p!=0)
System.out.printf("%d pennies\n",p);
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME