7.2 Arrays in Classes and Methods

A little more than kin, and less than kind.

—WILLIAM SHAKESPEARE, Hamlet

Arrays can be used as instance variables in classes. Methods can have an indexed variable or an entire array as an argument and can return an array. In short, arrays can be used with classes and methods just as other objects can. We begin with a case study that uses an array as an instance variable in a class.

Case Study Sales Report

In this case study, we will write a program to generate sales reports for a company’s team of sales associates. The company wants to easily see which associate or associates have the highest sales and to know how the sales of each associate compare to the average.

Since we need to ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.