Oop216d - Oor216d CT5 2024S1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CT5

FACULTY: INFORMATION & COMMUNICATION TECHNOLOGY


SUBJECT: OBJECT-ORIENTED PROGRAMMING
OOP216D AND OOR216D
Instructions
• Please login to EC to indicate your attendance for this
assessment (signing the class list). By signing the class list, you
agree that you understand and will adhere to the rules and
regulations of Tshwane University of Technology.

• Submission of answers:
• Log into EC
• Select [Student], then select [Tests], then select [Web Test 4]
• Select the subject code OOP216D or OOR216D
• Select the intake 20241
• Select the test number M
• Each question will have a separate section on EC where you
CLASS TEST 5 1st Examiner
should paste your answers. Answer each question in its
Duration: 50 min M LIEBENBERG
correct section.
Date: 23 May 2024
• Copy your answers from your source files and paste it in the
Total: 36 Moderator
provided spaces and click “GO” every time you are done. By
Pages: 3
clicking on “GO” you are actually saving your answer for that
question. DO NOT forget to click “GO”.
• Save your work frequently.
• This is a closed book test. NO additional resources, like the
“Debugging is twice as hard as writing the code in the first place. Internet or EC may be used for help.
Therefore, if you write the code as cleverly as possible, you are, by • You may NOT use any flash sticks during the test.
definition, not smart enough to debug it.” • Add your name as a comment on the first line in each file.
Brian W. Kernighan

1
Question 1 (File Manipulation): //20//
For this question, you are provided with an incomplete solution to a concrete class used to read and write records to a sequential text file.
The class consist of a file instance data member that represents the file to be manipulated. The constructor will initialize the file instance data member.

The saveToFile() method will receive the record as a parameter and write it to a new line in the text file.

The readFromFile() method will read all the records from the text file and return them as a list of String values.

Follow the provided code with its comments and fill in the missing code pieces under Section 1 on EC.

2
Question 2 GUI): //16//
Preparation:
1. Create a new NetBeans project called Question2 without a main method.
2. Add a new Java frame class called TriangleGUI to the Question2 project and create the GUI as described below.
Question:
For this question, you will create a basic, but functioning GUI as shown in Figure 1 to calculate the area of a triangle.

Figure 1

The GUI consists of the following components:


• Three labels that describe the content of the text fields.
• Three text fields. The user will have to enter the base and height of the triangle.
• One button will use the entered values, calculate the area, and place the answer in the third text field.
• The area of a triangle is calculated using the following formula:

Submitting your answers:


Follow the instructions on EC under section 2 and submit your answers to this question.
3

You might also like