Using Arrays of "Structs"
A Programming Pattern |
Prof. David Bernstein |
Computer Science Department |
bernstdh@jmu.edu |
public
attributes for convenience)struct
is a collection of heterogeneous elements
(unlike an array which is a collection of homogeneous
values)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++; }