gpt4 book ai didi

java - 运行应用程序时似乎无法输入任何整数值?它只显示结果 "grade c"

转载 作者:太空宇宙 更新时间:2023-11-04 09:05:12 24 4
gpt4 key购买 nike

某公司的薪资方案如下:

Salary range for grade A: $700 - $899

Salary range for grade B: $600 - $799

Salary range for grade 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();
}

关于java - 运行应用程序时似乎无法输入任何整数值?它只显示结果 "grade c",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60292173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com