Problem with class creation/data array

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1044 Views - Last Post: 17 March 2010 - 09:34 AM Rate Topic: -----

#1 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Problem with class creation/data array

Posted 16 March 2010 - 06:52 AM

I am taking my first programming class, and this program needs to contain a created class and one dimensional data arrays. When I try to compile it, I only get two errors, but I know the problem is deeper than that. My first question is can you get a function in my class to return multiple values to my main? I need to print several pieces of info calculated in the class but so far I have only had to return one item to main. Here is my program:

 //import decimal formatter
  import java.text.DecimalFormat;

 //import scanner object
  import java.util.Scanner;

 //import all file processing methods
  import java.io.*;

 public class prog4
 {

        public static void main(String[] args) throws IOException
        {
            final int DAR = 10; //constant size of array

            int number[], //the sale order
                count;    //number of sales

            double sale[],     //raw value of sale
                   tax[],      //tax amount
                   net_sale[], //sale value plus tax
                   change[],  // money returned to the customer
                   payment[], //money received from customer
                   total_tax, //total value of tax collected
                   total_net; //total value of net sales

            String flag[]; //tax status of item sold

            flag = new String[DAR];
            number = new int[DAR];
            sale = new double[DAR];
            payment = new double[DAR];
            tax = new double[DAR];
            net_sale = new double[DAR];
            change = new double[DAR];

            Trans pos; //a trans object at pos

            //create decimal format object
            DecimalFormat formatter = new DecimalFormat("#0.00");

            //create a scanner object for file input
            File input = new File("NCR.data");

            //open file for reading
            Scanner NCR = new Scanner(input);

            count = 0;
            while(NCR.hasNext())
            {
               flag[count] = NCR.nextString();
               number[count] = NCR.nextInt();
               sale[count] = NCR.nextDouble();
               payment[count] = NCR.nextDouble();
               count = count + 1;
            }
            NCR.close();
            pos = new Trans(count,flag,number,sale,payment);
            PrintHeadings();
            pos.CalcTotal(count,flag,sale,payment);
            PrintTable(count,number,sale,tax,net_sale,change);
            PrintLine();
            total_net = pos.CalcNet(count,net_sale);
            System.out.println("TOTAL SALES: " + formatter.format(total_net));
            total_tax = pos.CalcTaxt(count,tax);
            System.out.println("TOTAL TAX: " + formatter.format(total_tax));
            }

            //print heading funtion
            public static void PrintHeadings()
            {
              System.out.println("               POS CALC ALGORITHM TEST RUN");
              PrintLine();
              System.out.print("SALE#    NET SALE    SALES TAX");
              System.out.println("    SALE TOTAL    CHANGE");
              PrintLine();
            }

            //This function prints the table data. Input parameters are the
            //count, sale number, net sale, tax, sale total and change.
            public static void PrintTable(int count, int number[], double sale[],
            double tax[], double net_sale[], double change[])


            {
              int C;     //loop control variable

                for(C = 0; C < count; C++)
               {
                 System.out.printf("%3d", number[C]);
                 System.out.printf("%9.2f", sale[C]);
                 System.out.printf("%9.2f", tax[C]);
                 System.out.printf("%9.2f\n", net_sale[C]);
               }
            }

            //This function prints a line
            public static void PrintLine()
            {
              System.out.print("--------------------------");
              System.out.println("-------------------------");
            }
       }




And here is my class:

public class Trans
{
     final int DAR = 10;

    //set private variables of the class
    private String[] status = new String[DAR];
    private int[] num = new int[DAR];
    private double[] value = new double[DAR];
    private double[] receive = new double[DAR];

    //constructor sets private variables to inital value
    public Trans(int count)
    {
      int C;   //loop control variable
      for(C = 0; C < count; C++)
      {
          num[C] = 0;
          value[C] = 0.0;
          receive[C] = 0.0;
      }
    }

