




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
Chapter3Selections1Chapter3Selections1MotivationsIfyouassignedanegativevalueforradiusinListing2.1,ComputeArea.java,theprogramwouldprintaninvalidresult.Iftheradiusisnegative,youdon'twanttheprogramtocomputethearea.Howcanyoudealwiththissituation?2MotivationsIfyouassignedanObjectives3TodeclarebooleantypeandwriteBooleanexpressionsusingcomparisonoperators(§3.2).ToprogramAdditionQuizusingBooleanexpressions(§3.3).Toimplementselectioncontrolusingone-wayifstatements(§3.4)ToprogramtheGuessBirthdaygameusingone-wayifstatements(§3.5).Toimplementselectioncontrolusingtwo-wayifstatements(§3.6).Toimplementselectioncontrolusingnestedifstatements(§3.7).Toavoidcommonerrorsinifstatements(§3.8).Toprogramusingselectionstatementsforavarietyofexamples(BMI,ComputeTax,SubtractionQuiz)(§3.9-3.11).TogeneraterandomnumbersusingtheMath.random()method(§3.9).Tocombineconditionsusinglogicaloperators(&&,||,and!)(§3.12).Toprogramusingselectionstatementswithcombinedconditions(LeapYear,Lottery)(§§3.13-3.14).Toimplementselectioncontrolusingswitchstatements(§3.15).Towriteexpressionsusingtheconditionaloperator(§3.16).ToformatoutputusingtheSystem.out.printfmethodandtoformatstringsusingtheString.formatmethod(§3.17).Toexaminetherulesgoverningoperatorprecedenceandassociativity(§3.18).(GUI)Togetuserconfirmationusingconfirmationdialogs(§3.19).Objectives3TodeclarebooleanThebooleanTypeandOperatorsOfteninaprogramyouneedtocomparetwovalues,suchaswhetheriisgreaterthanj.Javaprovidessixcomparisonoperators(alsoknownasrelationaloperators)thatcanbeusedtocomparetwovalues.TheresultofthecomparisonisaBooleanvalue:trueorfalse.booleanb=(1>2);
4ThebooleanTypeandOperatorsComparisonOperators5Operator Name < lessthan <= lessthanorequalto> greaterthan>= greaterthanorequalto== equalto!= notequaltoComparisonOperators5OperatorProblem:ASimpleMathLearningTool6AdditionQuizRunThisexamplecreatesaprogramtoletafirstgraderpracticeadditions.Theprogramrandomlygeneratestwosingle-digitintegersnumber1andnumber2anddisplaysaquestionsuchas“Whatis7+9?”tothestudent.Afterthestudenttypestheanswer,theprogramdisplaysamessagetoindicatewhethertheansweristrueorfalse.Problem:ASimpleMathLearninOne-wayifStatementsif(boolean-expression){statement(s);}7if(radius>=0){area=radius*radius*PI;System.out.println("Thearea"+"forthecircleofradius"+radius+"is"+area);}One-wayifStatementsif(booleNote8Note8SimpleifDemo9SimpleIfDemoRunWriteaprogramthatpromptstheusertoenteraninteger.Ifthenumberisamultipleof5,printHiFive.Ifthenumberisdivisibleby2,printHiEven.SimpleifDemo9SimpleIfDemoRunProblem:GuessingBirthdayTheprogramcanguessyourbirthdate.Runtoseehowitworks.10GuessBirthdayProblem:GuessingBirthdayTheMathematicsBasisfortheGame19is10011inbinary.7is111inbinary.23is11101inbinary11MathematicsBasisfortheGameTheTwo-wayifStatementif(boolean-expression){statement(s)-for-the-true-case;}else{statement(s)-for-the-false-case;}12TheTwo-wayifStatementif(boif...elseExampleif(radius>=0){area=radius*radius*3.14159; System.out.println("Theareaforthe“+“circleofradius"+radius+"is"+area);}else{System.out.println("Negativeinput");}13if...elseExampleif(radius>=MultipleAlternativeifStatements14MultipleAlternativeifStatemTraceif-elsestatement15if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionisfalseanimationTraceif-elsestatement15if(sTraceif-elsestatement16if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionisfalseanimationTraceif-elsestatement16if(sTraceif-elsestatement17if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionistrueanimationTraceif-elsestatement17if(sTraceif-elsestatement18if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0gradeisCanimationTraceif-elsestatement18if(sTraceif-elsestatement19if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0ExittheifstatementanimationTraceif-elsestatement19if(sNoteTheelseclausematchesthemostrecentifclauseinthesameblock.20NoteTheelseclausematchesthNote,cont.Nothingisprintedfromtheprecedingstatement.Toforcetheelseclausetomatchthefirstifclause,youmustaddapairofbraces:inti=1;intj=2;intk=3;if(i>j){if(i>k)System.out.println("A");
}elseSystem.out.println("B");ThisstatementprintsB.21Note,cont.NothingisprintedCommonErrorsAddingasemicolonattheendofanifclauseisacommonmistake.if(radius>=0);{area=radius*radius*PI;System.out.println("Theareaforthecircleofradius"+radius+"is"+area);}Thismistakeishardtofind,becauseitisnotacompilationerrororaruntimeerror,itisalogicerror.Thiserroroftenoccurswhenyouusethenext-lineblockstyle.22WrongCommonErrorsAddingasemicoloTIP23TIP23CAUTION24CAUTION24Problem:AnImprovedMathLearningTool
Thisexamplecreatesaprogramtoteachafirstgradechildhowtolearnsubtractions.Theprogramrandomlygeneratestwosingle-digitintegersnumber1andnumber2withnumber1>number2anddisplaysaquestionsuchas“Whatis9–2?”tothestudent.Afterthestudenttypestheanswerintheinputdialogbox,theprogramdisplaysamessagedialogboxtoindicatewhethertheansweriscorrect.25SubtractionQuizProblem:AnImprovedMathLearProblem:BodyMassIndex
BodyMassIndex(BMI)isameasureofhealthonweight.Itcanbecalculatedbytakingyourweightinkilogramsanddividingbythesquareofyourheightinmeters.TheinterpretationofBMIforpeople16yearsorolderisasfollows:26ComputeBMIProblem:BodyMassIndexBodyProblem:ComputingTaxesTheUSfederalpersonalincometaxiscalculatedbasedonthefilingstatusandtaxableincome.Therearefourfilingstatuses:singlefilers,marriedfilingjointly,marriedfilingseparately,andheadofhousehold.Thetaxratesfor2009areshownbelow.27MarginalTaxRateSingleMarriedFilingJointlyorQualifiedWidow(er)MarriedFilingSeparatelyHeadofHousehold10%$0–$8,350$0–$16,700$0–$8,350$0–$11,95015%$8,351–$33,950$16,701–$67,900$8,351–$33,950$11,951–$45,50025%$33,951–$82,250$67,901–$137,050$33,951–$68,525$45,501–$117,45028%$82,251–$171,550$137,051–$208,850$68,525–$104,425$117,451–$190,20033%$171,551–$372,950$208,851–$372,950$104,426–$186,475$190,201-$372,95035%$372,951+$372,951+$186,476+$372,951+Problem:ComputingTaxesTheUSProblem:ComputingTaxes,cont.if(status==0){//Computetaxforsinglefilers}elseif(status==1){//Computetaxformarriedfilejointly}elseif(status==2){//Computetaxformarriedfileseparately}elseif(status==3){//Computetaxforheadofhousehold}else{//Displaywrongstatus}28ComputeTaxProblem:ComputingTaxes,contLogicalOperators29Operator Name ! not && and || or ^ exclusiveor
LogicalOperators29Operator NTruthTableforOperator!30TruthTableforOperator!30TruthTableforOperator&&31TruthTableforOperator&&31TruthTableforOperator||32TruthTableforOperator||32Examples33Hereisaprogramthatcheckswhetheranumberisdivisibleby2and3,whetheranumberisdivisibleby2or3,andwhetheranumberisdivisibleby2or3butnotboth:TestBooleanOperatorsRunExamples33HereisaprogramthTruthTableforOperator!34TruthTableforOperator!34TruthTableforOperator&&35TruthTableforOperator&&35TruthTableforOperator||36TruthTableforOperator||36TruthTableforOperator^37TruthTableforOperator^37Examples38System.out.println("Is"+number+"divisibleby2and3?"+((number%2==0)&&(number%3==0)));
System.out.println("Is"+number+"divisibleby2or3?"+((number%2==0)||(number%3==0)));
System.out.println("Is"+number+"divisibleby2or3,butnotboth?"+((number%2==0)^(number%3==0)));TestBooleanOperatorsRunExamples38System.out.println("The&and|OperatorsSupplementIII.B,“The&and|Operators”39CompanionWebsiteThe&and|OperatorsSupplemenThe&and|OperatorsIfxis1,whatisxafterthisexpression?(x>1)&(x++<10)Ifxis1,whatisxafterthisexpression?(1>x)&&(1>x++)Howabout(1==x)|(10>x++)?(1==x)||(10>x++)?40CompanionWebsiteThe&and|OperatorsIfxis1Problem:DeterminingLeapYear?41LeapYearRunThisprogramfirstpromptstheusertoenterayearasanintvalueandchecksifitisaleapyear.Ayearisaleapyearifitisdivisibleby4butnotby100,oritisdivisibleby400.(year%4==0&&year%100!=0)||(year%400==0)Problem:DeterminingLeapYearProblem:Lottery
Writeaprogramthatrandomlygeneratesalotteryofatwo-digitnumber,promptstheusertoenteratwo-digitnumber,anddetermineswhethertheuserwinsaccordingtothefollowingrule:42LotteryIftheuserinputmatchesthelotteryinexactorder,theawardis$10,000.Iftheuserinputmatchesthelottery,theawardis$3,000.Ifonedigitintheuserinputmatchesadigitinthelottery,theawardis$1,000.Problem:LotteryWriteaprogrswitchStatementsswitch(status){case0:computetaxesforsinglefilers;break;case1:computetaxesformarriedfilejointly;break;case2:computetaxesformarriedfileseparately;break;case3:computetaxesforheadofhousehold;break;default:System.out.println("Errors:invalidstatus");System.exit(0);}43switchStatementsswitch(statuswitchStatementFlowChart44switchStatementFlowChart44switchStatementRules45switch(switch-expression){casevalue1:statement(s)1;break;casevalue2:statement(s)2;break;…casevalueN:statement(s)N;break;default:statement(s)-for-default;}Theswitch-expressionmustyieldavalueofchar,byte,short,orinttypeandmustalwaysbeenclosedinparentheses.Thevalue1,...,andvalueNmusthavethesamedatatypeasthevalueoftheswitch-expression.Theresultingstatementsinthecasestatementareexecutedwhenthevalueinthecasestatementmatchesthevalueoftheswitch-expression.Notethatvalue1,...,andvalueNareconstantexpressions,meaningthattheycannotcontainvariablesintheexpression,suchas1+x.switchStatementRules45switchswitchStatementRules
Thekeywordbreakisoptional,butitshouldbeusedattheendofeachcaseinordertoterminatetheremainderoftheswitchstatement.Ifthebreakstatementisnotpresent,thenextcasestatementwillbeexecuted.46switch(switch-expression){casevalue1:statement(s)1;break;casevalue2:statement(s)2;break;…casevalueN:statement(s)N;break;default:statement(s)-for-default;}
Thedefaultcase,whichisoptional,canbeusedtoperformactionswhennoneofthespecifiedcasesmatchestheswitch-expression.
Thecasestatementsareexecutedinsequentialorder,buttheorderofthecases(includingthedefaultcase)doesnotmatter.However,itisgoodprogrammingstyletofollowthelogicalsequenceofthecasesandplacethedefaultcaseattheend.switchStatementRules ThekeyTraceswitchstatement47switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
Supposechis'a':animationTraceswitchstatement47switchTraceswitchstatement48switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
chis'a':animationTraceswitchstatement48switchTraceswitchstatement49switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
ExecutethislineanimationTraceswitchstatement49switchTraceswitchstatement50switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
ExecutethislineanimationTraceswitchstatement50switchTraceswitchstatement51switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
ExecutethislineanimationTraceswitchstatement51switchTraceswitchstatement52switch(ch){
case
'a':System.out.println(ch);
case
'b':System.out.println(ch);
case
'c':System.out.println(ch);}
Nextstatement;ExecutenextstatementanimationTraceswitchstatement52switchTraceswitchstatement53switch(ch){
case
'a':System.out.println(ch);
break;
case
'b':System.out.println(ch);break;
case
'c':System.out.println(ch);}
Supposechis'a':animationTraceswitchstatement53switchTraceswitchstatement54switch(ch){
case
'a':System.out.println(ch);
break;
case
'b':System.out.println(ch);break;
case
'c':System.out.println(ch);}
chis'a':animationTraceswitchstatement54switchTraceswitchstatement55switch(ch){
case
'a':System.out.println(ch);
break;
case
'b':System.out.println(ch);break;
case
'c':System.out.println(ch);}
ExecutethislineanimationTraceswitchstatement55switchTraceswitchstatement56switch(ch){
case
'a':System.out.println(ch);
break;
case
'b':System.out.println(ch);break;
case
'c':System.out.println(ch);}
ExecutethislineanimationTraceswitchstatement56switchTraceswitchstatement57switch(ch){
case
'a':System.out.println(ch);
break;
case
'b':System.out.println(ch);break;
case
'c':System.out.println(ch);}
Nextstatement;ExecutenextstatementanimationTraceswitchstatement57switchConditionalOperatorif(x>0)y=1elsey=-1;isequivalenttoy=(x>0)?1:-1;(boolean-expression)?expression1:expression2TernaryoperatorBinaryoperatorUnaryoperator58ConditionalOperatorif(x>0)ConditionalOperatorif(num%2==0)System.out.println(num+“iseven”);elseSystem.out.println(num+“isodd”);System.out.println((num%2==0)?num+“iseven”:num+“isodd”);59ConditionalOperatorif(num%ConditionalOperator,cont.(boolean-expression)?exp1:exp260ConditionalOperator,cont.(boFormattingOutput61Usetheprintfstatement.System.out.printf(format,items);Whereformatisastringthatmayconsistofsubstringsandformatspecifiers.Aformatspecifierspecifieshowanitemshouldbedisplayed.Anitemmaybeanumericvalue,character,booleanvalue,orastring.Eachspecifierbeginswithapercentsign.FormattingOutput61UsetheprFrequently-UsedSpecifiers62SpecifierOutput Example%b
abooleanvalue
trueorfalse
%c
acharacter
'a'
%d
adecimalinteger 200%f
afloating-pointnumber
45.460000
%e
anumberinstandardscientificnotation
4.556000e+01%s
astring
"Javaiscool"
Frequently-UsedSpecifiers62SOperatorPrecedencevar++,var--+,-(Unaryplusandminus),++var,--var(type)Casting!(Not)*,/,%(Multiplication,division,andremainder)+,-(Binaryadditionandsubtraction)<,<=,>,>=(Comparison)==,!=;(Equality)^(ExclusiveOR)&&(ConditionalAND)Short-circuitAND||(ConditionalOR)Short-circuitOR=,+=,-=,*=,/=,%=(Assignmentoperator)63OperatorPrecedencevar++,var-OperatorPrecedenceandAssociativityTheexpressionintheparenthesesisevaluatedfirst.(Parenthesescanbenested,inwhichcasetheexpressionintheinnerparenthesesisexecutedfirst.)Whenevaluatinganexpressionwithoutparentheses,theoperatorsareappliedaccordingtotheprecedenceruleandtheassociativityrule.Ifoperatorswiththesameprecedencearenexttoeachother,theirassociativitydeterminestheorderofevaluation.Allbinaryoperatorsexceptassignmentoperatorsareleft-associative.
64OperatorPrecedenceandAssociOperatorAssociativity
Whentwooperatorswiththesameprecedenceareevaluated,theassociativityoftheoperatorsdeterminestheorderofevaluation.Allbinaryoperatorsexceptassignmentoperatorsareleft-associative.a–b+c–disequivalentto
((a–b)+c)–dAssignmentoperatorsareright-associative.Therefore,theexpressiona=b+=c=5isequivalenttoa=(b+=(c=5))65OperatorAssociativityWhenExampleApplyingtheoperatorprecedenceandassociativityrule,theexpression3+4*4>5*(4+3)-1isevaluatedasfollows:66ExampleApplyingtheoperatorpCompanionWebsiteOperandEvaluationOrderSupplementIII.A,“AdvanceddiscussionsonhowanexpressionisevaluatedintheJVM.”67CompanionWebsiteOperandEvalu(GUI)ConfirmationDialogsintoption=JOptionPane.showConfirmDialog(null,"Continue");68(GUI)ConfirmationDialogsintProblem:GuessingBirthDate
Theprogramcanguessyourbirthdate.Runtoseehowitworks.69GuessBirthDateUsingConfirmationDialogProblem:GuessingBirthDateTChapter3Selections70Chapter3Selections1MotivationsIfyouassignedanegativevalueforradiusinListing2.1,ComputeArea.java,theprogramwouldprintaninvalidresult.Iftheradiusisnegative,youdon'twanttheprogramtocomputethearea.Howcanyoudealwiththissituation?71MotivationsIfyouassignedanObjectives72TodeclarebooleantypeandwriteBooleanexpressionsusingcomparisonoperators(§3.2).ToprogramAdditionQuizusingBooleanexpressions(§3.3).Toimplementselectioncontrolusingone-wayifstatements(§3.4)ToprogramtheGuessBirthdaygameusingone-wayifstatements(§3.5).Toimplementselectioncontrolusingtwo-wayifstatements(§3.6).Toimplementselectioncontrolusingnestedifstatements(§3.7).Toavoidcommonerrorsinifstatements(§3.8).Toprogramusingselectionstatementsforavarietyofexamples(BMI,ComputeTax,SubtractionQuiz)(§3.9-3.11).TogeneraterandomnumbersusingtheMath.random()method(§3.9).Tocombineconditionsusinglogicaloperators(&&,||,and!)(§3.12).Toprogramusingselectionstatementswithcombinedconditions(LeapYear,Lottery)(§§3.13-3.14).Toimplementselectioncontrolusingswitchstatements(§3.15).Towriteexpressionsusingtheconditionaloperator(§3.16).ToformatoutputusingtheSystem.out.printfmethodandtoformatstringsusingtheString.formatmethod(§3.17).Toexaminetherulesgoverningoperatorprecedenceandassociativity(§3.18).(GUI)Togetuserconfirmationusingconfirmationdialogs(§3.19).Objectives3TodeclarebooleanThebooleanTypeandOperatorsOfteninaprogramyouneedtocomparetwovalues,suchaswhetheriisgreaterthanj.Javaprovidessixcomparisonoperators(alsoknownasrelationaloperators)thatcanbeusedtocomparetwovalues.TheresultofthecomparisonisaBooleanvalue:trueorfalse.booleanb=(1>2);
73ThebooleanTypeandOperatorsComparisonOperators74Operator Name < lessthan <= lessthanorequalto> greaterthan>= greaterthanorequalto== equalto!= notequaltoComparisonOperators5OperatorProblem:ASimpleMathLearningTool75AdditionQuizRunThisexamplecreatesaprogramtoletafirstgraderpracticeadditions.Theprogramrandomlygeneratestwosingle-digitintegersnumber1andnumber2anddisplaysaquestionsuchas“Whatis7+9?”tothestudent.Afterthestudenttypestheanswer,theprogramdisplaysamessagetoindicatewhethertheansweristrueorfalse.Problem:ASimpleMathLearninOne-wayifStatementsif(boolean-expression){statement(s);}76if(radius>=0){area=radius*radius*PI;System.out.println("Thearea"+"forthecircleofradius"+radius+"is"+area);}One-wayifStatementsif(booleNote77Note8SimpleifDemo78SimpleIfDemoRunWriteaprogramthatpromptstheusertoenteraninteger.Ifthenumberisamultipleof5,printHiFive.Ifthenumberisdivisibleby2,printHiEven.SimpleifDemo9SimpleIfDemoRunProblem:GuessingBirthdayTheprogramcanguessyourbirthdate.Runtoseehowitworks.79GuessBirthdayProblem:GuessingBirthdayTheMathematicsBasisfortheGame19is10011inbinary.7is111inbinary.23is11101inbinary80MathematicsBasisfortheGameTheTwo-wayifStatementif(boolean-expression){statement(s)-for-the-true-case;}else{statement(s)-for-the-false-case;}81TheTwo-wayifStatementif(boif...elseExampleif(radius>=0){area=radius*radius*3.14159; System.out.println("Theareaforthe“+“circleofradius"+radius+"is"+area);}else{System.out.println("Negativeinput");}82if...elseExampleif(radius>=MultipleAlternativeifStatements83MultipleAlternativeifStatemTraceif-elsestatement84if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionisfalseanimationTraceif-elsestatement15if(sTraceif-elsestatement85if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionisfalseanimationTraceif-elsestatement16if(sTraceif-elsestatement86if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0TheconditionistrueanimationTraceif-elsestatement17if(sTraceif-elsestatement87if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0gradeisCanimationTraceif-elsestatement18if(sTraceif-elsestatement88if(score>=90.0)grade='A';elseif(score>=80.0)grade='B';elseif(score>=70.0)grade='C';elseif(score>=60.0)grade='D';elsegrade='F';Supposescoreis70.0ExittheifstatementanimationTraceif-elsestatement19if(sNoteTheelseclausematchesthemostrecentifclauseinthesameblock.89NoteTheelseclausematchesthNote,cont.Nothingisprintedfromtheprecedingstatement.Toforcetheelseclausetomatchthefirstifclause,youmustaddapairofbraces:inti=1;intj=2;intk=3;if(i>j){if(i>k)System.out.println("A");
}elseSystem.out.println("B");ThisstatementprintsB.90Note,cont.NothingisprintedCommonErrorsAddingasemicolonattheendofanifclauseisacommonmistake.if(radius>=0);{area=radius*radius*PI;System.out.println("Theareaforthecircleofradius"+radius+"is"+area);}Thismistakeishardtofind,becauseitisnotacompilationerrororaruntimeerror,itisalogicerror.Thiserroroftenoccurswhenyouusethenext-lineblockstyle.91WrongCommonErrorsAddingasemicoloTIP92TIP23CAUTION93CAUTION24Problem:AnImprovedMathLearningTool
Thisexamplecreatesaprogramtoteachafirstgradechildhowtolearnsubtractions.Theprogramrandomlygeneratestwosingle-digitintegersnumber1andnumber2withnumber1>number2anddisplaysaquestionsuchas“Whatis9–2?”tothestudent.Afterthestudenttypestheanswerintheinputdialogbox,theprogramdisplaysamessagedialogboxtoindicatewhethertheansweriscorrect.94SubtractionQuizProblem:AnImprovedMathLearProblem:BodyMassIndex
BodyMassIndex(BMI)isameasureofhealthonweight.Itcanbecalculatedbytakingyourweightinkilogramsanddividingbythesquareofyourheightinmeters.TheinterpretationofBMIforpeople16yearsorolderisasfollows:95ComputeBMIProblem:BodyMassIndexBodyProblem:ComputingTaxesTheUSfederalpersonalincometaxiscalculatedbasedonthefilingstatusandtaxableincome.Therearefourfilingstatuses:singlefilers,marriedfilingjointly,marriedfilingseparately,andheadofhousehold.Thetaxratesfor2009areshownbelow.96MarginalTaxRateSingleMarriedFilingJointlyorQualifiedWidow(er)MarriedFilingSeparatelyHeadofHousehold10%$0–$8,350$0–$16,700$0–$8,350$0–$11,95015%$8,351–$33,950$16,701–$67,900$8,351–$33,950$11,951–$45,50025%$33,951–$82,250$67,901–$137,050$33,951–$68,525$45,501–$117,45028%$82,251–$171,550$137,051–$208,850$68,525–$104,425$117,451–$190,20033%$171,551–$372,950$208,851–$372,950$104,426–$186,475$190,201-$372,95035%$372,951+$372,951+$186,476+$372,951+Problem:ComputingTaxesTheUSProblem:ComputingTaxes,cont.if(status==0){//Computetaxforsinglefilers}elseif(status==1){//Computetaxformarriedfilejointly}elseif(status==2){//Computetaxformarriedfileseparately}elseif(status==3){//Computetaxforhead
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 冠狀動(dòng)脈造影及支架植入術(shù)
- 2-6邏輯運(yùn)算的公式
- 原發(fā)性肝癌患者護(hù)理查房 2
- 上海市浦東新區(qū)浦東2025年招生伯樂馬模擬考試(三)生物試題含解析
- 山西財(cái)經(jīng)大學(xué)華商學(xué)院《中外設(shè)計(jì)史》2023-2024學(xué)年第二學(xué)期期末試卷
- 上海海關(guān)學(xué)院《數(shù)理統(tǒng)計(jì)理論與方法》2023-2024學(xué)年第一學(xué)期期末試卷
- 新疆伊寧市第七中學(xué)重點(diǎn)達(dá)標(biāo)名校2025年高中畢業(yè)班零診模擬考試英語試題含答案
- 山西警官職業(yè)學(xué)院《藥物分離工程》2023-2024學(xué)年第一學(xué)期期末試卷
- 九江理工職業(yè)學(xué)院《影視專業(yè)英語》2023-2024學(xué)年第一學(xué)期期末試卷
- 南京師范大學(xué)泰州學(xué)院《電氣安全》2023-2024學(xué)年第二學(xué)期期末試卷
- 《旅行社經(jīng)營管理》考試復(fù)習(xí)題庫及答案
- 粵教版五年級(jí)下冊(cè)科學(xué)知識(shí)點(diǎn)
- 《最好的未來》合唱曲譜
- 文言文《守株待兔》說課稿課件
- 生物礦物課件
- GB∕T 36765-2018 汽車空調(diào)用1,1,1,2-四氟乙烷(氣霧罐型)
- DB34-T 4243-2022 智慧醫(yī)院醫(yī)用耗材SPD驗(yàn)收規(guī)范
- 《覺醒年代》朗誦稿
- 混凝土格構(gòu)梁護(hù)坡施工方案設(shè)計(jì)
- 小學(xué)教育專業(yè)畢業(yè)論文
- 西南交通大學(xué)學(xué)報(bào)排模板
評(píng)論
0/150
提交評(píng)論