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.
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

Answered By
1 Like
Related Questions
The correct statement to create an object named mango of class fruit:
- Fruit Mango= new fruit();
- fruit mango = new fruit();
- Mango fruit=new Mango();
- fruit mango= new mango();
Define a class with the following specifications:
Class name: Bank
Member variables:
double p — stores the principal amount
double n — stores the time period in years
double r — stores the rate of interest
double a — stores the amountMember methods:
void accept () — input values for p and n using Scanner class methods only.
void calculate () — calculate the amount based on the following conditions:Time in (Years) Rate % Upto 1⁄2 9 > 1⁄2 to 1 year 10 > 1 to 3 years 11 > 3 years 12 void display () — display the details in the given format.
Principal Time Rate Amount XXX XXX XXX XXXWrite the main method to create an object and call the above methods.