Computer Applications
Define a class 'COMMISSION' as described below:
String name — stores the employee's name
int emp_no — stores the employee number
int sal — store monthly sales value
Member methods
void input() — to input and store employee's name, number and monthly sales value.
void compute( ) — to calculate commission on sale as per the tariff given below:
| Sale | Commission |
|---|---|
| Up to ₹50,000 | 5% on sales value |
| More than ₹50,000 and up to ₹80,000 | 8% on sales value |
| More than ₹80,000 and up to ₹1,00,000 | 10% on sales value |
| More than ₹1,00,000 | 12% on sales value |
void display( ) — to display the details of employee's name with commission.
Write a main method to create object of a class and call the above member methods.
Answer
import java.util.Scanner;
public class Commission
{
String name;
int emp_no;
int sal;
double comm;
void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter employee name: ");
name = in.nextLine();
System.out.print("Enter employee number: ");
emp_no = in.nextInt();
System.out.print("Enter monthly sales value: ");
sal = in.nextInt();
}
void compute() {
if (sal <= 50000) {
comm = 5.0 / 100.0 * sal;
}
else if (sal <= 80000) {
comm = 8.0 / 100.0 * sal;
}
else if (sal <= 100000) {
comm = 10.0 / 100.0 * sal;
}
else {
comm = 12.0 / 100.0 * sal;
}
}
void display() {
System.out.println("Employee name: " + name);
System.out.println("Employee Number: " + emp_no);
System.out.println("Monthly Sales: " + sal);
System.out.println("Commission: " + comm);
}
public static void main(String args[]) {
Commission obj = new Commission();
obj.input();
obj.compute();
obj.display();
}
}Output
Related Questions
DTDC a courier company charges for the courier based on the weight of the parcel. Define a class with the following specifications:
Class name: courier
Member variables:
name – name of the customer
weight – weight of the parcel in kilograms
address – address of the recipient
bill – amount to be paid
type – 'D'- domestic, 'I'- international
Member methods:
void accept ( ) — to accept the details using the methods of the Scanner class only.
void calculate ( ) — to calculate the bill as per the following criteria:
Weight in Kgs Rate per Kg First 5 Kgs Rs.800 Next 5 Kgs Rs.700 Above 10 Kgs Rs.500 An additional amount of Rs.1500 is charged if the type of the courier is I (International)
void print ( ) — To print the details
void main ( ) — to create an object of the class and invoke the methods