Computer Applications
Write a program in Java using a method Discount( ), to calculate a single discount or a successive discount. Use overload methods Discount(int), Discount(int,int) and Discount(int,int,int) to calculate single discount and successive discount respectively. Calculate and display the amount to be paid by the customer after getting discounts on the printed price of an article.
Sample Input:
Printed price: ₹12000
Successive discounts = 10%, 8%
= ₹(12000 - 1200)
= ₹(10800 - 864)
Amount to be paid = ₹9936
Java
User Defined Methods
111 Likes
Answer
import java.util.Scanner;
public class KboatSuccessiveDiscount
{
public void discount(int price) {
System.out.println("Amount after single discount = " + discount(price, 10));
System.out.println("Amount after successive discount = " + discount(price, 10, 8));
}
public double discount(int price, int d) {
double priceAfterDisc = price - price * d / 100.0;
return priceAfterDisc;
}
public double discount(int price, int d1, int d2) {
double priceAfterDisc1 = price - price * d1 / 100.0;
double priceAfterDisc2 = priceAfterDisc1 - priceAfterDisc1 * d2 / 100.0;
return priceAfterDisc2;
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter price: ");
int price = in.nextInt();
KboatSuccessiveDiscount obj = new KboatSuccessiveDiscount();
obj.discount(price);
}
}
Variable Description Table
Program Explanation
Output

Answered By
52 Likes
Related Questions
Which OOP principle implements method overloading?
How are the following data passed to a method?
- Primitive types
- Reference types
Write a program to input a three digit number. Use a method int Armstrong(int n) to accept the number. The method returns 1, if the number is Armstrong, otherwise zero(0).
Sample Input: 153
Sample Output: 153 ⇒ 13 + 53 + 33 = 153
It is an Armstrong Number.Write a program to input a number and check and print whether it is a 'Pronic' number or not. Use a method int Pronic(int n) to accept a number. The method returns 1, if the number is 'Pronic', otherwise returns zero (0).
(Hint: Pronic number is the number which is the product of two consecutive integers)Examples:
12 = 3 * 4
20 = 4 * 5
42 = 6 * 7