






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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.
Typology: Study Guides, Projects, Research
1 / 10
This page cannot be seen from the preview
Don't miss anything!







- In BlueJ, create a new project called Lab - Create a class in that project called MyArrays - Write a method in that class called arrayPlay that takes no parameters and returns no value - In arrayPlay, create an array called myNums that can hold 20 integers. - What are the valid indexes for this array? SOLUTION: Figure I
- Create a Random object for generating random numbers. Remember to import the java.util.Random class. - Use a for loop to fill the myNums array with random integers in the range 100 to 200. - Make sure the program compiles, though running it at this point still won't produce any output. - Could you have filled the array with a for-each loop instead?
Figure 4
- Print a blank line to separate the initial values from the following output. - Use a regular for loop to print every third value in the array starting with the first one. - That is, print the first value, the fourth value, the seventh value, etc.
- Once again: could a for-each loop be used for this? SOLUTION: Figure 5
- Print another blank line. - Now print the values in the array backwards, starting with the last position and moving to the first. - Regular for loop or for-each loop?
Figure IV Figure V
- Print another blank line. - Now print the index AND the value for each value that's over 170 - For example: 4 184 12 172 14 190 18 179 - Run your program several times. Results will vary.
Figure VI Figure VII
- Now write separate method called countValues that accepts an integer array as a parameter. Call the parameter list. - The method should return the number of values in the array that are less than 150. - In the arrayPlay method, call the countValues method, passing in the myNums array, and print the result: The number of values less than 150 are xxx