Java Programming Language and Application to Projects (CSCT4103)

Computer Science - COS

Semester: First Semester

Level: 400

Year: 2017

Page 1 of 2
SCHOOL: H.T.T.T.C. DEPARTEMENT: CS LECTURER(S): Mr. DEMANOU YMELE
COURSE CODE: CSCT4112 COURSE TITLE: Enterprise projects and Java programming language
OPTION: ICT Level: 400 Year: 3
DATE: HALL: ……. TIME: 1 hr NATURE: Exam
INSTRUCTION: ………………………………………………………………………………… …………….
Section A: MCQ (30 marks)
1. Consider,
public class MyClass
{ public MyClass(){/code/} }
To instantiate MyClass, you would write?
(a) MyClass mc = new MyClass(); (b) MyClass mc = MyClass();
(c) MyClass mc = MyClass; (d) MyClass mc = new MyClass;
2. The correct order of the declarations in a Java program is,
(a) Package declaration, import statement, class declaration
(b) Import statement, package declaration, class declaration
(c) Import statement, class declaration, package declaration
(d) Class declaration, import statement, package declaration
3. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive
access that accomplishes this objective?
A. public B. private C. protected D.transient
4. Given a class named student, which of the following is a valid constructor declaration for the class?
(a) Student (student s){ } (b) Student student ( ){ } (c) Private final student ( ){ } (d) Void student ( ) { }
5. Which of the following variable declaration would NOT compile in a java program?
(a) int var; (b) int VAR; (c) int var1; (d) int var_1; (e) int 1_var;.
6. A class member declared protected becomes member of subclass of which type?
A. public member B. private member C. protected member D. Static member
7. Which of the following statements is correct?
A. Public method is accessible to all other classes in the hierarchy
B. Public method can only be called by object of its class. C. Public method is accessible only to subclasses of its parent class
D. Public method can be accessed by calling object of the public class.
8. What is the output of the following program:
public class testmeth
{static int i = 1;
REPUBLIC OF CAMEROON
Peace Work Fatherland
***********
THE UNIVERSITY OF BAMENDA
***********
HIGHER TECHNICAL TEACHER TRAINING
COLLEGE (H.T.T.T.C.) BAMBILI
***********
DIRECTORATE OF STUDIES
**********
P.O.BOX 39 BAMBILI
REPUBLIQUE DU CAMEROON
Paix Travail - Patrie
***********
UNIVERSITE DE BAMENDA
***********
ECOLE NORMALE SUPERIEURE
D’ENSEIGNEMENT TECHNIQUE
***********
DIRECTION DES ETUDES
**********
Tél: 33 05 10 69
www.schoolfaqs.net
Page 2 of 2
public static void main(String args[])
{System.out.println(i+” , “); m(i); System.out.println(i);}//End of method “main”
public void m(int i){ i += 2;}//End of method “m”
}
(a) 1 , 3 (b) 3 , 1 (c) 1 , 1 (d) 1 , 0 (e) none of the above.
9. A constructor
(a) Must have the same name as the class it is declared within.
(b) Is used to create objects. (c) May be declared private (d) Both (A) and (B) above
10. Which of these method of String class can be used to test to strings for equality?
A. isequal() B. isequals() C. equal() D. equals()
Section B (50 marks)
The java program below is used to manage a DVD store. It can perform the following operations: save a DVD in the
database, search a DVD given a number, delete a dvd. We assume the dvd has two properties: number (primary key)
and title, respectively of type int and String; and that JPA is used with entity manager em called in the program.
1. Field the blanc (labeled) spaces with the corresponding code in the following list: persit(x); “Error”;
“DVD Saved”; int x; long number; this.tile = title; new Dvd(number,
title);this.title = y; dvd = new Dvd();
@Entity
class Dvd implements Serializable {
@Id
private int number;
private String title;
public Dvd() {}
public Dvd(int number, String title) {
this.number = number;
…………… (a) ………...
}
public int getNumber(){ return number;}
public void setNumber( …(b)……){number = x;}
public int getTitle(){ return title;}
public void setTitle( String y){ …..(c) ……;}
}
class DvdOP{
// ------ Some codes -----
public Dvd searchDvd(int number){
return em.find(Dvd.class, number);
}
public boolean exist(Dvd dvd){
return searchDvd (dvd.number)!=null;
//returns false if the dvd is not yet recorded
}
public void recordDvd(int number, String title){
Dvd dvd = …… (d)…….;
if(!exist(dvd)){persist(dvd);}
else{ System.out.println(……(e)……);}
}
public void deleteDvd(int number){}
public void displayDvds(){}
public static void main(String [] arg){
}
}
2. What happens if we try to record a DVD with a number already used in the database?
3. Provide the instructions of method deleteDvd to delete a DVD which number is passed as argument from the
Database.
4. Provide the instructions of method displayDvds to display all the DVDs recorded the Database.
5. Write some instructions in the main procedure to test your class. [Hint: you may instantiate two DVDs
record them, then display all ]
www.schoolfaqs.net