0% found this document useful (0 votes)
6 views4 pages

Amindat Java Ass

The document outlines an assignment for a Java programming course, detailing tasks involving arrays and objects. It includes instructions for creating classes, populating arrays with integers and strings, and defining a Student class with personal information. Solutions for each task are provided, demonstrating the use of loops and methods to display data.

Uploaded by

Ogunfolajin Dele
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)
6 views4 pages

Amindat Java Ass

The document outlines an assignment for a Java programming course, detailing tasks involving arrays and objects. It includes instructions for creating classes, populating arrays with integers and strings, and defining a Student class with personal information. Solutions for each task are provided, demonstrating the use of loops and methods to display data.

Uploaded by

Ogunfolajin Dele
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/ 4

COM 211 ASSIGNMENT

NAME: ABDULGANIYU AMIDAT FOLASHADE


MATRIC NUMBER: CS20230203619
LEVEL: ND 2

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.
Solution

Report

int[] myArray = new int[5];: Creates an array that can store 5 integers.

myArray[0] = 10; to myArray[4] = 50;: Adds values to each position (index) of the array.

The FOR loop goes from 0 to 4 and prints each number.


Report

String[] fruits = new String[5];: Creates an array of 5 strings.

Each fruits[index] = "value"; line adds a fruit name.

The FOR loop prints each string in the array.


Task 2: Working with Objects

1. Create a class named Student with the following variable:


o name
o matric Number
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.”

Solution
Report
String name; etc.: These are variables to store student info.

displayInfo() is a method that prints out the information using those variables.

Student student1 = new Student();: Creates a new object of the Student class.

student1.name = "Amidat";: Assigns values to the object’s variables.

student1.displayInfo();: Calls the method to print the student details.

You might also like