Java Assignment
Working with Arrays and Classes in Java
Objective:
Learn how to declare, initialize, and use arrays of primitive data types.
Understand how to create objects of a class and use them in another class.
Task 1: Working with Arrays
1. Create a Java class called FirstArray.
2. Declare and instantiate an array of integers with 5 elements.
3. Populate the array with values and print them using a loop.
1. Create another Java class called SecondArray.
2. Declare and instantiate an array of strings with 5 elements.
3. Populate the array with values and print them using a loop.
Task 2: Working with Objects
1. Create a class named Student with the following variable:
o
name
o
matricNumber
o
age
o
department
2. Create a method displayInfo() to print student details.
3. Create another class called MainClass
4. In MainClass, create an object of the Student class and use the object to initialize the
variables created in 1 above.
5. Then, call the displayInfo()method to show student details in this format: “My name
is ___, matric number ____. I am ____ years old, and I am from ______ department.”
Run and print the output of your program for submission. Also, write a brief
report to explain each line of your code (as you understand it). Consult your notes
and online resources to complete the assignment.
IT MUST BE DONE INDIVIDUALLY.
To be submitted on Wednesday 2nd April, 2025. 8am.