Java Programming Language an Application to Projects (CSCT4103)

Computer Science - COS

Semester: First Semester

Level: 400

Year: 2016

Page 1 of 2
SCHOOL: H.T.T.T.C. DEPARTEMENT: CS LECTURER(S): Mr. DEMANOU YMELE
COURSE CODE: CSC315 COURSE TITLE: Java Programming OPTION: FCS 300
DATE: HALL: ……. TIME: 2 hrs NATURE: Exam
INSTRUCTION: ………………………………………………………………………………… …………….
Section A: MCQ (20 marks)
1. Which three are legal array declarations?
1)int [] myScores []; 2) char [] myChars; 3) int [6] myScores; 4) Dog myDogs []; 5) Dog myDogs [7];
A. 1, 2, 4 B. 2, 4, 5 C. 2, 3, 4 D. All are correct.
2. What will be the output of the program?
int x = 100; double y = 100.1;
boolean b = (x = y); /* Line 7 */
System.out.println(b);
A. Compilation fails B. true C. false D. An exception is thrown at runtime
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. What is the prototype of the default constructor?
A. Test( ) B. Test(void) C. public Test( ) D. public Test(void)
5. Which of these keywords is used to refer to member of base class from a sub class?
A. Upper B. super C. this D. None of the mentioned
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 C. Public method can only be called by object of its class.
B. 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. Which method can be defined only once in a program?
A. main method B. finalize method C. static method D. private method
9. Which of the following statements are incorrect?
A. static methods can call other static methods only. B. static methods must only access static data.
C. static methods can not refer to this or super in any way.
D when object of class is declared, each object contains its own copy of static variables.
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
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)
A beauty salon sells products (perfume, soap). It offers 2 types of memberships: Premium and Gold. Premium and
gold members receive a discount of 15% and 10% respectively, for all products bought. Customers without
membership receive no discount. You have been hired by the salon to develop their discount system.
The system shall consist of Four classes: Customer, Visit and Customers subclasses Premium and Gold, as
shown in the class diagram below. It shall compute the total bill if a customer purchases x fcfa of products for a
visit. The constructor of class Customer takes as parameter the customers name, type, and a boolean indicating
whether a Customer is member or not. That of Visit takes as parameter the customer, the date and the product cost
1. Which access modifier is appropriate for pDiscount and gDiscount
2. Define the class Customer.
3. Define Premium and Gold as subclasses of customer provide a constructor for each.
4. Provide the definition of class visit
5. Write instruction to add customer fields to a JTable
6. Write a test program to exercise all the classes. Your test program should have at least 4 instructions:
- An instruction creating a customer of type premium
- An instruction creating a customer of type glod
- Two instructions creating visits for the two customers
7. We would like to persist the customers and their transactions. For simplification, we are storing only customers
into database. Also assume that the Entity Manager (em) is injected and the persist method available (public
persist(Object o))
a) Redefine Customer class as Entity which ID is id of type integer
b) Write instruction to persist a customer and another one to find a customer by id
1
m
www.schoolfaqs.net