Java代写 | PROG2007 Sample Exam

本次澳洲代写主要为Java编程相关的限时测试

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)
System.out.println(10%5);
System.out.println(10/5);
System.out.println(10<10);
System.out.println(10==10);

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;
loop++;
}

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’) {
System.out.println(“Excellent”);
} else if (code ==’B’ || code == ‘C’) {
System.out.println(“Good”);
} else if (code == ‘D’) {
System.out.println(“Poor”);
}

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 + “ “);
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;
System.out.println(“a”+a);
System.out.println(“b”+b);

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
marks):
new Date(“March”, 30, 1932);
Write another constructor that takes no parameters, for the same class (2 marks).