    //constructor assigns the data from the main into
    //class variables
    public Trans(int count, String flag[], double sale[],
    double payment[])
    {
      int C; //loop control variable

      for(C = 0; C < count; C++)
      {
         status[C] = flag[C];
         value[C] = sale[C];
         receive[C] = payment[C];
      }
    }
    // calculates the pos information, i.e. tax and net sales
    public void CalcTotal (int count, String flag[], double sale[],
    double payment[])
    {
      int C;  //loop control variable
      double tax[];
      double net_sale[];
      double change[];

      tax = new double[DAR];
      net_sale = new double[DAR];
      change = new double[DAR];

      for(C = 0; C < count; C++)
        if (status[C] != "N")
         {
          tax[C] = value[C]*.09;
         }
        else
         {
          tax[C] = 0.0;
         }
       net_sale[C] = tax[C] + value[C];
       change[C] = receive[C] - net_sale[C];

     }

     //calculates the total net sales

     public double CalcNet(int count, double net_sale[])
     {
       int C; //loop control variable
       double tot_sale;

       tot_sale = 0.0;

       for(C = 0; C < count; C++)
          tot_sale = tot_sale + net_sale[C];

          return tot_sale;
      }

     //calculates the total of taxes collected

     public double CalcTaxt(int count, double tax[])
     {
       int C; //loop control variable
       double tot_tax;

       tot_tax = 0.0;

       for(C = 0; C < count; C++)
         tot_tax = tot_tax + tax[C];

          return tot_tax;
     }
}





The two errors I receive in compilation are both from the main, and they are on the " flag[count] = NCR.nextString();" and " pos = new Trans(count,flag,number,sale,payment);" lines.... both are "cannot find symbol" errors, but as I said... I know there are a few more things that need to be addressed in the program. Any help would be greatly appreciated.

Oh, btw it is reading from this file:

T 231 123.33 150.50
N 232 34.55 40.00
T 243 10.25 100.00
T 244 45.70 50.00
T 245 148.78 200.00
T 246 55.35 100.00
N 250 145.55 150.75
N 255 19.95 20.00

Thanks for your time!

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with class creation/data array

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 08:17 AM

For your first error, it says that NCR.nextString)_ is illegal, because there is no nextString() method of the Scanner object. There is either next(), which reads only until whitespace, and then there's readLine(), which reads the whole line (I recommend the previous to read one character.

AS for your second error:
You are creating an object like this:
pos = new Trans(count,flag,number,sale,payment);



Notice it has 5 arguments, however you have THIS defined:
public void CalcTotal (int count, String flag[], double sale[],
    double payment[])


Notice it has 4 arguments not 5...

As for the rest of this program, the parallel arrays are really confusing and to answer your question, no it is not usually possible to do this without the help of objects.

I highly suggest employing objects into your program rather than tons of parallel arrays. I suggest you read macosxnerd101's tutorial on Moving Away From Parallel Arrays.
Was This Post Helpful? 2
  • +
  • -

#3 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 16 March 2010 - 09:04 AM

First, thank you for your response. I changed my String method as you advised, and it went away. Secondly, I have no choice but to use the parallel arrays, this is for an assignment, and they are required. My follow up question is this: Why does it matter that CalcTotal only uses 4 of the arrangements? Does this mean I should pass all of the arguments to CalcTotal even though it only uses a few of them?
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 09:11 AM

Mmmm...you didn't get what I said. I said just call call a method with whatever arguments you want, you have to match the number and type of variables.

So, if I have this method:
public void method(int[] args1, String args2)



I cannot call it with anything other than an int[] as the the first argument and a String argument as the second. So, in your method, you have 4 arguments, but you pass five, which is not matching number or type.

