Search the whole station

面向对象编程代考 Java代考 COMP2396 I CSIS0396代写

COMP2396 I CSIS0396 Object-oriented Programming and Java

面向对象编程代考 Only approved calculators as announced by the Examinations Secretary can be used in this examination. It is the candidates’ responsibility to

Date: December 22, 2015                                                                   Time: 2:30pm-5:30pm

Only approved calculators as announced by the Examinations Secretary can be used in this examination. It is the candidates’ responsibility to ensure that their calculator operates satisfactorily, and candidates must record the name and type of the calculator used on the front page of the answer sheets.

Answer ALL questions (100%).

Section A [20%] 面向对象编程代考

Q1

Which of the following is I are valid Javadoc tags?

i. @parameter

ii. @return

iii. @title

iv. @exception

a) i and ii         

b) ii and iii           

c) ii and iv 

d) i, ii and iv     

e) All of the above

Q2

Which of the following statements about Java syntax is I are correct?

i. An identifier can start with a $ character.

ii. The operands of+ operator must be numbers.

iii. A char data type variable takes 8 bits of memory.

iv. The number 7 5. is a literal of type float.

a) i only         

b) ii only           

c) i and iv

d) ii and iii     

e) ii and iv

Q3 面向对象编程代考

Which of the following statements about Java array is I are correct?

i. Let costone and costTwo be two double arrays of the same size. Then costOne = costTwo; copies every element of array costTwo into array costOne.

ii.You must know the array size to create an array.

iii. The array length is the same as the upper bound of the array.

iv. You can increase the size of an array inside your program.

a) i only         

b) ii only           

c) i and ii

d) ii and iii     

e) ii and iv

Q4

Given

int a, b, c; 
double x, y;
Scanner scannedinfo =new Scanner(System.in);

Which of the following assignment statements is I are invalid?

i. b = scannedinfo.nextint();

ii. c = scannedinfo. next () ;

iii. x = scannedinfo. nextDouble () ;

iv. x = System.out.println(y);

a) i only           

b) ii only           

c) i and iii

d) ii and iii     

e) ii and iv

Q5 面向对象编程代考

Which of the following statements about Java class methods is I are correct?

i. A static method must be invoked using the class name.

ii. Only a static method can modify a class variable.

iii. A class can have two methods that are identical in their heading except in their return type specification.

iv. A default constructor has no formal parameters.

a) i only           

b) ii only           

c) i and iv

d) ii and iii       

e) ii and iv

Q6

Which of the following statements about Java inheritance and polymorphism is / are correct?

i. Polymorphism refers to the presence of a method having the same name but possiblydifferent signatures in a superclass and subclass.

ii. The subclass inherits all attributes and services of the superclass.

iii. It is legal to modify an inherited private attribute.

iv. For a class to be abstract, it must have at least one abstract method.

a) i only           

b) ii only         

 c) i and iv

d) ii and iii     

e) ii and iv

Q7 面向对象编程代考

Which of the following statements about Java GUI programming is I are correct?

i. In the case ofGridLayout manager, components are placed from left to right in each row and rows are filled from top to right in each row and rows are filled from top to bottom.

ii. An applet is created as a subclass of JFrame.

iii. The paint is invoked by the user to draw various geometric shapes.

iv. There are user-generated events that do not fall under some event class.

a) i only

b) ii only

c) i and iii

d) ii and iii

e) ii and iv

Q8

What should be the correct sequence for executing the following methods when running a Java Applet?

i. paint()

ii. destroy ()

iii. start()

iv. stop()

v. init ()

a) i, v, iii, iv, ii

b) iii, v, i, iv, ii

c) v, iii, i, ii, iv

d) v, iii, i, iv, ii

e) v, i, iii, iv, ii

Q9 面向对象编程代考

What will be inside the stack (from top to bottom) when the following program is being executed?

public class Student {
private int Age;
private String Name;
private setName(String N) {
Name = N;
}
public Student(int A, String N) {
Age = A;
setName (N) ;
}
}
public static void main(String[] args) {
Student S = new Student (23, "Tim");
}

a) main(), Student(int, String), setName()

b) setName(), Student(int, String), main()

c) main(), Student(int, String)

d) Student(int, String), main()

e) setName(), Age, Student(int, String), main()

Q10 

Given the following client and server programs. The server program is started 5 minutes before the client program is run.

Client program:

try {
Sockets= new Socket("l47.8.123.456", 2396);
InputStreamReader is = new
InputStreamReader(s.getinputStream());
BufferedReader br =new BufferedReader(is);
String S = br.readLine();
System.out.println(S);
br.close();
} catch (IOException e) {
System. out .println ( "IOException caught");
}

Server program:

try {
ServerSocket ss =new ServerSocket(2396);
Socket s = ss.accept();
PrintWriter w =new PrintWriter(s.getOutputStream());
String S = "Merry Christmas!";
w.println(S);
w.close ();
} catch (IOException e) {
System. out .println ( "IOException caught") ;
}

Which of the following statement is correct?

a) “Merry Christmas!” will be printed out by the client program.

b) Nothing will be printed out by both programs.

c) “IO Exception caught” will be printed out by the client program.

d) “IOException caught” will be printed out by the server program.

e) “IOException caught” will be printed out by both programs.

Section B [80%] 面向对象编程代考

Q1. [10%]

(a) Please write down the four principles of objected-oriented programming? (4%)

(b) Please match each of the following to the above four principles. (6%)

(i) A programmer can catch the general Exception object instead of objects of sub-classes of Exception.

