0% found this document useful (0 votes)
4 views1 page

Exercise

The document is a worksheet and assignment focused on Object Oriented Programming concepts. It includes tasks such as writing methods to check multiples, creating subclasses, handling arrays to manage unique values, calculating π, and determining prime numbers. Each task requires coding solutions that demonstrate understanding of programming principles and data manipulation.

Uploaded by

negassierahel
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)
4 views1 page

Exercise

The document is a worksheet and assignment focused on Object Oriented Programming concepts. It includes tasks such as writing methods to check multiples, creating subclasses, handling arrays to manage unique values, calculating π, and determining prime numbers. Each task requires coding solutions that demonstrate understanding of programming principles and data manipulation.

Uploaded by

negassierahel
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/ 1

Object Oriented Programming

Worksheet and Assignment


1. What's the result of the logical expression
i.
ii.
iii.
2. Write a method multiple that determines, for a pair of integers from user
entry, whether the second integer is a multiple of the first. The method
should take two integer arguments and return true if the second is a
multiple of the first and false otherwise.
3. Write a subclass called TestSubClass that is derived from TestClass and that adds an integer
data field called data2 (declared as private) and a public method called CreateDataString()
that creates a string object from data1 and data2. That is, if data1 is equal to Java is cool!
and data2 is equal to 15, the CreateDataString() method should return Java is cool! 15 as a
single string object, otherwise return empty string. Also, create public methods called
SetData2() and GetData2() for setting and retrieving the value of data2, as well as a
constructor that accepts arguments for the starting values of data1 and data2.
4. Use a one-dimensional array to solve the following problem: Write an
application that inputs five numbers, each between 10 and 100,
inclusive. As each number is read, display it only if it is not a duplicate of
a number already read. Provide for the “worst case,” in which all five
numbers are different. Use the smallest possible array to solve this
problem. Display the complete set of unique values input after the user
enters each new value.
5. Write a function that get array of integer via parameter then compute
and displays the sum, smallest and largest of the numbers.

6. Calculate the value of π from the infinite series

7. An integer is said to be prime if it is divisible only by 1 and itself. For example, 2, 3, 5 and 7
are prime, but 4, 6, 8 and 9 are not.
a) Write a method that determines whether a number is prime and prints all the prime
numbers less than 10,000.
b) How many prime numbers you have up to 10,000?

You might also like