0% found this document useful (0 votes)
20 views7 pages

CS244 Final Exam Spring 2019-2020 v2.0

This document outlines the final assessment for the Advanced Programming Applications course (CS244) taught by Dr. Omar Shalash. It includes instructions for students regarding submission, question formats, and specific programming concepts to be addressed in the exam. The exam consists of multiple-choice questions, true/false statements, and coding-related tasks, with a total of 40 marks available.

Uploaded by

abdo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

CS244 Final Exam Spring 2019-2020 v2.0

This document outlines the final assessment for the Advanced Programming Applications course (CS244) taught by Dr. Omar Shalash. It includes instructions for students regarding submission, question formats, and specific programming concepts to be addressed in the exam. The exam consists of multiple-choice questions, true/false statements, and coding-related tasks, with a total of 40 marks available.

Uploaded by

abdo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COLLEGE OF COMPUTING & INFORMATION

TECHNOLOGY
Department:
Lecturer: Dr. Omar Shalash
Course Title: Advanced Programming Applications
Course Code: CS244
Semester: Second 2019/2020 Date: 13/06/2020
Time: 2 Hours Marks: 40

FINAL ASSESSMENT – TAKE HOME EXAM


Notes for Students:

• Kindly start by writing your: Full name, Registration number, and department on your answer papers.
• Kindly attach a copy of your Student/ National ID to your submitted file.
• Carefully number your answer papers and write the question number you are answering.
• Exam deadline for submission is 11:30 am 13/06/2020.
• The PDF file which include all your answer papers and ID scans should be renamed to [Your-Full-Name]-
[Your-Reg.Number]-CS244_Final_Answer.
• Submit (Turn in) the Exam on Google Classroom
Answer all questions. Show your work so that partial credits may be assigned
Question #1 (10 Marks):
Circle whether the following statements are True or False, Correct False and explain your
answer in both cases:
TF 1. Java programs can be compiled and run from the command line.

TF 2. You can invoke “socket.InetAddress()” on a Socket object, say socket, to obtain an InetAddress
object.

TF 3. The name of a Java class must begin with a capital letter; otherwise the program will not run.

TF 4. Java methods are private by default, which means they cannot be called from outside of that
file.

TF 5. To start a thread object, run() method is invoked.

TF 6. A method signature includes information about the number and types of parameters that a
method has.

TF 7. To be notified when a user clicks on a button, the program must add an event handler to the
button.

TF 8. To connect to a server running on the same machine with the client, "125.0.0.1" can be used
for the hostname.

TF 9. If FileNotFoundException occurs when a program is executed, it means that the program


contains a bug.
TF 10. getInputStream() and getOutputStream() are used to produce InputStream and OutputStream
on the socket.
Page 1 of 7 EDQMS 2/3
Question #2 (10 Marks):
Choose the correct answer and explain why:
1. Consider the following statement which is defined in a class.
private static int serial = 0;
The keyword static:
a. Means that serial is a constant.
b. Ensures that only one instance of serial exists and it will be shared by all objects of type Test.
c. Means that serial should be capitalized (e.g. SERIAL) to comply with Java naming conventions.
d. Results in a syntax error because it is missing the keyword final.
e. None of the above.

2. Which of the following statements about constructors is correct:


a. A constructor has the same name as the class name.
b. A constructor is responsible for the initialization of an object's instance fields.
c. Constructor methods have no return type.
d. A class can have several constructors.
e. All of the above.

3. If an exception occurs in a try-catch block, the code in the finally clause ________.
a. is not executed if the exception is caught
b. is not executed
c. may be executed
d. is executed
e. None of the above.

4. In the example code fragment shown below, the keyword abstract:


