In the previous article, we have seen Java Program for Grade Calculation System
In this article we are going to see how to calculate total amount from number of notes using java programming language.
Java Program for Calculate Total Amount from Number of Notes
In India, Currency notes are available in different denominations like 10 rupees note, 20 rupees note, 50 rupees note, 100 rupees note, 500 rupees note, 2000 rupees note.
So, to calculate the total amount we can multiply the number of notes available for each denomination with the value of each note and sum them up.
Let’s see different ways to calculate total amount from number of notes.
- By Using Static Input Value
- By Using User Input Value
- By Using User Defined Method
- CIPLA Pivot Point Calculator
Method-1: Java Program for Calculate Total Amount from Number of Notes By Using Static Input Value
Approach:
- Declare number of notes.
- Then multiply the note value with number of notes for each denomination.
- Print the result.
Program:
import java.util.Scanner; public class Main { public static void main(String[] args) { //declared number of notes of different notes int ten = 11; int twenty = 18; int fifty = 9; int hundred = 16; int fiveH = 7; int twoTh = 3; // calculate total amount int totalAmount = (ten * 10) + (twenty * 20) + (fifty * 50) + (hundred * 100) + (fiveH * 500) + (twoTh * 2000); // display total amount System.out.println("Total amount is " + totalAmount); } }
Output: Total amount is 12020
Method-2: Java Program for Calculate Total Amount from Number of Notes By Using User Input Value
Approach:
- Create Scanner class object.
- Take user input for number of notes he/she has under each denomination.
- Multiply the note value with number of notes for each denomination and add.
- Print the result.
Program:
import java.util.Scanner; public class Main { public static void main(String[] args) { // Calculate Total Amount from Number of Notes // create scanner class object Scanner sc = new Scanner(System.in); // prompt user to enter number of notes System.out.print("Enter number of 10 rupees notes: "); int ten = sc.nextInt(); System.out.print("Enter number of 20 rupees notes: "); int twenty = sc.nextInt(); System.out.print("Enter number of 50 rupees notes: "); int fifty = sc.nextInt(); System.out.print("Enter number of 100 rupees notes: "); int numberOfNotes = sc.nextInt(); System.out.print("Enter number of 500 rupees notes: "); int fiveH = sc.nextInt(); System.out.print("Enter number of 2000 rupees notes: "); int twoTh = sc.nextInt(); // calculate total amount int totalAmount = (ten * 10) + (twenty * 20) + (fifty * 50) + (numberOfNotes * 100) + (fiveH * 500) + (twoTh * 2000); // display total amount System.out.println("Total amount is " + totalAmount); } }
Output: Enter number of 10 rupees notes: 10 Enter number of 20 rupees notes: 5 Enter number of 50 rupees notes: 2 Enter number of 100 rupees notes: 5 Enter number of 500 rupees notes: 2 Enter number of 2000 rupees notes: 1 Total amount is 3800
Method-3: Java Program for Calculate Total Amount from Number of Notes By Using User Defined Method
Approach:
- Create Scanner class object.
- Take user input for number of notes he/she has under each denomination.
- Call user defined method amount() to calculate total amount.
- Inside method multiply the note value with number of notes for each denomination and add.
- Print the result.
Program:
import java.util.Scanner; public class Main { public static void main(String[] args) { // Calculate Total Amount from Number of Notes // create scanner class object Scanner sc = new Scanner(System.in); // prompt user to enter number of notes System.out.print("Enter number of 10 rupees notes: "); int ten = sc.nextInt(); System.out.print("Enter number of 20 rupees notes: "); int twenty = sc.nextInt(); System.out.print("Enter number of 50 rupees notes: "); int fifty = sc.nextInt(); System.out.print("Enter number of 100 rupees notes: "); int hundred= sc.nextInt(); System.out.print("Enter number of 500 rupees notes: "); int fiveH = sc.nextInt(); System.out.print("Enter number of 2000 rupees notes: "); int twoTh = sc.nextInt(); //calling user defined method amount() to calculate total amount amount(ten,twenty,fifty,hundred,fiveH,twoTh); } //user defined method amount() public static void amount(int ten,int twenty,int fifty,int hundred,int fiveH,int twoTh) { // calculate total amount int totalAmount = (ten * 10) + (twenty * 20) + (fifty * 50) + (hundred * 100) + (fiveH * 500) + (twoTh * 2000); // display total amount System.out.println("Total amount is " + totalAmount); } }
Output: Enter number of 10 rupees notes: 60 Enter number of 20 rupees notes: 44 Enter number of 50 rupees notes: 78 Enter number of 100 rupees notes: 83 Enter number of 500 rupees notes: 37 Enter number of 2000 rupees notes: 55 Total amount is 142180
Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease.
Related Java Programs: