0% found this document useful (0 votes)
84 views2 pages

Lab Exercise 2: Course Learning Outcome

This document provides instructions for a lab exercise on applying object-oriented concepts in Java programming. Students are asked to write three programs: 1) A program that adds integers entered by the user, using branching statements. 2) A program that calculates the sum and average of elements in an array, prompting the user to enter the array elements. 3) A program using overloaded constructors to calculate and display the area of a square based on the length entered by the user or initialized value. Students are instructed to comment their code and indent for clarity.

Uploaded by

Byakuya Kouta
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)
84 views2 pages

Lab Exercise 2: Course Learning Outcome

This document provides instructions for a lab exercise on applying object-oriented concepts in Java programming. Students are asked to write three programs: 1) A program that adds integers entered by the user, using branching statements. 2) A program that calculates the sum and average of elements in an array, prompting the user to enter the array elements. 3) A program using overloaded constructors to calculate and display the area of a square based on the length entered by the user or initialized value. Students are instructed to comment their code and indent for clarity.

Uploaded by

Byakuya Kouta
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/ 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: [email protected]
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: [email protected]

You might also like