HW7.12

import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
double[] rates = {0.10, 0.15, 0.25, 0.28, 0.33, 0.35};
int[][] brackets =
{
{8350, 33950, 82250, 171550, 372950},
{16700, 67900, 137050, 208850, 372950},
{8350, 33950, 68525, 104425, 186475},
{11950, 45500, 117450, 190200, 372950}
};
Scanner input = new Scanner(System.in);
System.out.print("Input the number of the people(0 to 3): ");
int person = input.nextInt();
System.out.print("Input the income: ");
int income = input.nextInt();
input.close();
double tax = computeTax(brackets, rates, person, income);
System.out.println("The tax is " + tax);
}
public static double computeTax(int[][] brackets, double[] rates, int person, int income)
{
int largerCount = 0;
for(int i = 0; i < brackets[person].length; i++)
{
if(brackets[person][i] < income)
largerCount++;
else
break;
}
if(largerCount == 0)
return 0;
else if(largerCount == 1)
return (income - brackets[person][0]) * rates[0];
else
{
int tax = 0;
tax += (income - brackets[person][largerCount - 1]) * rates[largerCount];
largerCount--;
while(largerCount > 0)
{
tax += (brackets[person][largerCount] - brackets[person][largerCount - 1]) * rates[largerCount];
largerCount--;
}
tax += brackets[person][0] * rates[0];
return tax;
}
}
}
HW7.12的更多相关文章
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
- AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决
原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...
- 读过MBA的CEO更自私?《哈佛商业评论》2016年第12期。4星
老牌管理杂志.每期都值得精度.本期我还是给4星. 以下是本书中的一些内容的摘抄: 1:他们发现在Airbnb上,如果客人姓名听起来像黑人,那么比名字像白人的客人的接受率会低16%.#45 2:对立组织 ...
- 12个小技巧,让你高效使用Eclipse
集成开发环境(IDE)让应用开发更加容易.它们强调语法,让你知道是否你存在编译错误,在众多的其他事情中允许你单步调试代码.像所有的IDE一 样,Eclipse也有快捷键和小工具,这些会让您感觉轻松许多 ...
- 第12章 Linux系统管理
1. 进程管理 1.1 进程查看 (1)进程简介 进程是正在执行的一个程序或命令(如ls命令也是一个进程),每个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. (2)进程管理的作用 ...
- Jexus Web Server 完全傻瓜化图文配置教程(基于Ubuntu 12.04.3 64位)[内含Hyper-v 2012虚拟机镜像下载地址]
1. 前言 近日有感许多新朋友想尝试使用Jexus,不过绝大多数都困惑徘徊在Linux如何安装啊,如何编译Mono啊,如何配置Jexus啊...等等基础问题,于是昨日向宇内流云兄提议,不如搞几个配置好 ...
- CSharpGL(12)用T4模板生成CSSL及其renderer代码
CSharpGL(12)用T4模板生成CSSL及其renderer代码 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立 ...
随机推荐
- Hibernate 异常 —— No CurrentSessionContext configured
在使用 SessionFactory 的 getCurrentSession 方法时遇到如下异常 “No CurrentSessionContext configured ” 原因是: 在hibern ...
- android测试常用的命令介绍
- gridview 单击行时如何让SelectedIndexChanging事件响应
在gridview控件上单击行的时候,是不触发SelectedIndexChanging事件的,那么想要单击时触发SelectedIndexChanging事件时怎么做呢? 我是这样做的: 在grid ...
- 用vi修改文件,保存文件时,提示“readonly option is set”的解决方法
来源:http://superuser.com/questions/300500/ubuntu-unable-to-edit-bashrc-file-because-of-readonly This ...
- 【转载】关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
原文在: https://yq.aliyun.com/articles/40353 这里有转载:http://www.cnblogs.com/zhao1949/p/5652167.html 先来一段S ...
- List排序的两种简便方式
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace List ...
- ASP.NET中动态获取数据使用Highcharts图表控件【Copy By Internet】
具体实现的效果如图:
- gitflow workflow
https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow Dream big, work smart, ...
- mac 安装使用 webp 来压缩图片
学习性网站: https://developers.google.com/speed/webp/docs/cwebp http://www.w3ctech.com//topic/1672 https: ...
- maven的settings.xml详细说明
转自:http://writeblog.csdn.net/ <?xml version="1.0" encoding="UTF-8"?> <s ...