day016 Java小作业
赶上课程布置的作业,更新几个java小程序,老师要求还要写伪代码,前面更新了如何写伪代码但是写的还需要再锻炼就不展示了。
1.计算税费
Problem: Computing Taxes
The United States federal personal income tax is calculated based on filing status and taxable income. There are four filing statuses: single filers, married filing jointly, married filing separately, and head of household. The tax rates vary every year. Table 3.2 shows the rates for 2009. If you are, say, single with a taxable income of $10,000, the first $8,350 is taxed at 10% and the other $1,650 is taxed at 15%. So, your tax is $1,082.5
you are to write a program to compute personal income tax. Your program should prompt the user to enter the filing status and taxable income and compute the tax. Enter 0 for single filers, 1 for married filing jointly, 2 for married filing separately, and 3 for head of household. Your program computes the tax for the taxable income based on the filing status.
下面是这个程序的完整代码:
/*
*@zzhao
*/
package HelloJava;
import java.util.Scanner;
public class ComputingTaxes
{
public static void main(String[] args)
{
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter filing status
System.out.print(
"(0-single filer, 1-married jointly or qualifying widow(er), "
+ "\n2-married separately, 3-head of household)\n" +
"Enter the filing status: ");
int status = input.nextInt();
// Prompt the user to enter taxable income
System.out.print("Enter the taxable income: ");
double income = input.nextDouble();
// Compute tax
double tax = 0;
if (status ==