I think the exercise is wrong because it declare average variable as double type, so the author expected a double type result. If it wasn't that way, the author must declare: "int average = 0;" In other hand, if the author declare: double average = 0; could compute: average = (double)(mathGrade+historyGrade+scienceGrade)/3;
Thank you, very much. -- Adrián On 19 ene, 00:13, lesh59 <[email protected]> wrote: > Hi > > Strictly speaking, it is wrong to show the result as 73.0 as it is not > accurate to 1 decimal place. > > It would be correct to show the result as 73 if you are not interested > in the decimal places. > > If you are interested in the decimal place then the result should be > displayed as 73.6 (not 73.0) or 73.66 if you are interested in 2 > decimal places. > > Also, the rules of rounding should be specified by the client, the > exam board in this example may ignore decimal places, but do they > always round down, round up or to the nearest ? > > For this example lets say that the rules say round down, so change the > average variable to an int, the result will show as 73 (with no > decimal places). > > On Jan 18, 2:48 pm, [email protected] wrote: > > > The exercise is not necessarily wrong. > > > Displaying someones grade average to decimal places may be wrong, > > displaying it as a whole number i.e. 73 may be correct, in that case > > the .66 is meaningless. So the exercise may be correct > > > On 17 Jan, 21:54, Adrián E. Córdoba <[email protected]> wrote: > > > > I understood. > > > So, that exercise is wrong: the type of variables isn't correctly > > > used. > > > Thank you, so much. > > > > On 17 ene, 04:58, Steffani Trinitra Setyasari <[email protected]> > > > wrote: > > > > > Maybe I can help you to explain what happened.... > > > > The type of variables "mathGrade", "historyGrade" and > > > > "scienceGrade" is integer. The divider of "average" is "3" that its > > > > type is integer,too. Both the numerator and denominator are integer so > > > > the result will be integer too. Although the result of "average " is > > > > 73.66.., it will be rounded off to 73. But because the type > > > > of "average" is "double" so the result is 73.0 > > > > > > > > If you want to get the exact result of "average" maybe you can change > > > > the divider "3" to "3.0" or change the type of "mathGrade", > > > > "historyGrade","scienceGrade" to double. > > > > > > > > Cheers! > > > > > --- On Sat, 17/1/09, Adrián E. Córdoba <[email protected]> wrote: > > > > > From: Adrián E. Córdoba <[email protected]> > > > > Subject: [java programming] Wrong average in LAB-1034 > > > > To: "Free Java Programming Online Training Course By Sang Shin" > > > > <[email protected]> > > > > Date: Saturday, 17 January, 2009, 2:38 AM > > > > > I think something is wrong in LAB-1034, Exercise 1 if/else control > > > > structure, "(1.1) Build and run a Java program that uses if/else > > > > control structure". > > > > If you follow the directives in that LAB, and build an run > > > > MyGradesProject and enter the math, history, and science grades (78, > > > > 56 and 87 respectively) like the figures show, the program compute and > > > > display that the average is "73.0" as Figure-1.15 shows. > > > > But, if you compute the same average: > > > > > (78+56+87) / 3 > > > > > in a calculator (like Windows Calculator), the average is "73.66..". > > > > What's wrong? > > > > > Thank you in advance. > > > > > Importing contacts has never been easier. Bring your friends over > > > > to Yahoo! Mail today!http://www.trueswitch.com/yahoo-sg-Hide quoted > > > > text - > > > - Show quoted text - > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
