Programming 2B ASSIGNMENT 2
Programming 2B ASSIGNMENT 2
Module Programming 2B
NQF Level 6
Credits
Weighting 20%
Examiner L. ZUKA
This question paper consists of 6 pages including the cover page.
STEP 1:
Scroll down to the Individual Assignment Section of your myClass page.
STEP 2:
Click on the Submission Icon
STEP 3:
Once you have added your attachment, it will appear in the File submissions block, click on ‘Save
changes'
STEP 6:
It is important to note that the assignment is NOT submitted yet – it will state “Draft (not submitted)”
Should you click on “Edit Submission”, you will be taken back to Step 4, where you will be able to
reupload the correct document.
To confirm the draft version that is already there, click on “Submit assignment”.
STEP 7:
To confirm your submission, be sure to check the box that appears there, and then click on ‘Submit’.
STEP 8:
Once you have clicked on Continue, you will see that the submission status has been changed to
“Submitted for grading”
Only once it states submitted for grading, the process of the online submission is complete.
SECTION A
Question 1 (20)
Placing data conversion attempts in a try block allows you to handle potential data
conversion errors caused by careless user entry.
b. a. True
b. False
A catch block is a method that can be called directly and takes an argument that is some
type of exception.
c. a. True
b. False
Comma-separated values (CSV) is a file format strictly used for working with Java and
databases.
d. a. True
b. False
Since variables declared within a try or catch block are local to that block, the variable
goes out of scope when the try or catch block ends.
e. a. True
b. False
The ____________________ class comprises less serious errors that represent unusual
g.
conditions that arise while a program is running and from which the program can recover.
In order to use a variable both with a try or catch block and afterward, you must declare
h.
the variable before the ____ block begins.
The ____ method returns the last Path element in a list of pathnames.
i.
Any of the file input or output methods in a Java program might throw an exception, so
j.
all the relevant code in the class is placed in a ____ block.
SECTION B
Question 2 (20)
What is the problem with the above interface? How would you correct the interface?
Using the code above, would it be possible to create a class in which you declare a Car
object with the statement Car myCar = new Car("Honda");?
Explain why or why not.
SECTION C
Question 3 (30)
Create a Division application that accepts 2 values- a numerator and denominator and
create a try-catch block that will catch any type of Exception object and display the
message “Invalid operation”.
Question 4 (30)
Write a Java program that reads a file and throws an exception if the file is
empty.
“End of Paper!!!”