(ii) Normally, we only need to write JavaDoc for non-private methods and class fields.

(iii) You can extend your class from JFrame so that you don’t need to create any JFrame object in your program.

(iv) You can make your class implement the ActionListener interface but then in your class, you need to provide implementation details of the actionPerformed (ActionEvent event) method.

Q2. [20%]

Consider three classes A, B, and C. Class A is a superclass of B and C.

Class A has two methods: void alpha () and void beta ().

Class B has two methods: void beta () and void gamma ().

Class c has two methods: void alpha () and void gamma ().

Further assume that a, b, and c are instances of A, B, and c respectively.

Indicate whether or not each of the code segment below has any error. If there is an error that can be corrected through proper casting, then correct it. Once the segment of code is error free, identify the method that is being invoked.

(i) a= b; a.beta();

(ii) a = b; … ; c = a; c.alpha();

(iii) b. alpha() ;

(iv) a = b; … ; a. alpha () ;

(v) a= b; … ; b = a; b.gamma();

Q3. [10%] 面向对象编程代考

(a) Briefly explain the difference between the terms “overriding” and “overloading”. (5%)

(b) Consider the following programs:

Gift.java:

public class Gift {
int Count = O;
static String Name;
public Gift(String N) {
Count ++;
Name = N;
}
}

Main.java:

public class Main {
public static void main(String[] args) {
Gift[] G =new Gift[3];
G[OJ = new Gift ("Pen");
G[l] =new Gift("Watch");
G[2] = new Gift ( "iPhone") ;
for (int i = O; i < 3; i++)
System.out.println(G[i] .Name);
System.out.println(Gift.Count);
}
}

The program Gift.java contains one syntax error. Please fix it to make the programs compilable. (2%)

(c) After fixing the problem in b) and when Main.java is run, the following is printed:

> java Main
iPhone
iPhone
iPhone
3

The program is expected to print the names of the three gifts (i.e. “Pen”, “Watch” and “iPhone”). Please fix any logical error in the programs. (3%)

Q4. (10%]

(a) What is the difference between checked exceptions and unchecked runtime exceptions? Give one example for each of the two types of exceptions. (4%)

(b) The following program cannot be compiled. Please update the main ( ) method to make the program compilable. (4%)

import java.io.*;
public class ABC {
public void writeFile() throws IOException {
PrintWriter outFile
=new PrintWriter (new FileWriter ( "outFile. txt"));
for (int i = O; i < 10; i++)
outFile.println(i);
}
public static void main(String[] args) {
ABC abc = new ABC();
abc.writeFile();
}
}

(c) Upon the main () method is updated and assume the program is now compilable. What is the content of “outFile.txt” after executing the above program? (2%)

Q5. (10%] 面向对象编程代考

(a) What is meant by Serialization? (2%)

(b) What is the advantage of using BufferedReader and BufferedWri ter? (2%)

(c) The following program segment is used to serialize an object from the Student class:

FileOutputStream FOS =new FileOutputStream("Obj.ser");
ObjectOutputStream OOS =new ObjectOutputStream(FOS);
OOS.writeObject(Sl); // Sl is a Student instance
OOS.close();

Write down a program segment to restore the object. (6%)

Q6. (20%]

A student has written the following JApplet for computing roots of quadratic equations. The JApplet has 3 JTextField components. A user can enter A, B and C which are coefficients of the quadratic equation Ax2+ Bx + C = 0. By pressing an “OK” button, the JApplet will calculate the two roots of the equation and display them using JLabel components.

import javax.swing.*; 
import java.awt.*;
import java.awt.event.*;
import java.math.*;

public class Quadratic extends JApplet implements
ActionListener {
JLabel label_A = new JLabel ("A: " } ;
JLabel label_B = new JLabel ( "B: " ) ;
JLabel label_C = new JLabel ( "C: " ) ;
JLabel label_Rl = new JLabel ("Root 1: " )
JLabel label_R2 = new JLabel ("Root 2: " )
JTextField text_A = new JTextField(lO);
JTextField text _B = new JTextField (10) ;
JTextField text - C = new JTextField(lO);
JButton button_OK = new JButton ("OK");
JPanel panel_Input = new JPanel();
JPanel panel = new JPanel ();

public void init () {
panel_Input.setLayout(new GridLayout(3, 2, 5, 5));
panel.setLayout(new BoxLayout(panel,
BoxLayout. Y_AXIS) ) ;
panel_Input.add(label_A);
panel_Input.add(text_A);
panel_Input.add(label_B);
panel_Input.add(text_B);
panel_Input.add(label_C);
panel_Input.add(text_C);
panel.add(panel_Input);
panel.add(button_OK);
panel.add(label_Rl);
panel.add(label_R2);
getContentPane() .add(panel);
button_OK.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
// To be implemented
}
}

(a) Briefly explain the major difference between Applet and JApplet? (2%)

(b) Draw the layout that will be rendered when the JApplet is initialized in browser. (6%)

(c) Complete the implementation of the method actionPerformed above so that the roots can be calculated and displayed. (6%)

(d) Write the html file for starting this JApplet. (4%)

( e) Suggest a way for implementing the listeners of more than one button. (2%)

面向对象编程代考
面向对象编程代考

更多代写:Cs北美代考推荐  托福网考代考  英国A-level补习  definition essay怎么写  case study写作技巧  计量经济数据分析代写

合作平台:essay代写 论文代写 写手招聘 英国留学生代写

The prev: The next:

Related recommendations

1
您有新消息,点击联系!