KnowledgeBoat Logo
|

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:

SaleCommission
Up to ₹50,0005% on sales value
More than ₹50,000 and up to ₹80,0008% on sales value
More than ₹80,000 and up to ₹1,00,00010% on sales value
More than ₹1,00,00012% 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.

Java

Java Classes

4 Likes

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

BlueJ output of 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: 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.

Answered By

1 Like


Related Questions