(CSE231) Spring - 2022
(CSE231) Spring - 2022
FACULTY OF ENGINEERING
Computer Engineering and Software Systems Program
Spring, 2022/2023 Course Code: CSE 231, CSE126 Time allowed: 2 Hrs.
Advanced Computer Programming
The Exam Consists of Three Questions in Four Pages. Maximum Marks: 40 Marks 1/4
Important Rules: ﻌﻠﻴﻤﺎت ﺎﻣﺔ
Having a (mobile -Smart Watch- earphones) inside the ﺳﻤﺎﻋﺔ اﻷذن( داﺧﻞ- اﻟﺴﺎﻋﺎت اﻟﺬﻛﻴﺔ- ﺣﻴﺎزة )ا ﻤﻮل
examination hall is forbidden and is considered as a . ﻨﺔ اﻻﻣﺘﺤﺎن ﻌﺘ ﺣﺎﻟﺔ ﻏﺶ ﺴﺘﻮﺟﺐ اﻟﻌﻘﺎب
cheating behavior. ﻻ ﺴﻤﺢ ﺑﺪﺧﻮل أي ﻛﺘﺐ أو ﻣﻼزم أو أوراق داﺧﻞ اﻟ ﻨﺔ
It is forbidden to have any references, notes, books, or .وا ﺎﻟﻔﺔ ﻌﺘ ﺣﺎﻟﺔ ﻏﺶ
any other materials even if it is not related to the exam
content with you in the examination hall.
Question (1): 15 (MARKS)
(a)
public class Test extends Exam {
public static void main(String[] args) {
System.out.println(new Test());
}
public Test() {
System.out.print("t");
}
class Exam {
private static int counter;
public Exam(){
this("r");
System.out.print("c");
}
public Exam(String s){
System.out.print("Co" + s + s);
System.out.print(this);
}
public String toString(){
String retVal;
if (counter == 0) {
counter++;
retVal = "e";
} else {
retVal = " A";
}
return retVal;
}
}
2- Complete the missing: The “Exam” Class inherits the Class …………. and it is
…………………the “toString” Method.
2
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer Engineering and Software Systems Program
Spring, 2022/2023 Course Code: CSE 231, CSE126 Time Allowed: 2 Hrs.
Advanced Computer Programming
The Exam Consists of Three Questions in Four Pages 3/4
5- The keyword final has different meanings according to the usage, explain it is
meaning in case of usage with variables, classes and methods.
(b)
1 public class Test {
2 public static void main(String[] args) {
3 Exam f = new FinalExam();
4 if(f instanceof Exam)
5 {
6 System.out.println("1");
7 }
8 else if (f instanceof FinalExam) {
9 System.out.println("2");
10 }
11 else
12 {
13 System.out.println("3");
14 }
15 }
16
17 }
18 class Exam{}
19
20 class Midterm extends Exam{}
21
22 class FinalExam extends Exam {}
3
AIN SHAMS UNIVERSITY, FACULTY OF ENGINEERING
Computer Engineering and Software Systems Program
Spring, 2022/2023 Course Code: CSE 231, CSE126 Time Allowed: 2 Hrs.
Advanced Computer Programming
The Exam Consists of Three Questions in Four Pages 4/4
Create three classes: Triangle, Square and Rectangle which have the following
properties:
- You can create one array that has objects of these class.
- You can sort the objects in this array using “java.util.Arrays.sort” method based
on the area of these objects.
- These classes have a method “printData” that prints the data of their objects.
- An exception is thrown when invalid data is entered.
- An incremental method is used to increment the object data and this method runs
as a thread.
- You can compare between any 2 objects of these classes (based on their areas)
using the method “equals”.
Write a test class that has a main method to show the usage of the above features of
these classes.