জাভা প্রোগ্রামিং পর্ব-০৬

Problem : Counting Monetary Units 
Here are the steps in developing the program:
1. Prompt the user to enter the amount as a decimal number, such as 11.56.
2. Convert the amount (e.g., 11.56) into cents (1156).
3. Divide the cents by 100 to find the number of dollars. Obtain the remaining cents using
the cents remainder 100.
4. Divide the remaining cents by 25 to find the number of quarters. Obtain the remaining
cents using the remaining cents remainder 25.
5. Divide the remaining cents by 10 to find the number of dimes. Obtain the remaining
cents using the remaining cents remainder 10.
6. Divide the remaining cents by 5 to find the number of nickels. Obtain the remaining
cents using the remaining cents remainder 5.
7. The remaining cents are the pennies.
8. Display the result.

Code : 
import java.util.Scanner;
public class ComputeChange {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
//Receive the amount
System.out.print("Enter an amount in double, for example 11.56: ");
int remainingAmount = (int)(amount * 100);
// Find the number of one dollars
remainingAmount = remainingAmount % 100;
// Find the number of quarters in the remaining amount
remainingAmount = remainingAmount % 25;
Find the number of dimes in the remaining amount
remainingAmount = remainingAmount % 10;
Find the number of nickels in the remaining amount
remainingAmount = remainingAmount % 5;
Find the number of pennies in the remaining amount
int numberOfPennies = remainingAmount;
// Display results
System.out.println("Your amount " + amount + " consists of \n" + "\t" + numberOfOneDollars + " dollars\n" + "\t" + numberOfQuarters + " quarters\n" +
"\t" + numberOfDimes + " dimes\n" + "\t" + numberOfNickels + " nickels\n" +
 "\t" + numberOfPennies + " pennies");
}
}

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle