27-04-2012, 07:39 AM
|
#459
|
تاريخ التسجيل: Feb 2010
التخصص: تقنية معلومات
نوع الدراسة: إنتظام
المستوى: الخامس
الجنس: أنثى
المشاركات: 181
|
رد: Cpcs 202 شروحات وحلول وواجبات الجافا
ياليت تشرحون لي هذي البرامج الله يجزاكم خير فهموني بس ايش المطلوب بالتفصيل في السؤال
والصور اللي يكتبها في مثل 10.4-10.9 ...وغيرها وين القاها انا عندي كتاب واحد ودورتها فيه ما لقيتها
ProgrammingChallenges
TheProgrammingChallengesaremoreinvolvedthanthe CodingExercisesand mayrequireasignificantamount oftimetocomplete.WriteaJavaprogramforeachoftheprob lemsinthissection.Theanswerstotheseproblems areavailableat www.pearsonhighered.com/deitel.Pseudocode,hintsorsampleoutputsareprovidedforeach problemtoaidyouinyourprogramming.
1. (PayrollSystemModification)ModifythepayrollsystemofFigs.10.4–10.9toincludeprivateinstancevariablebirthDateinclassEmployee.UseclassDateofFig.8.7torepresentanemployee’sbirthday.Addget methodstoclassDateandreplacemethodtoDateStringwithmethodtoString.Assumethatpayrollisprocessedonceper month.Createanarrayof Employeevariablestostorereferencestothevariousemployee objects.Inaloop,calculatethepayrollforeachEmployee(polymorphically),andadda$100.00bonusto theperson’spayrollamount ifthecurrentmonthisthemonthinwhichtheEmployee’sbirthdayoccurs.
Hint:
• Youroutputshouldappearasfollows:
Dateobjectconstructorfordate 6/15/1944
Dateobjectconstructorfordate 12/29/1960
Dateobjectconstructorfordate 9/8/1954
Dateobjectconstructorfordate 3/2/1965
Employees processedindividually:
salaried employee:John Smith
socialsecuritynumber:111-11-1111
birthdate:6/15/1944
weeklysalary:$800.00
earned:$800.00
hourlyemployee: Karen Price
socialsecuritynumber:222-22-2222
birthdate:12/29/1960
hourlywage:$16.75;hours worked: 40.00
earned:$670.00
commission employee:Sue Jones socialsecuritynumber:333-33-3333 birthdate:9/8/1954
gross sales:$10,000.00;commission rate:0.06 earned:$600.00
base-salariedcommission employee:BobLewis socialsecuritynumber:444-44-4444
birthdate:3/2/1965
gross sales: $5,000.00;commission rate:0.04;base salary:$300.00
earned:$500.00
Enterthe currentmonth(1 -12): 3
Employees processedpolymorphically:
salaried employee:John Smith
socialsecuritynumber:111-11-1111
birthdate:6/15/1944
weeklysalary:$800.00
earned $800.00
hourlyemployee: Karen Price
socialsecuritynumber:222-22-2222
birthdate:12/29/1960
hourlywage:$16.75;hours worked:40.00
earned $670.00
commission employee:Sue Jones socialsecuritynumber:333-33-3333 birthdate:9/8/1954
gross sales:$10,000.00;commission rate:0.06
earned $600.00
base-salariedcommission employee: BobLewis socialsecuritynumber:444-44-4444
birthdate:3/2/1965
gross sales: $5,000.00;commissionrate:0.04;base salary:$300.00
newbase salarywith 10%increaseis:$330.00
earned $530.00 plus $100.00 birthdaybonus
Employee 0isa SalariedEmployee Employee 1isa HourlyEmployee Employee 2isa CommissionEmployee
Employee 3isa BasePlusCommissionEmployee
Solution
2. (ShapeHierarchy)ImplementtheShapehierarchyshowninFig.9.3ofJavaHowtoProgram.EachTwoDimensionalShapeshouldcontainmethodgetAreatocalculatetheareaofthetwo-dimensionalshape.Each ThreeDimensionalShapeshouldhavemethodsgetAreaandgetVolumetocalculate thesurfaceareaandvolume,respectively,ofthethree-dimensionalshape.CreateaprogramthatusesanarrayofShapereferences toobjectsofeachconcreteclassin thehierarchy.Theprogramshouldprintatextdeionoftheo bject towhicheacharrayelementrefers.Also,intheloopthatpr ocessesalltheshapesinthearray,determine whethereachshapeisaTwoDimensionalShape oraThreeDimensionalShape.IfashapeisaTwoDimensionalShape, displayitsarea.IfashapeisaThreeDimensionalShape,displayitsareaandvolume.
Hint:
• Youroutputshouldappearasfollows:
Circle:[22,88] radius:4
Circle'sarea is50
Square:[71,96] side:10
Square'sarea is100
Sphere:[8,89] radius:2
Sphere'sarea is50
Sphere'svolume is33
Cube: [79,61] side:8
Cube's area is384
Cube's volumeis512
Solution
|
|
|
|
|