Java代写 | PROG2007 Sample Exam


Part A: Short Answer Questions (60 marks). Answer all questions. This is an example exam only.

1. What is a keyword? Give two examples, using Java as the programming language. (2 marks)

2. What will be the output for the following program segment? (2 marks)

3. What is the value of the variable named loop (2 marks) after the following code has run?
int count = 10;
int loop = 0;
while (count > 00) {
count = count – 1;

4. Explain one reason why you may have two constructors in a class (2 marks).

5. Create a class called DoSomething, that has two integer fields, int1 and int2. Initialise these
fields in a constructor. (3 marks)

6. Rewrite the following “if” construct as a switch/case statement: (2 marks)
char code;
if (code ==’A’) {
} else if (code ==’B’ || code == ‘C’) {
} else if (code == ‘D’) {

7. Convert the following code segment into an equivalent for loop (2 marks)
public void display()
int i = 10;
while (i !=20)
System.out.println(i + “ “);

8. What will be the output of the following program segment? (2 marks)
int a = 10;
int b = 30;
int c = 40;
a = b– + c * a / 2;

9. What is the difference between a field and a local variable? (2 marks)

10. What is a Wrapper class? Give two examples of a Wrapper class (2 marks)

11. What is the purpose of a break statement? (2 marks)

12. Write a for loop to loop through the following array and print out each number on a
separate line in an ascending order: (2 marks)
int[] numbers = {1, 3, 2 ,4, 2};

13. For each of the Java method signatures below, answer the following questions:
a. What is the method name?
b. Does the method return a value? If yes, what is the type of the return value?
c. How many parameters does the method have?
d. Write a sample Java method call for the method signature; that is: how would you
call the method in your code?

public void changeColour(String colour) (2 marks)
public int calculateLargest(int A, int B) (2 marks)
public boolean hasEaten() (2 marks)
14. Write a constructor for the Date class given the following sample object creation code (2
new Date(“March”, 30, 1932);
Write another constructor that takes no parameters, for the same class (2 marks).



本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail:  微信:itcsdx