department of computer science
college of computing
western delta university
first semester examination 2023/2024 session
CSC309 - advanced computer programming (Java) time: 2hrs: 30mins
Answer four (4) questions
Question 1 (Compulsory)
- Define the following:
- Event
- Action Listener
- Wtite a Java program segment that selects an item from a comboBox and assign the selected item to a textField. (4 marks)
- Write a Java method to convert the expression:
Celsius = (Fahrenheit - 32) * 0.55
. (4 marks) - The Malthusian population model for estimating the population of a country is given as:
Pt = P0t0eR(t-t0)
.
where:
Pt is the estimated population at time t,
Po is the initial population at time t0,
R is the population growth rate,
to is the initial time in year,
t is the final time in year in which population is to be estimated- Manually design a form to obtain the necessary input values from the user (4 marks)
- Create a command button with a label
Estimate Population
in the form. Write Java code for theEstimate Population
button so that when clicked, computes the estimated population using the given expression. (9 marks)
- Define the following:
Question 2
- Define Inheritance as used in Object Oriented Programming. (2 marks)
- Illustrate with one example how a class can inherit the methods available in another class. (5 marks)
- Define the following:
- Exception
- Error
- Write a Java program that generates
ArrayIndexOutBoundException
when there is an attempt by the user to access an array beyond the maximum index.(4 marks)
Question 3
- State four Java
IO.File
class methods that can be used to manipulate files. (4 marks) - State the role of the method named in (3a). (4 marks)
- Assuming the user is prompted to enter a name that is either file or directory. Write a Java program that determines if the name exists and invoke a method called
analyzeFile
that gives the properties of the file if the name is a file. (5 marks) - Highlight two major benefits of writing Java applications as unit of classes. (2 marks)
- State four Java
Question 4
- Define the following as used in Java
Class
definition:- Getter
- Setter
- State two differences betweeen a constructor and a method. (3 marks)
- Give a class definition of the computation of area of a box using UML class diagram and with the associated Java code. (5 marks)
- Define the keyword
Super
as used in object-oriented programming. Support your answer with the appropriate Java application. (5 marks)
- Define the following as used in Java
Question 5
- State the function of the following
jTextField
methods:setText
andgetText
. Write a Java program segment to illustrate their use. (6 marks) - Why is the private modifier used in the declaration of variables. (2 marks)
- Manually design a form that retrieves the following items of data from the user: MatNo, Surname, FirstName, Department, and GPA. Write a Java program to transfer the entered data by the user to a database table when a command button called "Transfer Data" is clicked. (7 marks)
- State the function of the following
Question 6
- Define the method
actionPerformed
.(2 marks) - What is a
JLabel
? (2 marks) - State two differences
Radio
button andCheckBox
GUI components. (4 marks) - Given that X and Y are square matrices, i.e.,Design a Java class calledX =[]984537625Y =[]263731468
MatMult
that computes the product of X and Y. Write your output to a formatted file calledmatxy.txt
. (7 marks)
- Define the method