JMU
Using Arrays of "Structs"
A Programming Pattern


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
An Alternative Pattern
An Example
public class Sales
{
    public double amount;
    public String code;
}
double     mean, total;
Sales[]    sales;
int        month;

sales = new Sales[12];

month = 0;
while (month < 12) 
{
  JMUConsole.printf("Enter the 3-letter code for %d: ", month);
  sales[month].code  = JMUConsole.readLine();

  System.out.printf("Enter the sales for %s: ", code[month]);
  sales[month].amount = JMUConsole.readDouble();

  month++;
}