Javaのプログラミングクラスでプログラムを書いています。プログラムは単純な do/while ループで、スキャナー クラスを使用していくつかの質問をし、ブール値を使用してプライミング読み取りを行います。ループが最初に繰り返されるときは正常に機能しますが、2 回目に繰り返されると、最初の質問と 2 番目の質問が同時に表示され、2 番目の質問にしか回答できなくなります。これが明確であることを願っています。誰にも洞察がありますか?コード:
/*
* Programmed By: Cristopher Ontiveros
* Date: 9/19/13
* Description: Compute weekly salary and witholding for employees
*/
package project.one.cristopher.ontiveros;
import java.util.Scanner;
public class ProjectOneCristopherOntiveros {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String fName, lName;
double rate=0, wPay=0, withholding=0;
int option = 0;
boolean badval = true;
System.out.println("Welcome to the Pay Calculator");
do{
System.out.println("Enter employee first name: ");
fName = sc.nextLine();
System.out.println("Enter employee last name: ");
lName = sc.nextLine();
System.out.println("Enter employee hourly rate: ");
rate = sc.nextDouble();
wPay = (rate * 40);
withholding = (wPay * .20);
System.out.println("Employee " + fName + " " + lName + "\nHourly Rate: " + rate + "\nWeekly Pay: " + wPay + "\nWithholding Amount: " + withholding);
System.out.println("Would you like to enter another employee? (1 = yes, 2 = no)");
option = sc.nextInt();
sc.nextLine()
if(option == 1){
badval = true;
} else {
badval = false;
}
}while(badval);
}
}