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多个独立 ...
随机推荐
- 判断线段相交 -- 51nod 1264 线段相交
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264 三角形的有向面积:a.x*b.y+b.x*c.y+c.x*a.y ...
- CF 314C Sereja and Subsequences(树状数组)
题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...
- 如何获取supersocket的源代码
源代码的地址:https://github.com/kerryjiang/SuperSocket 安装git之后,可以使用命令行git clone https://github.com/kerryji ...
- jboss jndi配置部分参数详解
使用的是jboss7.1.1, jndi的配置在$JBOSS_HOME/standalone/configuration/standalone.xml中进行配置.配置jndi时有很多参数,解释下用到的 ...
- UESTC 1074 秋实大哥搞算数 栈模拟
秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- hibernate annotation配置经验
1.将annotation写在entity类文件的get方法上面
- Incorrect key file for table '/tmp/#sql_882_0.MYI'; try to repair it
修表方法如下: 一法:. check table 和 repair table 方法1,进入Mysql 的Dos控制台,输入密码进入 2,use database;(你的数据库名) 3, check ...
- HDU 3294 (Manacher) Girls' research
变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...
- mysql 调用带返回值的存储过程
存储过程: create procedure proc_t(out uname varchar(50),out upwd varchar(50),in uid int) BEGIN select na ...
- Android用自己的app替换Launcher
/*********************************************************************** * Android用自己的app替换Launcher ...