IP_Tute_09_merged

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

Faculty of Computing

IT1120 – Introduction to Programming


Year 1 Semester 1 (2024)
Tutorial 09

Question 1

The roots of a function can be calculated as given below.

Write a pseudocode to input any three values for a, b, c and to calculate the roots.

Hint: Use pow() and sqrt() methods in Java Math class.

Question 2

Write a pseudocode method called circleArea() that take the radius of a circle as an
argument / parameter, then calculate area and return the area.

In the Main Method, read the radius value as an user input via keyboard, then call the
circleArea() method to display the result.

Question 3

Write three Java methods do the following

• add() – add two integers pass as parameters and return the result
• multiply() – multiply two integers pass as parameters and return the result
• square() – receive an integer as a parameter and return the result after multiplying
the number by itself

Use the above methods in the Main Method to calculate the result of the following
mathematical expressions:

i. (3 ∗ 4 + 5 ∗ 7)2
ii. (4 + 7)2 + (8 + 3)2

1
Question 4

Write a pseudocode to calculate the Final Mark and Grade of 5 students for a subject.

a) Write a method called calcFinalMark() to calculate the final mark of the sub-
ject. When calculating the final mark, 30% is taken from the assignment mark and
70% is taken from the exam paper mark.
Method should return the final mark when assignment mark and exam paper mark
are given as parameters to the method.

b) Write a method called findGrades() to return the grade obtained for the given
final mark.
Grades are calculated as follows:

c) Write a method called printDetails() to print the Name, Final Mark and Grade
of a student.
Your output should be as follows:

d) In Main Method, ask the user to enter the Name, Assignment Mark (out of 100)
and the Exam Paper Mark (out of 100) of the 5 students from the keyboard.
Display the Name, Final Mark and Grade of a student.
Hint: Use the methods written in section b) and c)

2
Faculty of Computing
IT1120 – Introduction to Programming
Year 1 Semester 1 (2024)
Tutorial 10

Question 1

a) Write a Java program that checks if a mark entered from the keyboard is greater
than or equal to 0 and less than or equal to 100.
Use assert to verify the condition. If the mark is not in the given range, program
should throw an Assertion Error with the message ‘Invalid Mark’. If not display
‘Mark is Validated’.

b) Modify the above program to have a method called validateMark() and use assert
inside the method.

You might also like