CSE110 - OOP - Lab Assignment 02 - Student Version
CSE110 - OOP - Lab Assignment 02 - Student Version
Assignment : 02
Instructor : Ahmed Abdal Shafi Rasel, Lecturer, Department of CSE
Section : 15, 16
Trimester : Spring 2024
Objective: The objective of this assignment is to develop problem solving skills relating to creating
methods, method-overloading, class, object, constructor, constructor overloading, access modifiers,
instance and static methods, immutable object, etc.
Tasks:
No. Problems
Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal
is the same as itself. Write a test program that prompts the user to enter an integer and reports
whether the integer is a palindrome.
2. (Display matrix of 0s and 1s) Write a method that displays an n-by-n matrix using the
following header:
public static void printMatrix(int n)
Each element is 0 or 1, which is generated randomly. Write a test program that prompts the
user to enter n and displays an n-by-n matrix. Here is a sample run:
3. (Check password) Some websites impose certain rules for passwords. Write a method that
checks whether a string is a valid password. Suppose the password rules are as follows:
■ A password must have at least eight characters.
■ A password consists of only letters and digits.
■ A password must contain at least two digits.
Write a program that prompts the user to enter a password and displays Valid Password if the
rules are followed or Invalid Password otherwise.
4. (Count the letters in a string) Write a method that counts the number of letters in a string using
the following header:
public static int countLetters(String s)
Write a test program that prompts the user to enter a string and displays the number of letters
in the string.
5. (Occurrences of a specified character) Write a method that finds the number of occurrences of
a specified character in a string using the following header:
public static int count(String str, char a)
For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to
enter a string followed by a character and displays the number of occurrences of the character
in the string.
Draw the UML diagram for the class and then implement the class. Write a test program that
creates a Stock object with the stock symbol ORCL, the name Oracle Corporation, and the
previous closing price of 34.5. Set a new current price to 34.35 and display the price-change
percentage.
7. (Use the GregorianCalendar class) Java API has the GregorianCalendar class in the
java.util package, which you can use to obtain the year, month, and day of a date. The no-arg
constructor constructs an instance for the current date, and the methods
get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH),
and get(GregorianCalendar.DAY_OF_MONTH) return the year, month, and day.
Draw the UML diagram for the class and then implement the class. Write a test
program that measures the execution time of sorting 100,000 numbers using
selection sort.
Draw the UML diagram for the class and then implement the class. Write a test program that
prompts the user to enter a, b, c, d, e, and f and displays the result. If ad - bc is 0, report that
“The equation has no solution.”.
10. (The Location class) Design a class named Location for locating a maximal value and its
location in a two-dimensional array. The class contains public data fields row, column, and
maxValue that store the maximal value and its indices in a two dimensional array with row
and column as int types and maxValue as a double type.
Write the following method that returns the location of the largest element in a two
dimensional array: public static Location locateLargest(double[][] a).
The return value is an instance of Location. Write a test program that prompts the user to enter
a two-dimensional array and displays the location of the largest element in the array. Here is
a sample run: