Employee Salaries

Employee Salaries

Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee with a name and an initial salary. The method salarychange(amount) will increase or decrease the salary by the specified amount. The method quit() will set the salary of the Employee to zero. The method getinfo() will return the current salary of the Employee. Write a program that lets a user create Employee objects and adjust their salaries (by raises or pay cuts). After each user command, the program must print the current salary of the Employee.

Note: A simple interface is sufficient to get user input, nothing fancy is required.

View Answers

February 21, 2012 at 4:11 PM

import java.util.*;

class EmployeeSalaries {
        static Scanner input = new Scanner(System.in);
        String name;
        static int amt,sal=0;

        EmployeeSalaries(String name, int sal) {
                this.name = name;
                this.sal = sal;
        }
        public void setName(String name){
            this.name=name;
        }

        public static void setSal(int sal){
            sal=sal;
        }

       static int increase() {
                System.out.print("Enter amount to increase:");
                amt = input.nextInt();
                if (amt < 0) {
                        System.out.println("Invalid Amount");
                        return 1;
                }
                sal = sal + amt;
                return 0;
        }

       static int decrease() {
                System.out.println("Your Balance=" + sal);
                System.out.print("Enter amount to decrease:");
                amt = input.nextInt();
                if (sal < amt) {
                        System.out.println("Not sufficient balance.");
                        return 1;
                }
                if (amt < 0) {
                        System.out.println("Invalid Amount");
                        return 1;
                }
                sal = sal - amt;
                return 0;
        }

        void getInfo() {
                System.out.println("Name:" + name);
                System.out.println("Balance:" + sal);

        }

        void quit() {
                EmployeeSalaries.setSal(0);
        }
        void salarychange(){
             int menu;
                System.out.println("1. Increase Salary Amount");
                System.out.println("2. Decrease Salary Amount");

                boolean quit = false;
                        System.out.print("Please enter your choice: ");
                        menu = input.nextInt();
                        switch (menu) {
                        case 1:
                                EmployeeSalaries.increase();
                                break;

                        case 2:
                                EmployeeSalaries.decrease();
                                break;

                        }
        }
        public static void main(String args[]) {
                System.out.println("Enter your Name: ");
                String nn = input.nextLine();
                System.out.println("Enter Initial Salary: ");
                int sal = input.nextInt();
                EmployeeSalaries b1 = new EmployeeSalaries(nn,sal);
                b1.salarychange();
                b1.getInfo();

        }
}









Related Tutorials/Questions & Answers:
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Advertisements
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Employee Salaries
Employee Salaries  Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee... the salary of the Employee to zero. The method getinfo() will return the current
Adding an employee
Adding an employee  coding for adding an employee
Add Employee
Add Employee  coding for adding an employee
EMPLOYEE - SQL
EMPLOYEE  CALCULATE EMPLOYEE SALARY  Hi friend, Please give the full details of Problem. Thanks
Employee form
Employee form  In employee form emp Id id after any data iserted is incremented for oher data insertion. insert, delete, update buttons when we cleak the select buttoun then the created table data iserted automaticaly
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I... and one report like details of employee thanks
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I... and one report like details of employee thanks
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I... and one report like details of employee thanks
application for an Employee
: in this page it should modify employee data and persist in DB 3.DISPLAY
employee progarm
employee progarm  Hai, I have developed a code for an employee program by using jtext fields and buttons,it has no errors but while we are compiling it it is saying that "Exception in thread "main
Employee Management System
Employee Management System  coding for employee management system
coding for employee management system
coding for employee management system  coding for employee management system
Employee Management System
Employee Management System  coding for employee management system
display the employee name
display the employee name  when i will select one employee designation based on that employee designation display the particular designation employee name display in another select box how it possible using servlet and mysql
Employee Management Sysem
Employee Management Sysem  coding for Daoclass Login Page Validation
program on employee details
program on employee details  to write a program on displaying the employee details like empid,empname,wonno,location,leave type by using the text fields in java swings
Auto Generated Employee ID
Auto Generated Employee ID  Hello Everyone I want to generate an ID like (SCS-0001) and then it should be auto incremented each time a new employee add page is opens. I am using My Sql database
compute the daily wage of an employee.
compute the daily wage of an employee.   B. Write a JavaScript program that would input Employee Name, Rate per hour, No. of hours worked and will compute the daily wage of an employee. If the number of hours worked exceeds
compute the daily wage of an employee.
compute the daily wage of an employee.   B. Write a JavaScript program that would input Employee Name, Rate per hour, No. of hours worked and will compute the daily wage of an employee. If the number of hours worked exceeds
Generate Employee ID (SCS-0001,SCS-0002......)
Generate Employee ID (SCS-0001,SCS-0002......)  Hello everyone i am beginner in java and i am working on my major project I want to generate bill number and employee number like SCS-0001 and so on and bill number like SCS/'date
Employee Details - JSP-Servlet
Employee Details  Respected Sir/Madam, Thanks for your response. Regarding that alert box problem what I have decided is to include the contents of process.jsp in the home page itself without any submit button
store the employee ID,name,login time and logout time of the employee in database
store the employee ID,name,login time and logout time of the employee in database  hello...I want to store the employee ID,name,login time and logout time of the employee along with the time difference between these two
to write a program to display the employee details..
to write a program to display the employee details..  To dipslay the employee details like empid,empname,salary,wonno bye using java swings.by... the employee details.please send me the code .it's urgent.send me as soon as possible
how to calculate the employee tax - JSP-Servlet
how to calculate the employee tax  How to calculate the employee tax.Can u please send to me calculation tables
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-id'
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-id'  ...: No module named 'odoo10-addon-hr-employee-id' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-id' error? Thanks
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-seniority'
ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-seniority' ...: ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-seniority' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-hr-employee-seniority
ModuleNotFoundError: No module named 'odoo10-addon-partner-employee-quantity'
ModuleNotFoundError: No module named 'odoo10-addon-partner-employee-quantity...: ModuleNotFoundError: No module named 'odoo10-addon-partner-employee-quantity' How...-employee-quantity' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-id'
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-id'  ...: No module named 'odoo11-addon-hr-employee-id' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-id' error? Thanks
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-firstname'
ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-firstname' ...: ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-firstname' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-hr-employee-firstname
ModuleNotFoundError: No module named 'odoo11-addon-stock-request-employee'
ModuleNotFoundError: No module named 'odoo11-addon-stock-request-employee' ...: ModuleNotFoundError: No module named 'odoo11-addon-stock-request-employee' How to remove...-employee' error? Thanks   Hi, In your python environment you have
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-document'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-document' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-document' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-document'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-firstname
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-health'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-health' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-health' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-health' error
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-id'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-id'  ...: No module named 'odoo12-addon-hr-employee-id' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-id' error? Thanks
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-language'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-product'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-service'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-service' ...: ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-service' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-service'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-ssn'
ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-ssn'  ...: No module named 'odoo12-addon-hr-employee-ssn' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-hr-employee-ssn' error
ModuleNotFoundError: No module named 'odoo12-addon-partner-employee-quantity'
ModuleNotFoundError: No module named 'odoo12-addon-partner-employee-quantity...: ModuleNotFoundError: No module named 'odoo12-addon-partner-employee-quantity' How...-employee-quantity' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-benefit'
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-benefit' ...: ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-benefit' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-benefit' error
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-gravatar'
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-gravatar' ...: ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-gravatar' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-gravatar'
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-product'
ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-product' ...: ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-product' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-hr-employee-product' error

Ads