19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

100 Chapter 3 Selections<br />

input status<br />

input in<strong>com</strong>e<br />

<strong>com</strong>pute tax<br />

exit program<br />

display output<br />

LISTING 3.6<br />

ComputeTax.java<br />

1 import java.util.Scanner;<br />

2<br />

3 public class ComputeTax {<br />

4 public static void main(String[] args) {<br />

5 // Create a Scanner<br />

6 Scanner input = new Scanner(System.in);<br />

7<br />

8 // Prompt the user <strong>to</strong> enter filing status<br />

9 System.out.print(<br />

10 "(0-single filer, 1-married jointly or qualifying widow(er),<br />

11 + "\n2-married separately, 3-head of household)\n" +<br />

12 "Enter the filing status: ");<br />

13 int status = input.nextInt();<br />

14<br />

15 // Prompt the user <strong>to</strong> enter taxable in<strong>com</strong>e<br />

16 System.out.print("Enter the taxable in<strong>com</strong>e: ");<br />

17 double in<strong>com</strong>e = input.nextDouble();<br />

18<br />

19 // Compute tax<br />

20 double tax = 0;<br />

21<br />

22 if (status == 0) { // Compute tax for single filers<br />

23 if (in<strong>com</strong>e

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!