出于某种原因,我的陈述一直延续到下一行,而没有做它应该做的事情。
package Employee;
import java.util.Scanner;
import static java.lang.System.out;
public class EmployeeTest {
public static void main (String args[]) {
out.println ("Welcome to employee storer: ");
Scanner imput = new Scanner (System.in);
Employee employee1 = new Employee();// Creates an employee
Employee employee2 = new Employee();
out.println ("Please enter first name: ");
String fName = imput.nextLine(); //reads keyboard
employee1.setfName(fName);// sets first name
out.println("please enter last name: ");
String lName = imput.nextLine();//reads keyboard
employee1.setlName(lName);// sets second name
out.println("Please enter pay: ");
double pay = imput.nextDouble();//reads keyboard
employee1.setPay(pay);//sets the pay
out.println ("Please enter first name: ");
String fName1 = imput.nextLine(); //reads keyboard
employee2.setfName(fName1);// sets first name
out.println("please enter last name: ");
String lName1 = imput.nextLine();//reads keyboard
employee2.setlName(lName1);// sets second name
out.println("Please enter pay: ");
double pay1 = imput.nextDouble();//reads keyboard
employee2.setPay(pay1);//sets the pay
employee1.printer();// prints the info
employee2.printer();// same here
employee1.raise();
}
}
我的问题是第二个 fName 输入,它永远不会从控制台获得输入,它最终看起来像这样
"Welcome to employee storer:
Please enter first name:
Jake
please enter last name:
Smith
Please enter pay:
100
Please enter first name:
please enter last name:
Jake
Please enter pay:
100
The employee Jake Smith yearly salary is: 1200.0
The employee Jake yearly salary is: 1200.0
Your raise is: 120.0
Your new yearly pay is: 1200.0120.0"
我的方法类如下所示: package Employee; 导入静态 java.lang.System.out;
public class Employee {
private String fName;
private String lName;
private double pay;
public void payCheck() {
if (pay > 0 )
pay = 0;
}
public double yearly() {
double overall = pay * 12;
return overall;
}
public void printer() {
out.println( " The employee " + fName + " " + lName +
" yearly salary is: " + pay * 12 );
}
public void raise() {
double year = pay * 12;
double increase = .1;
double raise = increase * year;
out.println("Your raise is: " + raise );
out.print("Your new yearly pay is: " + year + raise);
}
// Getters and setters
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public double getPay() {
return pay;
}
public void setPay(double pay) {
this.pay = pay;
}
}
最后的年薪我也得到了一个奇怪的输出。不太确定为什么,任何帮助将不胜感激。