And generally, you should only pass what you need to a method because each argument does take up space in computer memory (although it won't make THAT huge of a difference).
Was This Post Helpful? 1
  • +
  • -

#5 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 16 March 2010 - 11:34 AM

Follow up question. So I changed the program around a little and it compiles and runs. I have a problem however, with the parallel arrays that I modified. The program reads from the file correctly, and prints my heading and my first two columns of data correctly, but those two columns are just reading and printing. The next three columns of data are from my calculation functions, and they just print as columns of "0.00". At least it is the correct number of columns and the correct length. I checked my formulas, and they appear correct, so I think my problem is in passing the data maybe? Anyway, an updated look at my main:

 //import decimal formatter
  import java.text.DecimalFormat;

 //import scanner object
  import java.util.Scanner;

 //import all file processing methods
  import java.io.*;

 public class prog4
 {

        public static void main(String[] args) throws IOException
        {
            final int DAR = 10; //constant size of array

            int number[], //the sale order
                count;    //number of sales

            double sale[],     //raw value of sale
                   tax[],      //tax amount
                   net_sale[], //sale value plus tax
                   change[],  // money returned to the customer
                   payment[], //money received from customer
                   total_tax, //total value of tax collected
                   total_net; //total value of net sales

            String flag[]; //tax status of item sold

            flag = new String[DAR];
            number = new int[DAR];
            sale = new double[DAR];
            payment = new double[DAR];
            tax = new double[DAR];
            net_sale = new double[DAR];
            change = new double[DAR];

            Trans pos; //a trans object at pos

            //create decimal format object
            DecimalFormat formatter = new DecimalFormat("#0.00");

            //create a scanner object for file input
            File input = new File("NCR.data");

            //open file for reading
            Scanner NCR = new Scanner(input);

            count = 0;
            while(NCR.hasNext())
            {
               flag[count] = NCR.next();
               number[count] = NCR.nextInt();
               sale[count] = NCR.nextDouble();
               payment[count] = NCR.nextDouble();
               count = count + 1;
            }
            NCR.close();
            pos = new Trans(count,flag,sale,payment);
            PrintHeadings();
            pos.CalcTax(count,flag,sale);
            pos.CalcNetsale(count,tax,sale);
            pos.CalcChange(count,net_sale,payment);
            PrintTable(count,number,sale,tax,net_sale,change);
            PrintLine();
            total_net = pos.CalcNet(count,net_sale);
            System.out.println("TOTAL SALES: " + formatter.format(total_net));
            total_tax = pos.CalcTaxt(count,tax);
            System.out.println("TOTAL TAX: " + formatter.format(total_tax));
            }

            //print heading funtion
            public static void PrintHeadings()
            {
              System.out.println("               POS CALC ALGORITHM TEST RUN");
              PrintLine();
              System.out.print("SALE#    NET SALE    SALES TAX");
              System.out.println("    SALE TOTAL    CHANGE");
              PrintLine();
            }

            //This function prints the table data. Input parameters are the
            //count, sale number, net sale, tax, sale total and change.
            public static void PrintTable(int count, int number[], double sale[],
            double tax[], double net_sale[], double change[])

            {
              int C;     //loop control variable

                for(C = 0; C < count; C++)
               {
                 System.out.printf("%3d", number[C]);
                 System.out.printf("%9.2f", sale[C]);
                 System.out.printf("%9.2f", tax[C]);
                 System.out.printf("%9.2f\n", net_sale[C]);
               }
            }

            //This function prints a line
            public static void PrintLine()
            {
              System.out.print("--------------------------");
              System.out.println("-------------------------");
            }
       }




And my class:



public class Trans
{
     final int DAR = 10;

    //set private variables of the class
    private String[] status = new String[DAR];
    private int[] num = new int[DAR];
    private double[] value = new double[DAR];
    private double[] receive = new double[DAR];

    //constructor sets private variables to inital value
    public Trans(int count)
    {
      int C;   //loop control variable
      for(C = 0; C < count; C++)
      {
          num[C] = 0;
          value[C] = 0.0;
          receive[C] = 0.0;
      }
    }

    //constructor assigns the data from the main into
    //class variables
    public Trans(int count,  String flag[], double sale[],
    double payment[])
    {
      int C; //loop control variable

      for(C = 0; C < count; C++)
      {
         status[C] = flag[C];
         value[C] = sale[C];
         receive[C] = payment[C];
      }
    }
    // calculates the pos information, i.e. tax and net sales
    public void CalcTax (int count, String flag[], double sale[])
    {
      int C;  //loop control variable
      double tax[];

      tax = new double[DAR];

      for(C = 0; C < count; C++)
        if (!status[C].equals ("N"))
         {
          tax[C] = value[C]*.09;
         }
        else
         {
          tax[C] = 0.0;
         }

     }
     //this function calculates the net sale
    public void CalcNetsale (int count, double tax[], double sale[])
    {
     int C;    //loop control variable
     double net_sale[];

     net_sale = new double[DAR];

     for(C = 0; C < count; C++)

         net_sale[C] = tax[C] + sale[C];

    }

    //this function calculates the change returned
    public void CalcChange (int count, double net_sale[], double payment[])
    {
      int C; //loop control variable
      double change[];

      change = new double[DAR];

      for(C = 0; C < count; C++)

        change[C] = payment[C]-net_sale[C];

    }




     //calculates the total net sales

     public double CalcNet(int count, double net_sale[])
     {
       int C; //loop control variable
       double tot_sale;

       tot_sale = 0.0;

       for(C = 0; C < count; C++)
          tot_sale = tot_sale + net_sale[C];

         return tot_sale;
      }

     //calculates the total of taxes collected

     public double CalcTaxt(int count, double tax[])
     {
       int C; //loop control variable
       double tot_tax;

       tot_tax = 0.0;

       for(C = 0; C < count; C++)
         tot_tax = tot_tax + tax[C];

          return tot_tax;
     }
}



Once again, Thank you very much for your time!
Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 12:15 PM

Your calcTax method edits the values inside the array however, when the method returns, nothing inside that array changes, see my post | here | explaining why...

But you actually need to return your arrays from those methods instead of editing the parameters...
Was This Post Helpful? 1
  • +
  • -

#7 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 16 March 2010 - 12:40 PM

So I would need to set up an array in my main that aligns with my method like this: taxv[C] = pos.CalcTax(count,flag,sale);

and then add a return function at the end of my CalcTax method?
Was This Post Helpful? 0
  • +
  • -

#8 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 12:48 PM

I would do something like this:
tax = pos.CalcTax(count,flag,sale);
net_sale = pos.CalcNetsale(count,tax,sale);
change = pos.CalcChange(count,net_sale,payment);



And make each of those methods return an array of the proper type, yes.
Was This Post Helpful? 1
  • +
  • -

#9 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 16 March 2010 - 12:58 PM

Two more things. One, wouldn't I need to set them up in my main as arrays? The way you have them (tax =, not tax[]=) makes it seem like it would be attempting to cram the array into a regular space. Secondly, you kick ass. Seriously, this isn't the first time you have helped me out. Thank you.
Was This Post Helpful? 0
  • +
  • -

#10 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 01:02 PM

1) Yes you would...and you have...
                   tax[],      //tax amount
                   net_sale[], //sale value plus tax
                   change[],  // money returned to the customer



