Ppa115d_tro115d_fa2 2024s1 Paper Moderated
Ppa115d_tro115d_fa2 2024s1 Paper Moderated
SEMESTER: 1
ASSESSMENT: Formative Assessment 2
SPECIAL REQUIREMENTS
NONE
NON-PROGRAMMABLE POCKET CALCULATOR
SCIENTIFIC CALCULATOR
COMPUTER ANSWER SHEET
GRAPH PAPER
DRAWING INSTRUMENTS
OTHER:
1. Create a folder on D:\ Drive and rename the folder your student number.
2. Save all your work in the folder you have created
3. Open a text editor (notepad++ is recommended) or MS Word and save your document in your
student number folder.
4. Open the browser.
5. Type http://ec.tut.ac.za in the address field of the browser and press enter.
6. Click Login.
7. Type in student number for username and your tut4Life password.
8. Click Login button.
9. Click [Continue]
10. Select [Student]
11. Select [Tests]
12. Select [Webtest 4]
13. Type or Select PPA115D/TRO115D into the first text field.
14. Type or Select 20241 into the second text field.
15. Type or Select J into the third text field (The “J” must be a capital letter).
16. Click "Next"
17. Click on the "Write" button.
18. Click on "[Start]" and you will be in the test to submit your answers.
19. Click on [Section] on the test to submit each Questions and click [Go] to submit your answer-
Copy your answer and paste it in the space provided.
20. Click [Test] to move to the next or previous Questions.
21. Under each question click edit to update your answer.
1
PPA115D/TRO115D FA2 20241
QUESTION 1 [6]
True/False
Instructions
Log on to EC and proceed to the correct test. Select section 1 and provide your answers to this
question therein.
STATEMENT
1.1 In a counter control loop, the loop continues until a certain condition is met.
1.2 The purpose of logical operators in programming is to compare two values or expressions
and determine the relationship between them.
1.3 In a switch statement in Java, if the break statement is omitted in a case block, the code
associated with the matching case executes, and the code in subsequent cases until a
break statement is encountered or the end of the switch statement is reached.
1.4 The body of a pre-test loop may never execute if the loop condition is initially false.
1.5 The declaration of a local variable in a method can appear anywhere in that method.
2
PPA115D/TRO115D FA2 20241
Question 2 [6]
Multiple Choice
Instructions
Log on to EC and proceed to the correct test. Select Section 2 and provide your answers to this
question therein.
2.2 What is the correct order of precedence (from highest to lowest) for the following types of
operators in Java?
a. Logical, relational, arithmetic
b. Relational, logical, arithmetic
c. Arithmetic, relational, logical
d. Arithmetic, logical, relational
2.5 Which of the following statements does not correctly describes the components of a for loop in
Java?
a. The loop condition is evaluated after each iteration.
b. The loop body is mandatory.
c. The initialization statement is executed after the loop body.
d. The update statement is optional.
2.6 Which of the following statements correctly describes the use of a switch statement in Java?
a. A switch statement is used to execute a block of code repeatedly until a condition is met.
b. A switch statement is used to execute a block of code only if a specified condition is true.
c. A switch statement is used to execute one block of code from multiple possibilities based on
the value of an expression.
d. A switch statement is used to define and initialize variables.
3
PPA115D/TRO115D FA2 20241
Question 3 [12]
Short Questions
Preparations
• Open Microsoft word or notepad and type in your answers therein.
• Question 3.1 to Question 3.3 answer must be typed onto this notepad/word document.
• Submit each question under the slot/section provided on EC.
• Make sure you submit your answers whenever you are done with a question.
Instructions:
• Log on to EC and proceed to the correct test. Select Section 3 and provide your answers to this
question therein.
• Remember not to code the solutions for this question using an Editor as they will consume a lot of
your time. Provide only the required structure as instructed by the question.
3.1 Write only the required simple-if for the following using the Java syntax for each.
3.1.1 Determine if the value of the results is 75. The value is stored in a variable called results. (2)
3.1.2 Determine if a student qualifies to be a mentor. To be a mentor, the students must be in their
second year (2) of study and have an average of at least 80% for all subjects. The input values
are stored in variables called yearOfStudy and average respectively. (2)
3.1.3 Determine if the remainder of valueA divided by valueB is greater than valueC. (2)
3.2 Write only the required statement(s) for the following using the Java syntax for each.
3.2.1 Write a for-loop in Java that has an initial value of 3, a final value of 25 and an increment of
2. The counter control variable must be stored in a variable called counter. (2)
3.2.2 Re-write the for-loop above in 3.2.1 in descending order. (2)
3.3 In your own words, what happens to a loop without an update to the counter control variable. (2)
4
PPA115D/TRO115D FA2 20241
Question 4 [16]
Preparations
• Create a folder in the D drive called “D:\My Documents\StudentNumber\Question4\”, where
StudentNumber is your actual student number.
• Create a new file in Notepad++ called “MealCostApp.java”. Open the file and complete the
question as instructed below.
Sample Output
5
PPA115D/TRO115D FA2 20241
Figure 4.3: Invalid Choice
6
PPA115D/TRO115D FA2 20241
Question 5 [10]
Preparations
• Create a folder in the D drive called “D:\My Documents\StudentNumber\Question5\”, where
StudentNumber is your actual student number.
• Create a new file in Notepad++ called “PatternGeneratorApp.java”. Open the file and complete
the question as instructed below.
Write a Java program that will help them generate patterns. The patterns must have 10 numbers in the
series and the starting number for the pattern can be any random number from 1 to 10.
NB: Use the Random class to generate the starting number.
Sample Output
Figure 5.1
Figure 5.2
Figure 5.3
7
PPA115D/TRO115D FA2 20241
Question 6 [30]
Selection Control Structure
Preparations
• Create a folder in the D drive called “D:\My Documents\StudentNumber\Question6\”, where
StudentNumber is your actual student number.
• Create a new file in Notepad++ called “WaterTariffApp.java”. Open the file and complete the
question as instructed below.
Just Metering has requested your service to develop an application that will help generate an
invoice/bill for their clients.
Develop a Java application that will help Just Metering to create an invoice for their clients. To
successfully do that, proceed as follows:
6.1 Develop a Java application class WaterTariffApp and save this in a file called WaterTariffApp.java.
6.2 Declare all necessary variables and constants.
6.3 Prompt the user for the following (See Figure 6.1):
6.3.1 The customer account number and
6.3.2 The water usage in kilolitres.
8
PPA115D/TRO115D FA2 20241
Figure 6.1: Prompting user input.
6.4 Determine the current water usage charge for each category using the information in Table 6.1
above.
6.4.1 If the water usage is a negative number, the program must display an appropriate error
message as shown in Figure 6.2.
9
PPA115D/TRO115D FA2 20241