我试图在我的代码决赛中做几个双打。我尝试了一些方法,例如“public static final”,只是“final”等。
import java.util.Scanner;
import java.text.DecimalFormat;
public class Pay_stub {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
double fedinctax = .15;
double statetax = .035;
double socsectax = .0575;
double meditax = .0275;
double penplan = .05;
double healthins = 75;
double hoursworked;
double hourlyrate;
double netpay;
double grosspay;
String firstname, lastname;
System.out.println("Enter employee first name: ");
firstname = input.next();
System.out.println("Enter employee last name: ");
lastname = input.next();
System.out.println("Enter hours worked: ");
hoursworked = input.nextDouble();
System.out.println("Enter hourly rate: ");
hourlyrate = input.nextDouble();
grosspay = hoursworked * hourlyrate;
double fit = grosspay * fedinctax;
double st = grosspay * statetax;
double sst = grosspay * socsectax;
double mmt = grosspay * meditax;
double pp = grosspay * penplan;
double total = fit + st + sst + mmt + pp + healthins;
double net = grosspay - total;
System.out.println(firstname + lastname + "'s monthly paycheck is: ");
System.out.println("Gross Pay: " + (df.format(grosspay)));
System.out.println("Federal Income Tax: " + fit);
System.out.println("State Tax: " + st);
System.out.println("Social Security Tax: " + sst);
System.out.println("Medicare/Medicaid Tax: " + mmt);
System.out.println("Pension Plan: " + pp);
System.out.println("Health Insurance: " + healthins);
System.out.println("Net Pay: " + (df.format(net)));
}
}
这些是我想做的最终结果:
double fedinctax = .15;
double statetax = .035;
double socsectax = .0575;
double meditax = .0275;
double penplan = .05;
double healthins = 75;
我只是不确定我应该将最后几行放在代码中的哪个位置,或者它们应该如何编写