0% found this document useful (0 votes)
12 views12 pages

ST3 Practice Memo

The document contains a series of programming questions and answers related to Java, including true/false statements, multiple-choice questions, and short answer questions. It covers topics such as control structures, operators, boolean expressions, and basic programming logic. Additionally, it includes a problem-solving section for creating a TV purchase finance calculator program.

Uploaded by

ntandogift63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views12 pages

ST3 Practice Memo

The document contains a series of programming questions and answers related to Java, including true/false statements, multiple-choice questions, and short answer questions. It covers topics such as control structures, operators, boolean expressions, and basic programming logic. Additionally, it includes a problem-solving section for creating a TV purchase finance calculator program.

Uploaded by

ntandogift63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Question 1 (TRUE or FALSE) [10]

State whether the following statements are TRUE or FALSE


Statements Answer

1.1 The condition in an if-else statement must always be a relational True


expression.
1.2 The unary operator "--" increments the value of a variable by 1. False

1.3 A trace table is a tool used to visualize the flow of control in a True
program's execution.
1.4 In Java, the operator > is used to check if a value is less than False
another value.
1.5 The || operator returns false if at least one operand is false. False

1.6 The parentheses ( ) can be used to override the default True


precedence of operators in Java expressions.
1.7 A diamond symbol in a flowchart indicates the start and/or end False
of a program.
1.8 if - is a java keyword. True

1.9 Compound assignment operators perform operations on variables False


of different data types.
1.10 The condition to check if quizMark is at least score 80% is; False
if(quizMark >= 80%)

Question 2 (MULTIPLE CHOICE) [10]


Select the correct answer for the following questions. Mark with an X.
2.1 In Java, what is the role of the "else" statement in an if-else
statement?
A. It defines a new condition A

B. It specifies the condition for the "if" statement B

C. It provides an alternative block of code to execute when the "if" C


condition is false
D. It terminates the program D

2.2 Compound assignment operators are used to perform:


A. String concatenation A

B. Arithmetic operations and assignment B

C. Comparison operations C

D. Logical operations D

2.3 Which unary operator decrements a variable by 1?

A. ++ A

B. -- B

C. += C

D. == D

2.4 In an expression a || b && c, if a is true, b is false, and c is true, what


will be the result of the expression?
A. true A

B. false B

C. Compilation error C

D. Depends on context D

2.5 What will be the exact output of the following segment of code? int
a = 25;
System.out.print("1"); if(++a
< 25)
System.out.println("2"); else
System.out.println("3");

A. 1 A

B. 2 B

C. 3 C

D. 13 D
2.6 What will be the exact output of the following segment of code?
int x=10, y=20, z=30; if(x > y || x > 10) z++; else z--;
System.out.println("z "+z);

A. z = 29 A

B. z = 30 B

C. z 29 C

D. z 31 D

2.7 In a Boolean expression, which operator is used to perform logical


negation?
A. && A

B. || B

C. ! C

D. ^ D

2.8 The following code section will display the word DONE only if which of
the following options is true?

if (a == 1 && b == 3 && c != 5)
System.out.print(“DONE”);

A. a is one, B is 3, C is 5. A

B. either a is 1 or b is 3 and c is not 5. B

C. either a is 1 and b is 3, or C is five. C

D. a is 1, b is 3 and c is less or greater than 5. D

2.9 Which of the following expressions is equivalent to (x > 5)&&(x < 10)?

A. !(x <= 5) && (x >= 10) A

B. (x > 5) || (x < 10) B


C. !(x <= 5 || x >= 10) C

D. !(x > 5) || (x < 10) D

2.10 int a = 22; int b = 2 *


a + 13 - --a; int c = b
+ 22 - a--;

if(b > c)
System.out.println("Greater" + b); else
System.out.println("Less" + c);

A. Greater36 A

B. Less37 B

C. Greater37 C

D. Less36 D

Question 3 (Short Answers) [15]


3.1 What will be the exact output of the following segment of code?

int a = -5;
int b = -3;

if(a < b)
System.out.print(a);
System.out.println(b);

-5-3

3.2 What will be the exact output of the following segment of code?

boolean bChoice = false;

if (!bChoice)
System.out.println("Go");
else
System.out.println("Stop");

Go

3.3 What will be the exact output of the following segment of code?
int x = 23; int y = 123;

if (x > 23 || y <= 123)


System.out.print(x + " " + y + " " + (y + x)); else
System.out.print(x + " " + y + " " + (y - x));

23 123 146

3.4 Re-write Only the if statement line to give correct result:

if(17 < iAge < 60)


sCategory = "ADULT";

if(iAge > 17 && iAge <


60)

3.5 Write two java statement that prints “Same sign” if iNum1 and iNum2 have the
same sign (-/+).

if(iNum1 * iNum2 > 0)


System.out.println(“Same sign”); OR if(iNum1 > 0 &&
iNum2 > 0 || iNum1 < 0 && iNum2 < 0)
System.out.println(“Same sign”);

3.6 Normal body temperature ranges from 36.1°C to 37.2°C. Write two java
statements that checks if the variable rBodyTemp is within limits and display "Normal
body temperature".

if(rBodyTemp >= 36.1 && rBodyTemp <=


37.2) System.out.println("Normal body
temperature");
Question 4 (Convert flowchart to Java program) [10]
The flowchart below illustrates a program that calculates and displays the square root
of three divided by a given integer number. However, before performing the
calculation, you need to check if the input value is valid to avoid undefined results.
Figure out what the condition should be and write the Java code that implements this
chart.

start

"Enter an integer number: "

iNum

is___________? True

False

𝑟𝑟𝑟𝑟𝑟 = √3/𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 "Error! Calculation not possible."


𝑟𝑟𝑟

"The answer is: " + rAns

end
Possible Solution

Question 5 (Write a Java program from IPO table) [10]


Consider the following program that reads an integer from the user, calculates, and
displays both the double and half of the entered value. Complete a trace table to
determine the final output of the algorithm. Use a value of 5 as input for variable
iValue.
Step Type of statement Display
1
2
3
4
5
6
Exact
Output
Question 6 (Problem solving with Java programs) [20]
TV Purchase Finance Calculator
You have been assigned the task of creating a program that helps customers choose
a TV and provides them with information about instalment plans. The program will
present customers with three TV options of different sizes, along with their prices. The
customers will choose an option by selecting the corresponding letter. Your program
should validate the choice, calculate the monthly instalment, and display the credit
price after interest. Interest charged at 74.15%.
Program Requirements:
Write a Java program that meets the following requirements:
• Use the DecimalFormat class to format currency values and escape sequences
for alignment and spaces.
• Declare constants to store the prices of three TV options. This ensures that any
changes made to the value of a constant will automatically be reflected in all
displays and calculations.
• Display the TV options to the user:

• Read the letter from the user to select a TV.


• Use if statements (without else) to select the correct TV's price based on the
user's choice.
• Use an if-else statement to validate if the choice is not valid (not A, B, or C),
display the message:

• The program should only accept uppercase letters as valid. Lowercase should
be treated as invalid.

• If the choice is valid, calculate the monthly instalment amount and the total
credit price. The total credit amount financed, includes the original TV price
plus the interest amount is spread out over 24 months in instalments.
Possible solution:

You might also like