公司的薪酬方案如下:
A级薪金范围:$ 700-$ 899
B级薪金范围:$ 600-$ 799
C级薪资范围:$ 500-$ 649
薪水在600美元至649美元之间的人,如果他的功绩点低于10,则为C级;否则,他是B级。薪水在700美元至799美元之间的人,如果他的功绩点在20以下,则为B级。 ,他处于A年级。编写一个程序来读取一个人的薪水和优点,并显示他的成绩。
package trydontquit1;
import java.util.*;
public class tryagain {
public int salary;
public int merits;
public class employee {
employee (int inputsalary, int inputmerits){
salary = inputsalary;
merits = inputmerits;
}
//grade the input in regard to salary and merits point
void grade() {
int c = 0, b = 0, a = 0;
c = salary - 600;
b = salary - 700;
a = salary - 800;
if (c <= 49 && merits < 10)
System.out.println("Grade = C");
else if (b <= 99 && merits < 20)
System.out.println("Grade = B");
else if (b > 99)
System.out.println("Grade = A");
}
}
//to instantiate an object and to grade employee
public static void main(String[] args) {
int x=0, y=0;
System.out.println("Grading of employee");
tryagain tryagain = new tryagain();
employee sc = tryagain.new employee(x,y);
System.out.println("Please enter salary\n");
Scanner i = new Scanner(System.in);
System.out.println("Please enter merits\n");
Scanner j = new Scanner(System.in);
sc.grade();
}
}
最佳答案
似乎您没有阅读输入。您需要更改main
方法中的代码流。请检查以下代码:
public static void main(String[] args) {
int x = 0, y = 0;
System.out.println("Grading of employee");
tryagain tryagain = new tryagain();
Scanner i = new Scanner(System.in);
System.out.println("Please enter salary\n");
x = i.nextInt();
System.out.println("Please enter merits\n");
y = i.nextInt();
employee sc = tryagain.new employee(x, y);
sc.grade();
}