Re: Cross tabulation - someone please help if you can
- From: Ross Bamford <ross@xxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 00:29:35 +0100
On Thu, 2005-04-28 at 11:23 -0700, rn29 wrote:
> Hi,
>
> I need advise re the best data structure to use for representing data
> in aggregated form. I am looking to do something like this
> Year 1 Year 2
> number percent number percent ...
>
> MAJ 66 0.0 61 0.0 ...
> GRAD 0 0.0 0 0.0 ...
> NOTA 0 0.0 3 0.0 ...
> TOTAL 66 100.0 66 100.0 ...
>
Am I reading you correctly here? Because from what you're saying above I
would figure something like:
class YearStats
{
final int maj;
final int grad;
final int nota;
YearStats(int maj, int grad, int nota) {
this.maj = maj;
this.grad = grad;
this.nota = nota;
}
public int total() {
return int+maj+grad;
}
public int asPercent(int value) {
return (total() / 100) * value;
}
}
Which you'd then keep in a simple List:
ArrayList<YearStats> years = new ArrayList<YearStats>();
years.add(new YearStats(66,0,0));
years.add(new YearStats(61,0,3));
... etc ...
And then you could print 'em:
for (YearStats year : years) {
System.out.println("Year "+i+");
System.out.println("MAJ " + year.maj+" (" + year.asPercent(maj) +
")");
System.out.println("GRAD "+year.grad+" (" + year.asPercent(grad) +
")");
System.out.println("NOTA "+year.nota+" (" + year.asPercent(nota) +
")");
System.out.println("TOTAL "+year.total());
}
Not sure if that's what you meant?
> Any help will be much appreciated. Please let me know if it is helpful
> for you to see the code so far.
>
> -Reuben
>
Always :)
--
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + info@xxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- References:
- Prev by Date: uploading files..
- Next by Date: Re: Cross tabulation - someone please help if you can
- Previous by thread: Cross tabulation - someone please help if you can
- Next by thread: Re: Cross tabulation - someone please help if you can
- Index(es):
Relevant Pages
|
|