Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a final double to my program
    primarykey
    data
    text
    <p>I'm attempting to make a few doubles in my code final. I've tried a few methods such as "public static final," just "final," etc.</p> <pre><code>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))); } } </code></pre> <p>These are what I would like to make final:</p> <pre><code> double fedinctax = .15; double statetax = .035; double socsectax = .0575; double meditax = .0275; double penplan = .05; double healthins = 75; </code></pre> <p>I just am not sure where I'm supposed to put the final lines in the code, or how they are supposed to be written</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload