English 中文(简体)
我可以发现这种很容易的法典中的逻辑错误。 Java语,简单的数学方案
原标题:I can t find the logic error in this easy piece of code. Java language, simple math program
  • 时间:2011-11-23 19:31:43
  •  标签:
  • java

This is a program that is supposed to prompt user for hours worked and hourly rate of pay, and calculate and display their net pay (including taxes deducted).

我可以从事这项工作,但是,如果我的逻辑错误,我会得到错误的回答,而且可以说出。 请伸出手,利用你的专长。 感谢STACK FM/FLOW

import java.util.*;
public class HA8PayrollErr {
    public static void main(String[] args){
    float hoursWorked;
    float ratePay;

    float basePay = 0.0f;
    float overtimePay = 0.0f;
    float totalPay = 0.0f;
    float taxDeducted = 0.0f;
    float netPay = 0.0f;

    int doAgain = 0;
    Scanner input = new Scanner(System.in);

    do {
        System.out.println("Enter hours worked this week"); 
        hoursWorked = input.nextFloat();
        System.out.println("Enter rate of pay");
        ratePay = input.nextFloat();

        if (hoursWorked > 37.5f) {
            basePay = 37.5f*ratePay;
            overtimePay = (hoursWorked - 37.5f) * ratePay * 1.5f;
        } else {
            basePay = hoursWorked * ratePay;
        }
        totalPay = basePay + overtimePay;
        if (totalPay < 1000) 
            taxDeducted = 0;
        else if (totalPay > 2000)
            taxDeducted = totalPay *0.30f;
        else taxDeducted = totalPay * 0.20f;

        netPay = totalPay - taxDeducted;

        System.out.println ("Base pay is : $" + basePay);
        System.out.println ("Overtime pay is : $"+ overtimePay);
        System.out.println ("Tax deducted is : $" + taxDeducted);
        System.out.println ("Net pay is : $" + netPay);

        System.out.println ("Enter 0 to repeat, or 1 to quit: ");
        doAgain = input.nextInt();
    } while (doAgain == 0);
    }
}
最佳回答

您不重新计算加班时间 支付每艘轮胎。 因此,如果此人没有加班时间,而是在以前退休时,价值将再次增加。

if (hoursWorked > 37.5f) {
    basePay = 37.5f*ratePay;
    overtimePay = (hoursWorked - 37.5f) * ratePay * 1.5f;
} else {
    basePay = hoursWorked * ratePay;
    overtimePay = 0.0f;
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签