Object-oriented programming (OOP) refers to a type of computer programming (software design) in which programmers define the data type of a data structure, and also the types of operations (functions) that can be applied to the data structure.
Download Lab Report #6: Using the ArrayList Class in Java and more Study Guides, Projects, Research Object Oriented Programming in PDF only on Docsity!
LAB REPORT:
SUBJECT More practice with arrays
SUBMITTED BY: SAMIA
REG. NO: 17JZBCS
DEPARTMENT: CS&IT
TITLE: Using the ArrayList class
Exercise 1:
In BlueJ, create a new project called Lab
Create a class in that project called ListORama
Write a method in that class called makeLists that takes no parameters and returns no value
In makeLists, use an ini5aliza5on list to create an array called people that hold the following names: Chris, Robert, ScarleK, Clark, Jeremy, Gwyneth, Mark
SOLUTION:
FIGURE 1
Exercise 2:
Use a regular for loop to print the elements of the people array, one per line.
Then print a blank line.
Now use a for-each loop to print the elements again, all on the same line separated by a single space.
SOLUTION:
FIGURE 4
Exercise 5:
Add "Chris H." to the end of the ArrayList.
Change the first element "Chris" to "Chris E."
Insert "Loki" between "Robert" and "ScarleK"
Print the size of the ArrayList again.
Print the en3re list again, but this 3me list them on one line.
SOLUTION:
FIGURE 5
Exercise 6:
Print the elements of the ArrayList again, this 3me on one line separated by commas.
Don't print a comma aaer the last name!
To do this, use a regular for loop and the ArrayList get method to get each name to print.
Use an if statement to decide whether to print a comma aaer each Name