0% found this document useful (0 votes)
85 views3 pages

CSC 203 Examination Tutorials

The document contains 7 questions about computer programming concepts in Java for a university exam. The questions cover topics like syntax errors, control flow, classes, methods, and writing simple programs to calculate areas and perimeters of shapes.

Uploaded by

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

CSC 203 Examination Tutorials

The document contains 7 questions about computer programming concepts in Java for a university exam. The questions cover topics like syntax errors, control flow, classes, methods, and writing simple programs to calculate areas and perimeters of shapes.

Uploaded by

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

Lead City University, Ibadan

Faculty of Basic Medical and Applied Sciences


Department of Computer Science
Tutorials 2023/ 2024 Academic Session

B.Sc. Degree Examinations


Course Title: Computer Programming I
Course Code: CSC 203
Number of Units: 3

Question 1:

Consider the following java program snippet:


int sum = 0; i, j = 2;
for (i = 10; i >= 0; i – = 2); {
sum += j%i;
j += 3;
}
System.out.print(“Total accumulated Sum = ”, sum);

i. Identify and correct any syntax and logical errors in the snippet.
ii. Explain what the snippet does in summary.
iii. Write out the output from the program if the semicolon in line 2 is not
removed.

QUESTION 2
1. a) Write a simple Java code to calculate the sum of even number between 1 and 1000.
Make sure you use if and for loop control. Please print out the even numbers and also
print out their sum.
b) Write the syntax for the following control statements
 if-else
 for loop
 while loop
 do while loop
c) Explain the following
 class in java and also mention the types of access modifiers that can be applied
to a class.
 constructors and the types
 data types and the types
 method
 variable
QUESTION 3

Write a program that reads the user’s age and then prints “You are a child” if the age <
18, “You are an adult” if 18 ≤ age < 65, and “You are a senior citizen” if age ≥ 65. Use
java scanner utility to perform this operation.

QUESTION 4

In a class, write a simple java code to calculate the area of a rectangle then print the
result. Then in the same class calculate the area of a circle and print the result. Ensure
that you solve the problems using methods within the class and local variables. Then use
the instance of the class to call the methods. Do not use return statement.

QUESTION 5
An engineer in a construction company requests your expertise to create a simple
computer program that will help in his construction work. He presents the following
shapes to you:

30cm

60cm

50.30cm

20.60cm

Now you are required to write a simple java class, that has class a variable and uses
constructors to calculate the perimeter and area of the shapes as they apply and prints the
results. (Follow the instruction strictly)
QUESTION 6

Correct if there is error


public class detectError
{
void Calculate( int length, double breadth)
{
double rectPerimeter = 2*(length + breadth );
System.out.println("The perimeter of the rectangle is" + rectPerimeter);
}
void Calculate(int rectArea)
{
int area = rectArea*rectArea;
System.out.println("The perimeter of the rectangle is" + area);
}
public static void main(String[] args)
{
detectError detect = new detectError();
detect.Calculate(56,"89.9");
detect.Calculate(4.5);
}

QUESTION 7
Lead City University was designed to accommodate 15, 000 students. At present, there are 9000
students and the growth rate is 5% per year. If the present growth rate is maintained, write a
program to determine the population of the school per year and in how many years' time the
capacity will be exceeded.

You might also like