Or am I misunderstanding your question?

2) Thanks, nice to get good feedback! :gunsmilie:
Was This Post Helpful? 1
  • +
  • -

#11 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 16 March 2010 - 01:09 PM

Actually I think that is it. Thanks again. :punk:
Was This Post Helpful? 0
  • +
  • -

#12 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 16 March 2010 - 01:14 PM

No problem.
Was This Post Helpful? 1
  • +
  • -

#13 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 17 March 2010 - 05:43 AM

I still have the same issue. It is returning my first two columns correctly, but it is giving me zeros in the other columns. Updated main:

 //import decimal formatter
  import java.text.DecimalFormat;

 //import scanner object
  import java.util.Scanner;

 //import all file processing methods
  import java.io.*;

 public class prog4
 {

        public static void main(String[] args) throws IOException
        {
            final int DAR = 10; //constant size of array

            int number[], //the sale order
                count,    //number of sales
                    C;

            double sale[],     //raw value of sale
                   tax[],      //tax amount
                   net_sale[], //sale value plus tax
                   change[],  // money returned to the customer
                   payment[], //money received from customer
                   total_tax, //total value of tax collected
                   total_net; //total value of net sales

            String flag[]; //tax status of item sold

            flag = new String[DAR];
            number = new int[DAR];
            sale = new double[DAR];
            payment = new double[DAR];
            tax = new double[DAR];
            net_sale = new double[DAR];
            change = new double[DAR];

            Trans pos; //a trans object at pos

            //create decimal format object
            DecimalFormat formatter = new DecimalFormat("#0.00");

            //create a scanner object for file input
            File input = new File("NCR.data");

            //open file for reading
            Scanner NCR = new Scanner(input);

            count = 0;
            while(NCR.hasNext())
            {
               flag[count] = NCR.next();
               number[count] = NCR.nextInt();
               sale[count] = NCR.nextDouble();
               payment[count] = NCR.nextDouble();
               count = count + 1;
            }
            NCR.close();
            pos = new Trans(count,flag,sale,payment);
            PrintHeadings();
              for(C = 0; C < count; C++)

            tax[C] =  pos.CalcTax(count,flag,sale);
            net_sale[C] =  pos.CalcNetsale(count,tax,sale);
            change[C] = pos.CalcChange(count,net_sale,payment);
            PrintTable(count,number,sale,tax,net_sale,change);
            PrintLine();
            total_net = pos.CalcNet(count,net_sale);
            System.out.println("TOTAL SALES: " + formatter.format(total_net));
            total_tax = pos.CalcTaxt(count,tax);
            System.out.println("TOTAL TAX: " + formatter.format(total_tax));
            }

            //print heading funtion
            public static void PrintHeadings()
            {
              System.out.println("               POS CALC ALGORITHM TEST RUN");
              PrintLine();
              System.out.print("SALE#    NET SALE    SALES TAX");
              System.out.println("    SALE TOTAL    CHANGE");
              PrintLine();
            }

            //This function prints the table data. Input parameters are the
            //count, sale number, net sale, tax, sale total and change.
            public static void PrintTable(int count, int number[], double sale[],
            double tax[], double net_sale[], double change[])

            {
              int C;     //loop control variable

                for(C = 0; C < count; C++)
               {
                 System.out.printf("%3d", number[C]);
                 System.out.printf("%9.2f", sale[C]);
                 System.out.printf("%9.2f", tax[C]);
                 System.out.printf("%9.2f\n", net_sale[C]);
               }
            }

            //This function prints a line
            public static void PrintLine()
            {
              System.out.print("--------------------------");
              System.out.println("-------------------------");
            }
       }



