- ROM
- CPU
- RAM
- GPU
I am writing a program for school and I can't figure out how to get the max value in a column. I need to find the highest Sales value in the ArrayList. I don't have a fixed number of Names so there could be 2 or 10 Salespersons Name,Sales in the arraylist depending on the quantity the user inputs. After the user finishes input I need to find the highest sales value so I can output each salesperson and display how much they need to meet or exceed the highest sales.
Here is how I get the data into the ArrayList:
ArrayList list = new ArrayList[];
list.add[new Salesperson[myName,mySales]];
The Salesperson class/constructor is setup like this:
private static class Salesperson{
private String name;
private double Sales;
public Salesperson[String n, double s]{
this.Name = n;
this.Sales = s;
}
}
- NetBeans.org NetBeans IDE
- Oracle Corporation Java
::Smacks forehead::
It's an ArrayList, not an Array. Let's try angle brackets.
9 Replies
The length member variable should give you what you need. If not, try the size[] member function.
Joseph2982 wrote:
The length member variable should give you what you need. If not, try the size[] member function.
Javadouble max = 0; for[int i = 0; i max] max = list[i].Sales;
Thanks for the help! I tried it and here is what I get:
I get errors. "array required, but ArrayList found.
Length wasn't an option so size[] was an available option.
In the IF statement max= list[i].Sales; I get illiegal character: '\ufeff' and "array required, but ArrayList found"
Ah! The Sales member is private. You will need to make it public or write a get[] function. Best practice says, "make a get[] function."
There is also a mismatch with capitalization in Name member.
Does it like this any better?
Below is the code. I am still getting the same errors!