Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views3 pages

Type 4 Method

The document contains two Java programs that calculate financial figures based on user input. The first program computes a sales commission based on the sales amount, applying a rate of 25% for amounts over Rs. 100,000 and 15% otherwise. The second program calculates the total payable amount for a product based on quantity and price, applying a 12% discount if the total exceeds Rs. 3,000.

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Type 4 Method

The document contains two Java programs that calculate financial figures based on user input. The first program computes a sales commission based on the sales amount, applying a rate of 25% for amounts over Rs. 100,000 and 15% otherwise. The second program calculates the total payable amount for a product based on quantity and price, applying a 12% discount if the total exceeds Rs. 3,000.

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Type 4 method: parameterized with return value

1. Write a Java program to input the sales amount. Define a method


calculateCommission(double amount) that receives the sales amount as an
argument and returns the commission to the main method.
 If the sales amount is more than Rs. 100000, the commission is 25% of
the amount.
 Otherwise, the commission is 15% of the amount.

import java.util.Scanner;
public class CommissionCalculator
{
public static double calculateCommission(double salesAmount)
{
double commission;
if (salesAmount > 100000)
{
commission = 0.25 * salesAmount;
} else {
commission = 0.15 * salesAmount;
}
return commission;
}
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the sales amount: Rs. ");
double salesAmount = sc.nextDouble();
double commission = calculateCommission(salesAmount);
System.out.println("The commission is: Rs. " + commission);
}
}
Variable Description
Variable Name Data Type Description
sc Scanner Scanner object used to take input from the user
salesAmount double The sales amount entered by the user
commission double The calculated commission based on the sales amount

2. Write a program in Java to input the quantity and price per unit of a product.
Define a method calculatePayableAmount(int quantity, double price) that
receives the quantity and price as arguments and returns the payable amount
after applying a discount.
If the total amount (quantity × price) is more than Rs. 3000, a discount of 12%
is applied. Otherwise, no discount is given. Display the payable amount from
the main() method.

import java.util.Scanner;
public class ProductBill
{
public static double calculatePayableAmount(int quantity, double price)
{
double amount = quantity * price;
double reduction = 0;
if (amount > 3000)
{
reduction = 0.12 * amount;
}

double payableAmount = amount - reduction;


return payableAmount;
}

public static void main()


{
Scanner sc = new Scanner(System.in);
System.out.print("Enter quantity: ");
int quantity = sc.nextInt();
System.out.print("Enter price per unit: Rs. ");
double price = sc.nextDouble();
double payable = calculatePayableAmount(quantity, price);
System.out.println("Total payable amount after reduction (if any): Rs. " +
payable);
}
}

You might also like