Sie sind auf Seite 1von 2

DFC3013 Object Oriented Programming

LAB EXERCISE 2
COURSE LEARNING OUTCOME:
CLO2: apply Object Oriented Concepts in designing a successful program using programming
tools.

Instructions:

 Answer all questions. You are required to submit the program codes and the output in
Word document(softcopy)
 In order to make sense of program listing you have written in the past it is a good idea
to being each program with the following sections:

/*
Author :
Program Title :
Description :
Date :
Signature :
*/
 Comment your code.
 Indent your code to increase clarity.

Question 1: (CLO 2) [10 marks]

Write a java program that adds up integers that the user enters. First the program asks
how many numbers will be added up. Then the program prompts the user for each
number. Finally it prints the sum. Use branching statement to solve this problem.

How many integers will be added:


5

Result:
Enter an integer 1:
3
Enter an integer 2:
4
Enter an integer 3:
-4
Enter an integer 4:
-3
Enter an integer 5:
7

The sum is 7

1/2
Prepared by: norhaliza.poli@1govuc.gov.my
DFC3013 Object Oriented Programming

Question 2: (CLO2) [10 marks]

Write a java program that computes the sum and average of all the elements in an
array. First the program asks the size of an array. Then the program prompts the user
to enter the elements of an array based on its array index. Finally it prints the sum and
average of the array.

Question 3: (CLO2) [10 marks]

Write a program using overload constructor to calculate the area of square


(length*length) and display it. Display I and II.

I. Initialize the sides of the square=3.


II. User will enter the sides of the square.

2/2
Prepared by: norhaliza.poli@1govuc.gov.my

Das könnte Ihnen auch gefallen