And updated class:

//This class holds the pos information.
//It also calculates tax and net sale.

public class Trans
{
     final int DAR = 10;

    //set private variables of the class
    private String[] status = new String[DAR];
    private int[] num = new int[DAR];
    private double[] value = new double[DAR];
    private double[] receive = new double[DAR];

    //constructor sets private variables to inital value
    public Trans(int count)
    {
      int C;   //loop control variable
      for(C = 0; C < count; C++)
      {
          num[C] = 0;
          value[C] = 0.0;
          receive[C] = 0.0;
      }
    }

    //constructor assigns the data from the main into
    //class variables
    public Trans(int count,  String flag[], double sale[],
    double payment[])
    {
      int C; //loop control variable

      for(C = 0; C < count; C++)
      {
         status[C] = flag[C];
         value[C] = sale[C];
         receive[C] = payment[C];
      }
    }
    // calculates the pos information, i.e. tax and net sales
    public double CalcTax (int count, String flag[], double sale[])
    {
      int C;  //loop control variable
      double tax[];

      tax = new double[DAR];

      for(C = 0; C < count; C++)
        if (!status[C].equals ("N"))
         {
          tax[C] = value[C]*.09;
         }
        else
         {
          tax[C] = 0.0;
         }

       return tax[C];

     }
     //this function calculates the net sale
    public double CalcNetsale (int count, double tax[], double sale[])
    {
     int C;    //loop control variable
     double net_sale[];

     net_sale = new double[DAR];

     for(C = 0; C < count; C++)

         net_sale[C] = tax[C] + sale[C];

         return net_sale[C];
    }

