Académique Documents
Professionnel Documents
Culture Documents
IF USING THIS AS A MOCK PAPER NOTE THE GRADES MAY BE CALCULATED IN A DIFFERENT WAY IN FUTURE YEARS
Page 1 of 5
Question 1 [25 marks] a) Explain what is meant by the i) declaration of a variable ii) initialisation of a variable . Illustrate your answers with appropriate examples. Answer:
[6 Marks] [Total Marks for Part 1a: 6 marks] Question 1 continues overleaf.
Page 2 of 5
Question 1 continued. b) Give the final string value of z after each fragment of code in the question sub-parts below is executed. Justify your answers. i)
String z = A; String x = AA; x = x + x; Z = z + x;
Answer: Justification:
[2 Marks]
ii)
int x = 5; if(x>5) {z = B;} else if (x>3) {z = BB;} else if (x == 5) {z = BBB;} else {z = BBBB;}
Answer: Justification:
[2 Marks] Question 1 continues overleaf. Page 3 of 5 ECS401 Mid term Test Autumn 2007
Question 1 continued.
iii)
String z = C; for(int i = 1; i <= 3; i++) {z = z + CC;}
Answer: Justification:
[2 Marks]
iv)
String z = ; for(int i = 1; i <= 2; i++) { for(int j = 1; j <= 4; j++) {z = z + D;} }
Answer: Justification:
[3 Marks] [Total Marks for Part 1b: 9] Question 1 continues overleaf. Page 4 of 5 ECS401 Mid term Test Autumn 2007
Question 1 continued.
c) Write a Java program that allows football teams to be rated. It asks the user to type in the name of a player. The program then asks for a score out of 10 for how well that player played. Finally it prints a message about them containing their name and varying depending on the score: Flop! if the score was less than 5, Star! if the score was more than 8 and Solid otherwise. An example run of the program might go: Name? Sasha Score? 9 Sasha, you are a Star! Extend your program with a loop so that it does the above for each of the 11 players in the team in turn before ending. Your program should check for the range of the input (between 0 and 10), though you may assume that an integer is always input for the score. Answer:
[10 Marks]