Re: Cross tabulation - someone please help if you can



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


.



Relevant Pages

  • Re: [C++] Help Parsing an Integer/Character Mix
    ... - What kind of data structure are you using? ... int Number; ... while(InFile>> Buffer) ... possible even an member function. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: large file support
    ... FileHeader::Allocate(BitMap *freeMap, int fileSize) ... describing where on disk to find all of the data in the file. ... // The file header data structure can be stored in memory or on disk. ...
    (comp.lang.cpp)
  • Passing complex structure from C# to C++ and back
    ... to pointer structure, as in "prop **x". ... My question is what data structure, marshaling or code do I have to ... int l; // number of elements ...
    (microsoft.public.dotnet.framework.interop)
  • Re: passing structures among functions
    ... "Header files should only contain declarations." ... It also defines for the data structure at the ... int get_data ...
    (comp.lang.c)
  • Re: pass an array throuh a function
    ... In message, Ben Cottrell ... > int minutes; ... >So now, you have a data structure called clock, which has 3 properties ...
    (alt.comp.lang.learn.c-cpp)