I have a program that takes input(id, name, designation, salary) for employee details and gives them a grade based on salary.
Here is my code:
public class Solution {
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
String id = reader.nextLine();
String employeeName = reader.nextLine();
String designation = reader.nextLine();
String salary = reader.nextLine();
String grade;
int yee = Integer.parseInt(salary);
if(yee <= 20000)
{
grade = "D";
}
else if(yee <= 50000)
{
grade = "C";
}
else if(yee <= 100000)
{
grade = "B";
}
else
{
grade = "A";
}
System.out.println("Employee grade is:");
System.out.println(grade + " Grade");
System.out.println("Employee details are:");
System.out.println("Employee ID=" + id);
System.out.println("Employee Name=" + employeeName);
System.out.println("Designation=" + designation);
System.out.println("Salary=" + salary);
}
}
Current Input :
1, CodeZinger, Software Developer, 80000
Current Output :
Employee grade: A
Employee details:
ID=1
Name = CodeZinger
Designation= Software Developer
Salary= 80000
While my code for this program works, I now need to add methods:
void getEmployee
to get the input void showGrade
to display the grade and void showEmployee
to print the details for the employee. Can someone give me a basic outline of what this would look like? I also need some more resources concerning objects/classes because I am still learning this concept.
You just need to convert your each logic into functions and then call those functions via making an object of the class
Solution so=new Solution() ;
so.getEmployee();
......
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.