COM 1202 Introduction To Programming PAPER
COM 1202 Introduction To Programming PAPER
INSTRUCTIONS:
Attempt all Questions in section A and any other two questions from section B
QUESTION 1
(a)Explain the meaning of the following terms (3 Marks)
(i) Algorithm
(ii) String Concatenator
(iii) Variable
(b) Suggest a good variable name for the following variables providing a sample
declaration/assignment statement for each (5 Marks)
(i) Age
(ii) The number of stars in the galaxy
(iii)The average rainfall for the month of December
(iv) Your name
(v) A status value corresponding to failure or success
(c) Discuss four main qualities of a good programming language (4 Marks)
(d) Give the output of the following block of code (3 Marks)
class IfSample {
public static void main(String args[]) {
int x, y;
x = 10;
y = 20;
if(x < y) System.out.println("x is less than y");
x = x * 2;
if(x == y) System.out.println("x now equal to y");
x = x * 2;
if(x > y) System.out.println("x now greater than y");
// this won't display anything
if(x == y) System.out.println("you won't see this");
}
}
(e) Write a complete java program to converts a temperature from degrees
Fahrenheit to degrees Celsius. Use comments to explain your code.
Hint: °C = (°F - 32) x 5/9 (5 Marks)
(f) Write the code for the calculate area button to display the area on jLabel3
using the variables indicated in the following figure (3 Marks)
Page|2
textLen
textWid
QUESTION 2
(a)
(b) Write an algorithm and a program to reads two values, determines the
largest value and prints the largest value with an identifying message
(5 Marks)
(c) Draw a flowchart to find the sum of first 50 natural numbers (5 Marks)
QUESTION 3
(a) Draw a flow chart to calculate the average marks of students (4 Marks)
(b) Write an input process and output (IPO) chart for a payroll system.
(4 Marks)
(c) Write a payroll program in java program using the IPO chart (b) above
(6 Marks)
Page|3
(d) Identify six errors by first indicating the line number then the error and
finally suggest how to correct the error (6 Marks)
1. public class Narf {
2. public static void zoop(string fred int bob) {
3. System.out.println(fred);
4. if (bob = 5) {
5. ping("not ");
6. } else {
7. System.out.println("!");
8. }}
9. }
10. public static void main(String[] args) {
11. int bizz = 5;
12. int buzz = 2;
13. zoop("just for", bzz);
14. clink(2*buzz)
15. }
16. public static void clink(int fork) {
17. System.out.print("It's );
18. zoop("breakfast ", fork) ;
19. }
20. public static void ping(string strangStrung) {
21. System.out.println("any " + strangStrung "more ");
22. }
23. }
QUESTION 4
(a)What is the output of the following block of code (2 Marks)
for (int i=1;i < 5;i++)
{
if (i % 2= =0)
System.out.println(“Hello World: ”+i);
}
(b) Write a program that will output the following (3 Marks)
Page|4
(c) Identify what is wrong with the following program code (3 Marks)
public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect;
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}
(d) Write an algorithm and a complete java program that reads three numbers
and prints the value of the largest number. (3 Marks)
(e)Write a pseudocode, algorithm, flowchart and a complete java program to
perform the following tasks
(i) Compute the perimeter of a rectangle (5 Marks)
(ii) Compute the area of a triangle (5 Marks)
END//
Page|5