【发布时间】:2013-09-25 01:10:01
【问题描述】:
我正在我的 Java 编程课程中编写一个程序。该程序是一个简单的 do/while 循环,它使用扫描程序类和一个布尔值启动读取来询问一些问题。当循环第一次迭代时,它可以正常工作,但是当它第二次迭代时,它会同时显示第一个问题和第二个问题,并且只允许我回答第二个问题。我希望这很清楚。任何人有任何见解?代码:
/*
* 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);
}
}
【问题讨论】:
-
我知道这与您的问题无关,但看在上帝的份上,请开始更好地命名您的课程:p
-
@redFIVE 班级被命名为 我可以看到教授喜欢这样,所以他可以在打印出来时知道谁的作业是谁的。
-
将项目的根文件夹命名为类似名称,而不是类名。评论块可以为添加名称、日期等内容创造奇迹