Java程序设计基础版前三章部分编程

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2-13

import java.util.Scanner;

publicclass Ex2_13{

publicstaticvoid main(String[] args) {

Scanner input=new Scanner(System.in);

System.out.println("Enter investment amount:");

double investmentamount=input.nextDouble();

System.out.println("Enter annually interest rate:");

double annuallyinterestrate=input.nextDouble();

System.out.println("Enter number of years");

int years=input.nextInt();

double Accumlatedvalue=investmentamount*pow(1+annuallyinterest rate/1200, years*12);

System.out.println("Accumlated value is" + Accumlatedvalue);

}

}

2-15

publicclass Ex2_15{

publicstaticvoid main(String[] args) {

int months=1;

double value=0;

double monthlyinterestrate=0.00417;

for(;months<=6;months++)

value=(100+value)*(1+monthlyinterestrate);

System.out.println("The value after six months is:"+value);

}

}

3-13

importjava.util.Scanner;

public class Ex3_13{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print(

"(0-single filer,1-married jointly,\n"+

"2-married separately,3-head of household)\n"+

"Enter the filing status: ");

int status=input.nextInt();

System.out.print("Enter the taxable income: ");

double income= input.nextDouble();

double tax=0;

if(status==0){

if(income<=8350)

tax=income*0.10;

else if(income<=33950)

tax=8350*0.10+(income-8350)*0.15;

else if(income<=82250)

tax=8350*0.10+(33950-8350)*0.15+(income-33950)*0.25;

else if(income<=171550)

tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+(income-82 250)*0.28;

else if(income<=372950)

tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82 250)*0.28+(income-171550)*0.33;

else

tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82 250)*0.28+(372950-171550)*0.33+(income-372950)*0.35;

}

if(status==1){

if(income<=16700)

tax=income*0.10;

else if(income<=67900)

tax=16700*0.10+(income-16700)*0.15;

else if(income<=137050)

tax=16700*0.10+(67900-16700)*0.15+(income-67900)*0.25;

else if(income<=208850)

tax=16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+(income -137050)*0.28;

else if(income<=372950)

tax=16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+(208850 -137050)*0.28+(income-208850)*0.33;

else

tax=16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+(208850 -137050)*0.28+(372950-208850)*0.33+(income-372950)*0.35;

}

if(status==2){

if(income<=8350)

tax=income*0.10;

else if(income<=33950)

tax=8350*0.10+(income-33950)*0.15;

else if(income<=68525)

tax=8350*0.10+(33950-8350)*0.15+(income-33950)*0.25;

else if(income<=104425)

tax=8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+(income-68 525)*0.28;

else if(income<=186475)

tax=8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68 525)*0.28+(income-104425)*0.33;

else

tax=8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68 525)*0.28+(income-104425)*0.33+(income-186475)*0.35;

}

if(status==3){

if(income<=11950)

tax=income*0.10;

else if(income<=45500)

tax=11950*0.10+(income-11950)*0.15;

else if(income<=117450)

tax=11950*0.10+(45500-11950)*0.15+(income-45500)*0.25;

else if(income<=190200)

tax=11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+(income -117450)*0.28;

else if(income<=372950)

tax=11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+(372950 -117450)*0.28+(income-190200)*0.33;

else

tax=11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+(372950 -117450)*0.28+(income-190200)*0.33+(income-372950)*0.35;

}

if(status>3||status<0){

相关文档
最新文档