public abstract class Test { // . . . more class code
a. Implies that no object of type Test can ever be created.
b. Makes class Test independent of all other classes; in particular, it is not a subclass of the class
Object.
c. Requires the implementation of the toString() method.
d. Ensures that only one object of type Test is ever created.
e. All of the above.

5. Which class do you use to write data into a text file?


a. Scanner
b. System
c. File
d. PrintWriter
6. In the Java graphics coordinate system, where is (0,0)? _______
a. Center of the pane
b. Upper right corner
c. Upper left corner
d. Lower right corner
e. Lower left corner

Page 2 of 7 EDQMS 2/3


Use the class declaration shown on the right and the following declarations to answer the next three
questions:
class SuperClass {
SuperClass obj1 = new SuperClass();
private int x;
SuperClass obj2 = new SubClass(1, 2);
private int y;
public SuperClass ( )
7. What will the following statement display to the
{ x = 2; y = 3; }
screen?
public SuperClass (int x, int y)
System.out.println (obj1);
{ this.x = x; this.y = y; }
a. Something like: SuperClass@4e3380fa
public String toString ( )
(the Object implementation of toString())
{ return "Numbers are: " + x + "
b. Numbers are: 1 and 2
and " + y; }
c. Numbers are: 2 and 3
public int returnSum( )
d. Numbers are: 2 and 3 and 9
{ return (x+y); }
e. None of the above.
}
8. What will the following statement display to the
class SubClass extends SuperClass {
screen?
private int z;
System.out.println(obj2);
public SubClass( )
a. Something like: SubClass@4e7770bb
{ super( ); }
(the Object implementation of
public SubClass(int x, int y)
toString())
{ super(x, y); z = 4; }
b. Numbers are: 1 and 2
public int returnSum( )
c. Numbers are: 2 and 3
{ return (super.returnSum() + z);
d. Numbers are: 1 and 2 and 3
}
e. None of the above
}
9. Given the following statement, what will display to the screen?
System.out.print("Sum is:" + obj2.returnSum());
a. Sum is: 20
b. Sum is: 200
c. Sum is: 4
d. Invalid statement – won’t compile
e. None of the above.

10. Analyze the following code: (Choose all that


apply.) class Test {
private double i;
a. this.i may be replaced by i. public Test(double i) {
b. this(1) must be called before this.t();
System.out.println(ʺDefault constructorʺ). this.i = i;
c. this.t() may be replaced by t(). }
d. this(1) must be replaced by this(1.0). public Test() {
System.out.println(ʺDefault constructorʺ);
this(1);
}
public void t() {
System.out.println(ʺInvoking tʺ);
}
}

Page 3 of 7 EDQMS 2/3


Question #3 (15 Marks):
(4 points) Part a:
Assuming you have a class named Restaurant intended to store information about a restaurant. In each of the
sub questions shown below, a signature of some constructors and methods that could be defined for that class
is given. Write a single statement per sub question that would show how you would call these methods.

For the purposes of this question, you can assume that the following variables have been declared and
initialized, if necessary:
Restaurant restaurant;
String restName;
String restAddress;
String menu;
Person restOwner;
String ownerName;
String[] dessertList;

Do not provide an implementation for these methods.


a. public Restaurant (String name)

b. public String getAddress()

c. public void setOwner (Person owner)

d. public String[] getDessertList ()

(3 points) Part b:

Write a statement that


a. Adds two buttons bt1 and bt2 into a Pane object named pane.

b. Creates a Button object with the text OK.

c. A Scene object for a pane with width and height 100 and 200.

d. Sets the title of a Stage object to "Demo".

e. Displays a stage for a Stage object named stage.

f. Write a statement that rotates a Node object named node to 45 degrees.

Page 4 of 7 EDQMS 2/3


(8 points) Part c:
Write single statements to show how to:
a. Create an ArrayList for storing double values? java.util.ArrayList<E>
+ArrayList() Creates an empty li
b. Append an object to a list? +add(o: E) : void Appends a new elem
+add(index: int, o: E) : void Adds a new elemen
+clear(): void Removes all the ele
c. Insert an object at the beginning of a list? +contains(o: Object): boolean Returns true if this
+get(index: int) : E Returns the elemen

d. Find the number of objects in a list? +indexOf(o: Object) : int Returns the index o
+isEmpty(): boolean Returns true if this
+lastIndexOf(o: Object) : int Returns the index o
f. Remove a given object from a list? +remove(o: Object): boolean Removes the eleme
+size(): int Returns the number
+remove(index: int) : boolean Removes the eleme
g. Remove the last object from the list? +set(index: int, o: E) : E Sets the element at

h. Check whether a given object is in a list?

i. Retrieve an object at a specified index from a list?

Page 5 of 7 EDQMS 2/3


Question #4 (5 Marks):
Find ten errors (there are more than ten) in the following Java class. The errors are both syntactic (compiler
errors) and logical (bugs). For each error, identify the line number and briefly explain how to fix it.

1. private class Circle {


2. public static final float PI = 3.14 ;
3.
4. private double x, y ; /* The center of the circle. */
5. private double r ; /* The radius of the circle. */
6.
7. public Circle(double r) {
8. this(0.0,0.0,this.r) ;
9. }
10.
11. public double Circle(double x, double y, double r) {
12. this.x = x ;
13. this.y = y ;
14. this.r = r ;
15.
16. /* Returns the area of the circle. */
17. public double area() {
18. return PI * r^2 ;
19. }
20.
21. /* Indicates whether a point is on the boundary of the circle.
22. public boolean onCircle(double x1, y1) {
23. int dx = x1 - x ;
24. int dy = y1 - y ;
25. return dx*dx + dy*dy == r*r ;
26. }
27.
28. /* Creates a series of concentric circles */
29. public static void main(string[] args) {
30. int i ;
31.
32. for( int i=0 ; i < 10 ; i++ )
33. Circle c = Circle(10.0*i) ;
34. System.out.println("r="+c.r+" A="+c.area) ;
35. }
36. }

Page 6 of 7 EDQMS 2/3


Good Luck

Page 7 of 7 EDQMS 2/3

You might also like