    //this function calculates the change returned
    public double CalcChange (int count, double net_sale[], double payment[])
    {
      int C; //loop control variable
      double change[];

      change = new double[DAR];

      for(C = 0; C < count; C++)

        change[C] = payment[C]-net_sale[C];

       return change[C];
    }




     //calculates the total net sales

     public double CalcNet(int count, double net_sale[])
     {
       int C; //loop control variable
       double tot_sale;

       tot_sale = 0.0;

       for(C = 0; C < count; C++)
          tot_sale = tot_sale + net_sale[C];

         return tot_sale;
      }

     //calculates the total of taxes collected

     public double CalcTaxt(int count, double tax[])
     {
       int C; //loop control variable
       double tot_tax;


       tot_tax = 0.0;

       for(C = 0; C < count; C++)
         tot_tax = tot_tax + tax[C];

          return tot_tax;
     }
}




Was This Post Helpful? 0
  • +
  • -

#14 jhar131  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 149
  • Joined: 03-February 10

Re: Problem with class creation/data array

Posted 17 March 2010 - 07:38 AM

Anyone?
Was This Post Helpful? 0
  • +
  • -

#15 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with class creation/data array

Posted 17 March 2010 - 07:54 AM

Again, your method needs to either return an array, ot you need to call the method with a for loop:
public double[] CalcTax (int count, String flag[], double sale[])
    {
      int C;  //loop control variable
      double tax[];

      tax = new double[DAR];

      for(C = 0; C < count; C++)
        if (!status[C].equals ("N"))
         {
          tax[C] = value[C]*.09;
         }
        else
         {
          tax[C] = 0.0;
         }

       return tax;

     }



And then call it like this:
Again, your method needs to either return an array, ot you need to call the method with a for loop:
[code]
public double[] CalcTax (int count, String flag[], double sale[])
    {
      int C;  //loop control variable
      double tax[];

      tax = new double[DAR];

      for(C = 0; C < count; C++)
        if (!status[C].equals ("N"))
         {
          tax[C] = value[C]*.09;
         }
        else
         {
          tax[C] = 0.0;
         }

       return tax[];

     }



And then call it like this:
// tax is the array, waiting to get an array from the method.
tax = pos.CalcTax(count,flag,sale);




Just do that with the other two methods...
Now, about your constructors:
public Trans(int count,  String flag[], double sale[],
    double payment[])
    {
      int C; //loop control variable

      for(C = 0; C < count; C++)
      {
         status[C] = flag[C];
         value[C] = sale[C];
         receive[C] = payment[C];
      }
    }



You copy all the elements? Why not make life easy for yourself:
public Trans(int count,  String flag[], double sale[],
    double payment[])
    {
         status = flag;
         value = sale;
         receive = payment;
      
    }



And also, you can do a similar thing here (remember that basic datatype arrays default to 0, and the only one you need to worry about is the String[]:
public Trans(int count)
 {
    for (int i = 0; i < count; i++)
        status[i] = "";
 }


This post has been edited by Dogstopper: 17 March 2010 - 08:28 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2