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多个独立 ...
随机推荐
- The GPG keys listed not correct
The GPG keys listed for the "Extra Packages for Enterprise Linux 5 - x86_64" repository ar ...
- [Topcoder]ZigZag(dp)
题目链接:https://community.topcoder.com/stat?c=problem_statement&pm=1259&rd=4493 题意:给一串数字,求出最长的波 ...
- URAL1513. Lemon Tale(dp)
1513 这题好久之前就看过了,悲催的是当时看题解都没看懂,今天又看了看so easy... n个B里不能出现超过连续k个L的情况 一维递推就可以 两种情况 1.dp[i] += dp[i-1] 在i ...
- 简单了解JAVA8的新特性
JAVA8新特性会颠覆整个JAVA程序员的编程习惯 甚至如果您坚守JAVA7之前的编程习惯,今后你看比较年轻的程序员写的JAVA代码都会无法理解 所以为了保证不脱钩,我觉得有必要学习JAVA8的新特性 ...
- [转]C#中的?和??
原文链接:http://msdn.microsoft.com/zh-tw/library/2cf62fcy%28VS.80%29.aspx 使用可為 Null 的型別 (C# 程式設計手冊) Visu ...
- How to begin with the webpage making
1.网页制作三剑客必须要会使用.(dreamweaver /fireworks/flash)2.学习些最基层的html语言的知识,3.在学习一些基本的html标签(要多加练习哦)4.先试着用表格进行 ...
- 一些纯css3写的公司logo
随着对css3了解得越深入,越来越发现了css3的强大.css3不但能完成一些基本的特效如圆角阴影等,还能借助动画技术实现一些复杂的动画,能替代很多以前js才能完成的工作,css3的作用还不止于此 ...
- (转)每天一个Linux命令(5): rm
http://www.cnblogs.com/peida/archive/2012/10/26/2740521.html 昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和 ...
- foreach的指针问题
从代码: $arr = array(,,,,); echo '$arr = array(1,2,3,4,5)','<br>'; foreach($arr as $key => &am ...
- 使用C#代码审批/转签K2 Blackpearl流程
转:http://www.cnblogs.com/dannyli/archive/2011/08/02/2125302.html 以下是使用代码审批.转签k2 blackpearl流程,初探K2 Bl ...