KnowledgeBoat Logo

Computer Applications

The basic salary of employees is undergoing a revision. Define a class called Grade_Revision with the following specifications:

Data MembersPurpose
String nameto store name of the employee
int basto store basic salary
int expnto consider the length of service as an experience
double incto store increment
double nbasto store new basic salary (basic + increment)
Member MethodsPurpose
Grade_Revision()constructor to initialize all data members
void accept()to input name, basic and experience
void increment()to calculate increment based on experience as per the table given below
void display()to print all the details of an employee
ExperienceIncrement
Up to 3 years₹1,000 + 10% of basic
3 years or more and up to 5 years₹3,000 + 12% of basic
5 years or more and up to 10 years₹5,000 + 15% of basic
10 years or more₹8,000 + 20% of basic

Write the main method to create an object of the class and call all the member methods.

Java

Java Constructors

57 Likes

Answer

import java.util.Scanner;

public class Grade_Revision
{
    private String name;
    private int bas;
    private int expn;
    private double inc;
    private double nbas;
    
    public Grade_Revision() {
        name = "";
        bas = 0;
        expn = 0;
        inc = 0.0;
        nbas = 0.0;
    }
    
    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name: ");
        name = in.nextLine();
        System.out.print("Enter basic: ");
        bas = in.nextInt();
        System.out.print("Enter experience: ");
        expn = in.nextInt();
    }
    
    public void increment() {
        if (expn <= 3)
            inc = 1000 + (bas * 0.1);
        else if (expn <= 5)
            inc = 3000 + (bas * 0.12);
        else if (expn <= 10)
            inc = 5000 + (bas * 0.15);
        else
            inc = 8000 + (bas * 0.2);
            
        nbas = bas + inc;
    }
    
    public void display() {
        System.out.println("Name: " + name);
        System.out.println("Basic: " + bas);
        System.out.println("Experience: " + expn);
        System.out.println("Increment: " + inc);
        System.out.println("New Basic: " + nbas);
    }
    
    public static void main(String args[]) {
        Grade_Revision obj = new Grade_Revision();
        obj.accept();
        obj.increment();
        obj.display();
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of The basic salary of employees is undergoing a revision. Define a class called Grade_Revision with the following specifications: Write the main method to create an object of the class and call all the member methods.

Answered By

22 Likes


Related Questions