
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.

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();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.