The Artima Developer Community
Sponsored Link

Java Answers Forum
how do you not calculate first row of a multidimensional array?

2 replies on 1 page. Most recent reply: Nov 9, 2003 5:37 PM by s

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jeff

Posts: 1
Nickname: panthera
Registered: Nov, 2003

how do you not calculate first row of a multidimensional array? Posted: Nov 7, 2003 8:51 PM
Reply to this message Reply
Advertisement
I am trying to use a double array to calculate sales totals per saleperson and overall averages but do not want to use the salesperson number in the calculations. Can someone show me the correct code?

Below is how I start:

import java.awt.*;

public class SalesArray extends JApplet {
int sales[][] = {{1180,45,75,94,65},
{1181,21,88,89,20},
{1182,79,51,55,67}};

int salesperson, items;
String output;
JTextArea outputArea;

{rest of code}

I am trying to not use the first column in my calculation but to output it only under saleperson and get the following output:

Salesperson [1] [2] [3] [4] Average:
1180 45 75 94 65
1181 21 88 89 20
1182 79 51 55 67

Lowest Sales earned =
Highest Sales earned =
Overall Average =
Mediam of overall Sales =


Steve

Posts: 5
Nickname: srbeckle
Registered: Nov, 2003

Re: how do you not calculate first row of a multidimensional array? Posted: Nov 9, 2003 10:43 AM
Reply to this message Reply
Just use elements 1 through (SalesArray.length - 1) to do your calculations (element 0 is the salesperson), but print elements 0 through length-1 to produce your report column titles.


> I am trying to use a double array to calculate sales
> totals per saleperson and overall averages but do not want
> to use the salesperson number in the calculations. Can
> someone show me the correct code?
>
> Below is how I start:
>
> import java.awt.*;
>
> public class SalesArray extends JApplet {
> int sales[][] = {{1180,45,75,94,65},
> {1181,21,88,89,20},
> {1182,79,51,55,67}};
>
> int salesperson, items;
> String output;
> JTextArea outputArea;
>
> {rest of code}
>
> I am trying to not use the first column in my calculation
> but to output it only under saleperson and get the
> following output:
>
> Salesperson [1] [2] [3] [4] Average:
> 1180 45 75 94 65
> 1181 21 88 89 20
> 1182 79 51 55 67
>
> Lowest Sales earned =
> Highest Sales earned =
> Overall Average =
> Mediam of overall Sales =

s

Posts: 23
Nickname: codemonkey
Registered: Nov, 2003

Re: how do you not calculate first row of a multidimensional array? Posted: Nov 9, 2003 5:37 PM
Reply to this message Reply
How about an OBJECT...yes java is an OO
language ...maybe a SalesPerson object yes
that would be neat and then the SalesPerson
object could contain a Vector with sales totals
and an salesperson id and whatever other crap
you would want to throw in there maybe even a
method in SalesPerson that returns that salespersons
monthly totals/averages or something...just so you
know ,whenever you are writing special code to parse
things out of an array based on the index ...you are doing very wrong stuff.

Flat View: This topic has 2 replies on 1 page
Topic: Need Help wit JList Previous Topic   Next Topic Topic: shortcut key to javax.swing.ProgressMonitor

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use