CalcAverage
This exercise focuses on conversion between integers and floating
point numbers.
Download files: CalcAverage.java
Areas: Primitive types.
Download files: CalcAverage.java
Areas: Primitive types.
|
|
CalcAverage.java |
|
|
| Question 1 |
| What is the programmer trying to do? |
| Question 2 |
| Assuming the programmer is trying to calculate the exact average of each student's marks, will he get the desired result? |
| Question 3 |
| What will the value of ave be? |
| Question 4 |
| After several complaints from unhappy students, the programmer decided to
change the last line of the code to
int ave = (mark1 + mark2 + mark3) / 3.0;
Is the problem solved? |
| Question 5 |
| Realizing programming is hard work and requires considerable amount of persistency,
the programmer did not give up. After hours of trial and error, he
changed the code to
double ave = (mark1 + mark2 + mark3) / 3;
The compiler error disappeared; all seemed to be good. However, the programmer
continues to hear the same complaints from students. Now he is
completely confused. Do you know where the problem is? How would you make
the code work? |
