Exactly 25 years ago, on February 24, 1980, the US Olympic Ice Hockey team has won its gold medal. This event was described in a recent movie "Miracle".

1. Write down a method named *anniversary* that,
given the year of the event and current year,
computes how many years have passed since that event.
Show, on the example of
1980 and 2005, that your method correctly computes the value 25.

Answer: public int anniversary(int event, int current){ return current - event;} } checking: int age = anniversary(1980, 2005); this call will compute the value 2005 - 1980 =25 and assign it to the variable age2. If a variable

int many = (int) years * 10.0; int few = (int) years/10.0; next = years++; next--;What is the advantage of using next-- instead of next = next - 1?

Answer: many = 250, few = 2, next = 25 after the third statement, then 24 next-- is shorter than next = next - 1, so it is faster for a programmer to write; besides, if you have to repeat the variable name twice, you make a mistake and accidentally type in two different names3. After sending an email to your friends about the hockey anniversary, you realized that you accidentally got confused with the Miners miraculous 1966 victory and typed

Answer: int location = email.indexOf("basketball"); email = email.substring(0,location) + "hockey" + email.substring(location + "basketball".length(),email.length());4. In hockey, winning is easy to describe:

- if the first team scored more, it wins, so it gets 2 points and the second team gets none;
- if the second team scored more, then the second team wins, it gets 2 points and the first team gets none;
- if both teams scored the same, they get 1 point each.

Answer: if (score1 > score 2) {points1 = 2; points2 = 0;} else if (score2 > score 1) {points1 = 0; points2 = 2;} else {points1 = 1; points2 = 1;}5. In the competition between the three teams 1, 2, and 3, a team becomes a champion if it has earned more points than every other team. Write down a method

Answer: public Boolean champion1(int points1, int points2, int points3){ return (points1 > points2) && (points1 > points3); }6. What are the reasonable test cases for the method you developed for Problem 5? Explain your answer.

Answer: * a case when the first team gets more points than others, e.g., 10, 8, and 7; * a case when the first team in not a champion, e.g., 7, 8, and 10; * a borderline case, e.g., 10, 10, and 8 * a random case, when all three variables get values from a random number generator7. Let us assume that the points earned by the team in different games are stored, line by line, in a file

Answer: Buffered Reader in = new BufferedReader(new FileReader("points.dat")); String line; int overall = 0; while((line = in.readLine())!=null){ overall = overall + Integer.parseInt(line);} in.close();8. To celebrate their victory, the hockey players usually skate in circles. To describe this celebration, define an object

*Reminder:*

- the diameter of circle is equal to 2 times its radius;
- the circumference of a circle is 2*PI times its radius;
- the area of a circle is PI times the radius squared (use the corresponding method from the Math package).

Answer: import Math.*; public class Circle{ private double radius; public Circle(double aradius){ radius = aradius; } // this method is only needed if we define the field as private public double getRadius(){ return radius; } // this method is only needed if we define the field as private public void setRadius(int aradius){ radius = aradius; } public double diameter(){ return 2.0*radius; } public double circumference(){ return 2.0*Math.PI*radius; } public double area(){ return math.Pi*power(radius,2.0); } }