私は自分のコード final でいくつかの double を作成しようとしています。「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;
コードの最終行をどこに配置すればよいのか、どのように記述すればよいのかわかりません