Hey there folks,

So I am working on an assignment for class and I have gotten a considerable amount done thus far. I am having some issues with the final important aspect though. The assignment asks that we read a .txt file with a bunch of records of cars sold including attributes of each car, i.e. model, color, year, etc. We then store each entry into a 5 dimensional array. I have no issue with the part of the code as it seems to be storing fine after testing it. We then have to read another .txt file with a handful of queries. We take these queries and derive a total of the value of the cars sold based upon the query criteria. We are to derive the totals by getting the information from the 5 dimensional array we populate earlier. The issue I am having is I can not seem to get the nested loops to properly sum the total for each query. I can read the query.txt file fine and everything but it seems my logic is screwy in dealing with the data after that. I am wondering if anyone can point me in the right direction or maybe guide my debugging. I do NOT want any exact code that will fix the problem so please do not offer that as help. I am just asking for a fresh, more experienced set of eyes to offer a bit of guidance. Thanks! The code is included at the bottom of the message, it is fairly large and somewhat sloppy and for this I apologize. I am still a beginner yet and I am to stupid to understand the value of organization. If you want the .txt files I have been using to test I will offer those as well.

import java.io.*;
import java.lang.*;


public class Main
{

private TextFileReader inFile, inFile2;
private Members currentRecord,nextRecord;
private QueryFile currentRecord2;

String [] wordList = {"Lemur", "Rhesus", "Chimp", "Orangutan", "Gorilla", "Black", "White", "Red", "Blue", "Green", "Yellow", "Standard", "Automatic", "Air", "NoAir", "2007", "2008", "2009", "2010"};
int attributePosition [] = {1,1,1,1,1,2,2,2,2,2,2,3,3,4,4,5,5,5,5};
int attributeValue [] = {0,1,2,3,4,0,1,2,3,4,5,0,1,0,1,0,1,2,3};
int attribute1, attribute2,attribute3,attribute4,attribute5 = 0;
String [] recordArray = new String [5];
double [][][][][] profit = new double[5][6][4][4][7];
String record, record2, record3, record4= " ";
String [] queryArray = new String[5];
double sum = 0.00;
double totalSum = 0.00;
String queryRecord= "";
int tempApp1 = 0;
 int minApp1,minApp2,minApp3,minApp4,minApp5 = 0;
    int maxApp1,maxApp2,maxApp3,maxApp4,maxApp5 = 0;
    int loopApp1, loopApp2,loopApp3,loopApp4,loopApp5 =0;


public static void main (String args[])
    {
        (new Main()).populateArray ();
    }

private void populateArray ()
/***************************************************************************
*Method that reads the members.txt file and populate's the dues array with
*the appropriate totals for each record category.
****************************************************************************/
   {
       inFile = new TextFileReader("CARS.txt");
       inFile2 = new TextFileReader("query.txt");
       nextRecord = new Members (inFile.readLine ());

      DisplayHeader();

  	do
    	{
            currentRecord = nextRecord;
            nextRecord = new Members (inFile.readLine ());

            recordArray = currentRecord.getModel().replaceAll("\\s+", " ").split("\\s");

            for (int i =0; i<recordArray.length; i++){
           // System.out.println(recordArray[i]);
            }

            if (recordArray.length ==6)
            try {
                 sum = Double.valueOf(recordArray[5].trim()).doubleValue();

             } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException: " + nfe.getMessage());
             }
             else if(recordArray.length ==5){
            	 sum = Double.valueOf(recordArray[4].trim()).doubleValue();

             }
            attributeCheck();
        } while (inFile.moreData());

    }

private void attributeCheck()
{

	for (int i = 0; i<wordList.length; i++){
		for (int j = 0; j<recordArray.length; j++) {
		 if (recordArray[j].equalsIgnoreCase(wordList[i]) && i<=4){
             attribute1 = attributeValue[i];
            }
				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>=5 && i<=10) {
                 attribute2 = attributeValue[i];

                }
				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>=11 && i<=12) {
                    attribute3 = attributeValue[i];
                }

				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>= 13 && i<=14){
                    attribute4 = attributeValue[i];
                }

				if (recordArray[j].equalsIgnoreCase(wordList[i]) && i>=15 && i <=19){
                   attribute5 = attributeValue[i];
                }
         }
	}

         profit[attribute1][attribute2][attribute3][attribute4][attribute5] += sum;

        // System.out.println( attribute1+". "+ attribute2+". "+attribute3+". "+attribute4+". "+attribute5+". "+ profit[attribute1][attribute2][attribute3][attribute4][attribute5]);

         compareQuery();
}

private void compareQuery(){
      
	readChange();

 for (int j = 0; j<queryArray.length; j++)
 {
   for (int i = 0; i<wordList.length; i++)
   {

		 if (wordList[i].equalsIgnoreCase(queryArray[j])){
             tempApp1 = i;
         }
           // System.out.println(queryArray[j]);

System.out.println(tempApp1);



        switch (tempApp1){

            case 0: case 1: case 2: case 3: case 4:
                minApp1 = attributeValue[tempApp1];
                maxApp1= attributeValue[tempApp1];
               // System.out.println(tempApp1+" "+minApp1+" "+maxApp1+". "+loopApp1);
                    break;
            
            case 5: case 6: case 7: case 8: case 9: case 10:
                minApp2 = attributeValue[tempApp1];
                maxApp2= attributeValue[tempApp1];
               // System.out.println(tempApp1+" "+minApp2+" "+maxApp2+". "+loopApp2);
                    break;

            case 11: case 12:
                minApp3 = attributeValue[tempApp1];
                maxApp3= attributeValue[tempApp1];
                     break;

            case 14: case 15:
                minApp4 = attributeValue[tempApp1];
                maxApp4= attributeValue[tempApp1];
                     break;
            case 16: case 17: case 18: case 19:
                minApp5 = attributeValue[tempApp1];
                maxApp5= attributeValue[tempApp1];
                    break;

            }
        }
 }


           for (loopApp1 = minApp1; loopApp1<maxApp1; loopApp1++) 
                for (loopApp2 = minApp2; loopApp2<maxApp2; loopApp2++)
                    for (loopApp3 = minApp3; loopApp3<maxApp3;loopApp3++)
                        for (loopApp4 = minApp4; loopApp4<maxApp4; loopApp4++)
                            for (loopApp5 = minApp5; loopApp5<maxApp5; loopApp5++)
                        totalSum +=  profit[loopApp1][loopApp2][loopApp3][loopApp4][loopApp5];
                       System.out.println("Total Sum: "+maxApp1+". "+maxApp2+". "+maxApp3+". "+maxApp4+ ". "+ maxApp5 +". "+ totalSum);


           minApp1 = 0;
           maxApp1= 0;
           minApp2 = 0;
           maxApp2= 0;
           minApp3 = 0;
           maxApp3= 0;
           minApp4 = 0;
           maxApp4= 0;
           minApp5 = 0;
           maxApp5= 0;
           tempApp1=0;
          totalSum =0;
              

}

private void readChange()
    {
/*******************************************************************************************************************
 This method reads the query records in the queries.txt file in order to split each record line and assign the
 query request name in order to search the query request later.
******************************************************************************************************************/

    	currentRecord2 = new QueryFile (inFile2.readLine ());

         queryRecord = currentRecord2.getQuery();


         if (queryRecord.equals("ALL RECORDS"))
          {
              record = "ALL RECORDS";
          }

       // System.out.println(queryRecord);

        for (int i = 0; i<queryArray.length; i ++){
            queryArray[i]= "";
        }
           queryArray= currentRecord2.getQuery().replaceAll("\\s+", " ").split("\\s");
        
          if (queryArray.length ==1)
          {
             record = queryArray[0];
          }
          if (queryArray.length ==2)
          {
              record = queryArray[0];
              record2 = queryArray[1];
          }
          if (queryArray.length ==3)
          {
              record = queryArray[0];
              record2 = queryArray[1];
              record3 = queryArray[2];
          }
          if (queryArray.length ==4)
          {
              record = queryArray[0];
              record2 = queryArray[1];
              record3 = queryArray[2];
              record4 = queryArray[3];
          }

    }

    private void DisplayHeader()
/*************************************************************************
*Method to display header for query report.
*************************************************************************/
    {

    System.out.println("===========================================================================================================");
    System.out.println("                    DUES TOTALS QUERY REPORT FOR DATA STRUCTURES AWARENESS SOCIETY");
    System.out.println("===========================================================================================================");
    System.out.println("     Region                Category            Journals                Membership Level        Total Dues");
    System.out.println("-----------------------------------------------------------------------------------------------------------");
    }


class QueryFile
/*************************************************************************
*Class for the query file.
*************************************************************************/
{
    public String getQuery()
    {
        return query;
    }

    public void setQuery(String query)
    {
        this.query = query;
    }

    String query;

    public QueryFile(String inputLine)
/*************************************************************************
* This constructor intializes the data fields with the string information
* provided by one line from the data files.
*************************************************************************/
    {
      {
        if (inputLine == null)
        {
            System.out.printf("\n\n%23s%23s"," ","All queries have been processed..........Exiting program.\n\n");
            System.exit(1);
        }
        else
        {
            query = inputLine.trim();
            if (query.equals(""))
            {
                query ="ALL";
            }
        }
      }
    }
}

class Members
/*************************************************************************
*Class for the members file information.
*************************************************************************/
 {
    public String getModel()
    {
        return model;
    }

    public void setModel(String model)
    {
        this.model = model;
    }


    String model;


    public Members (String inputLine)
/*************************************************************************
* This constructor intializes the data fields with the string information
* provided by one line from the data files.
*************************************************************************/
    {
      {
        if (inputLine == null)
        {
        }
        else
        {
            model = inputLine.trim();

        }
      }
    }
 }
class TextFileReader
/***************************************************************************
* Class TextFileReader controls reading from a text file by opening the file,
*  reading one line at a time, keeping track
*  of the end of file, and handling I/O errors.
***************************************************************************/
  {
    private BufferedReader inputFile;
    private String fileName;
    private boolean dataLeft;

public TextFileReader (String name)
/***********************************************************************
* This constructor opens the file given by the name passed in the parameter.
***********************************************************************/
    {
     fileName = name;
        try
        {
            inputFile = new BufferedReader(new FileReader(fileName));
        }
        catch (IOException error)
        {
            error.printStackTrace();
            System.err.println ("An error occured opening file " + fileName + "!\n");
            System.exit(1);
        }
        dataLeft = true;
  } // end TextFileReader

public String readLine ()
/****************************************************************************
* This method reads and returns one line of the text file. if the file is
* empty, an empty string is returned.
****************************************************************************/
    {
    String inputLine;
    try
    {
        if ( (inputLine = inputFile.readLine()) == null )
            dataLeft = false;
        else return inputLine;
    }
    catch (IOException error)
    {
        System.err.println ("An error occured reading from file " + fileName +
                            "!\n");
        System.exit(1);
    }
    return null;
    }   // end readLine

public boolean moreData ()
/**************************************************************************
* This function returns true if the end has not
**************************************************************************/
  { return dataLeft; } // end moreData
    }// end class TextFileReader
}

The issue I am having is I can not seem to get the nested loops to properly sum the total for each query.

Can you show what the program outputs, explain what is wrong with that output and show what you want it to output.

The only debugging technique I can offer is continue to add print out of values until you can see why your logic is wrong.

A suggestion for your print outs. Add an id string vs just numbers:
System.out.println(tempApp1);
vs
System.out.println("tempApp1=" + tempApp1);

No problem. The input is a small .txt file with the following data that is used to populate the 5 Dim. profit array.

ORANGUTAN WHITE automatic AIR 2007 100.00
GOrIlla GREEN auTOmatic air 20010 100.00
Rhesus Yellow automatic aIr 2007 100.00
Lemur Black automatic 2007 100.00
GOrIllA BLACK AUTOMATIC air 2007 100.00
Orangutan YELLOW automatic AIR 2008 100.00
Orangutan Blue AUTOMATIC air 2007 100.00
RHeSuS Blue STANDARD air 2009 100.00
ChImp BLACK standard air 2007 100.00
Gorilla BLUE standard air 20010 100.00

This is the output that I get when I run the program. The numbers is the loopApp1 value after the for loops run through and the double value after them should be a total of the query. The words are the criteria of the query being asked for.

01 ================================
02 DUES TOTALS QUERY REPORT FOR DATA STRUCTURES AWARENESS SOCIETY
03 ================================
04 Region Category Journals Membership Level Total Dues
05 ----------------------------------------------------
06 OraNGUtaN Blue AUTOMATIC 2009
07 Total Sum: 4. 4. 2. 1. 3. 0.0
08 BLACK AUTOMATIC
09 Total Sum: 1. 1. 2. 1. 1. 0.0
10 automatic
11 Total Sum: 1. 1. 2. 1. 1. 0.0
12 Orangutan WHITE standard air
13 Total Sum: 4. 2. 1. 1. 1. 0.0
14 air
15 Total Sum: 1. 1. 1. 1. 1. 0.0
16 BLUe automatic NOAIR
17 Total Sum: 1. 4. 2. 2. 1. 0.0
18 automatic
19 Total Sum: 1. 1. 2. 1. 1. 100.0
20 Chimp GREEN AIR
21 Total Sum: 3. 5. 1. 1. 1. 0.0
22 GORILLA Green
23 Total Sum: 5. 5. 1. 1. 1. 0.0
24 2008
25 Total Sum: 1. 1. 1. 1. 2. 0.0
26 CHIMP air
27 Total Sum: 3. 1. 1. 1. 1. 100.0


What I expect to see is higher values as I want it to grab a query and add all the values associated with that attribute in the 5 Dim. array. For example if the query asks to find automatics it should print the profit of 700 based upon the input data. Hope this helps. If not let me know and I can clarify. Thanks again!

This post has been edited by macosxnerd101: 29 minutes ago
Reason for edit:: Added code tags around for formatting, and removed excessive = symbols to prevent the h-scroll from being broken.

What I expect to see is higher values as I want it to grab a query and add all the values associated with that attribute in the 5 Dim. array.

What exactly are the values that you expect to see?

What is in the QUery.txt file/

The query.txt file contains the queries that I have printed out in my output above. They are the words on the even lines of my output file. Each one is one query. As I stated. If a query asks for automatic in the query field then the total for all automatic cars in the input file should be displayed. In the case of the above input file it should display 700.00. Alternatively if the query asks for Orangatun blue automatic 2009 the output should display the total for all cars that match that criteria in the 5 dim. array.

- A 5 dimensional array? I see the five dimensional array, and it's scary to me.
Can you talk about what it is you're doing there, and why you need 5 dimensions to model it?

- I'm having a little trouble figuring out what your code's meant to be doing, because your explanation deals in cars, and you start out with car-like things, but soon you're into dues and members and things. This makes your code annoying to read, and means I'm probably missing things. Tidying that up would help a lot.

However I do see that this bit of code needs a looking at:

#
 

for (loopApp1 = minApp1; loopApp1<maxApp1; loopApp1++)
  for (loopApp2 = minApp2; loopApp2<maxApp2; loopApp2++)
    for (loopApp3 = minApp3; loopApp3<maxApp3;loopApp3++)
      for (loopApp4 = minApp4; loopApp4<maxApp4; loopApp4++)
        for (loopApp5 = minApp5; loopApp5<maxApp5; loopApp5++)
          totalSum += profit[loopApp1][loopApp2][loopApp3][loopApp4][loopApp5];

You probably realize that this assigns maxApp5 X maxApp4 X maxApp3 X maxApp2 X maxApp1 separate variables. So if the smallest of those values is 10, you're dealing with a minimum of 10^5 = 100,000 separate variables, all of which are being assigned each time you call compareQuery.

Can you talk us through what's going on here?

Thank you for the advice. I certainly understand your consideration about the sloppiness and illegibility of my code. I will work on cleaning it up so that it is easier to read so that it might be easier to get some help.

In response to your question about the 5 dimensional array:

The theory is that we have a txt file with 5 different attributes a car might have:

Model
Color
Transmission
Air/No Air
Year

The idea is to populate a 5 dim array by setting each indices in the array for the proper attribute. This is to say that, if I have the listing Lemur Black standard air 2009 you would have code that would set the 5 dim array to profit[2][4][1][0][2] or whatever that indices of those attributes would be. It is a requirement of the program allegedly geared to teach us about multidimensional arrays.

My idea with the loops is that I want to be able to effectively call the values in the 5 dim array and total an amount based upon the query data. I try to set min values and max values that the loop should be in order to cycle through the array and get the grand total. This is to say that, if a query asks for cars of the lemur model I want to set the min and max of the loop for the first attribute, which is the model attribute to the index of lemur and then loop through the rest of the indexes in the profit 5 dim array in order to get the totals that have anything to do with that one attribute. So essentially I want to be able to set a min and a max based upon the query and only set it for the ones that the query asks for, otherwise I want it too loop through all possible indexes if not specified.

I am not sure if I explained this coherently so please forgive me if I did not. I really appreciate anyone simply taking them time to entertain my silly and probably laughable coding attempts. :) If you need anything else to aid the process let me know. Thanks.

Note: Previous post is wrong on the calculation of the number of iterations - I didn't take into account your starting point. However, loops nested five deep should always freak you out.
However, I think I see your logic here: by setting the model column's min and max values to the values for any known fields, you can cancel out the loop for that column, thus reducing the complexity of the loops selectively. So if you're looking for Lemurs with no air conditioning, you can eliminate two loops, and so forth.
Okay.


I still have serious reservations about this usage of a 5D array, but your handling of it is at least better than the spec.

Now, debugging.
There's a lot of techniques, but the first one to deploy is to make sure you know what it's supposed to do. Walk through the code in your head - you should be able to figure out where it's going to go, and to map that out. (I use big sheets of paper for this, usually on the floor because my desk is a mess)
In the process, you might get some ideas of where it's going wrong. Put some println statements that will reveal whether that hypothesis is correct. Check whether methods are called when they're supposed to be, whether they return the correct values, whether loops execute, and so forth.
Exploring the code in this vein will help you see the code outside of the frame of the screen, which can help you see bugs.

However, I think I see your logic here: by setting the model column's min and max values to the values for any known fields, you can cancel out the loop for that column, thus reducing the complexity of the loops selectively. So if you're looking for Lemurs with no air conditioning, you can eliminate two loops, and so forth.

That is precisely my thought on the process and though I would rather not use a 5 dim array it is a requirement of the assignment so I am stuck with it. I have made some progress with the code and I have cleaned it up a bit for easier readability as per your advice. I am going to repost the somewhat cleaned up code. I have gotten it to the point where it will sum a number of the totals though some seem to be wrong and some seem to be spot on. I am still not sure why this is though I am inclined to believe it has something to do with the nested loops. I am also having an issue reading the entirety of the query file as it only seems to go through 11 queries and then stops. I believe this may be because I am not using a loop to grab the next query but once again I am not entirely sure. I am just going to plug away all day today and see if I can't figure this out. Hopefully some others will join the conversation and offer me some advice. Thanks again Jon! Oh and I will also include my new output that the program is generating. The input and query data is the same.

public class Main
{

private TextFileReader inFile, inFile2;
private Members currentRecord,nextRecord;
private QueryFile currentRecord2;

String [] wordList = {"Lemur", "Rhesus", "Chimp", "Orangutan", "Gorilla", "Black", "White", "Red", "Blue", "Green", "Yellow", "Standard", "Automatic", "Air", "NoAir", "2007", "2008", "2009", "2010"};
int attributePosition [] = {1,1,1,1,1,2,2,2,2,2,2,3,3,4,4,5,5,5,5};
int attributeValue [] = {0,1,2,3,4,0,1,2,3,4,5,0,1,0,1,0,1,2,3};
int attribute1, attribute2,attribute3,attribute4,attribute5 = 0;
String [] recordArray = new String [5];
double [][][][][] profit = new double[5][6][4][4][7];
String [] queryArray = new String[5];
double sum = 0.00;
double totalSum = 0.00;
String queryRecord= "";
int tempApp1 = 0;
int minApp1,minApp2,minApp3,minApp4,minApp5 = 0;
int maxApp1,maxApp2,maxApp3,maxApp4,maxApp5 = 0;
int loopApp1, loopApp2,loopApp3,loopApp4,loopApp5 =0;


public static void main (String args[])
    {
        (new Main()).populateArray ();
    }

private void populateArray ()
/***************************************************************************
*Method that reads the members.txt file and populate's the dues array with
*the appropriate totals for each record category.
****************************************************************************/
   {
       inFile = new TextFileReader("CARS.txt");
       inFile2 = new TextFileReader("query.txt");
       nextRecord = new Members (inFile.readLine ());

      DisplayHeader();

  	do
    	{
            currentRecord = nextRecord;
            nextRecord = new Members (inFile.readLine ());

            recordArray = currentRecord.getModel().replaceAll("\\s+", " ").split("\\s");

            for (int i =0; i<recordArray.length; i++){
           // System.out.println(recordArray[i]);
            }

            if (recordArray.length ==6)
            try {
                 sum = Double.valueOf(recordArray[5].trim()).doubleValue();

             } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException: " + nfe.getMessage());
             }
             else if(recordArray.length ==5){
            	 sum = Double.valueOf(recordArray[4].trim()).doubleValue();
             }
            attributeCheck();
        } while (inFile.moreData());

    }

private void attributeCheck()
{
	for (int i = 0; i<wordList.length; i++){
		for (int j = 0; j<recordArray.length; j++) {
		 if (recordArray[j].equalsIgnoreCase(wordList[i]) && i<=4){
             attribute1 = attributeValue[i];
            }
				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>=5 && i<=10) {
                 attribute2 = attributeValue[i];

                }
				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>=11 && i<=12) {
                    attribute3 = attributeValue[i];
                }

				if (recordArray[j].equalsIgnoreCase(wordList[i])&& i>= 13 && i<=14){
                    attribute4 = attributeValue[i];
                }

				if (recordArray[j].equalsIgnoreCase(wordList[i]) && i>=15 && i <=19){
                   attribute5 = attributeValue[i];
                }
         }
	}
         profit[attribute1][attribute2][attribute3][attribute4][attribute5] += sum;
        // System.out.println( attribute1+". "+ attribute2+". "+attribute3+". "+attribute4+". "+attribute5+". "+ profit[attribute1][attribute2][attribute3][attribute4][attribute5]);
         compareQuery();
}

private void compareQuery(){


currentRecord2 = new QueryFile (inFile2.readLine ());

   // do{
        queryRecord = currentRecord2.getQuery();

         if (queryRecord.equals("ALL RECORDS"))
          {
            //  record = "ALL RECORDS";
          }
        System.out.println(queryRecord);
           queryArray= currentRecord2.getQuery().replaceAll("\\s+", " ").split("\\s");
    

	//readChange();
 //  do{

 for (int j = 0; j<queryArray.length; j++)
 {
   for (int i = 0; i<wordList.length; i++)
   {
		 if (wordList[i].equalsIgnoreCase(queryArray[j])){
             tempApp1 = i;

        switch (tempApp1){

            case 0: case 1: case 2: case 3: case 4:
                minApp1 = attributeValue[tempApp1];
                maxApp1= attributeValue[tempApp1];
           minApp2=0;
           maxApp2=5;
           minApp3=0;
           maxApp3=1;
           minApp4=0;
           maxApp4=1;
           minApp5=0;
           maxApp5=3;
               
               // System.out.println(tempApp1+" "+minApp1+" "+maxApp1+". "+loopApp1);
                    break;

            case 5: case 6: case 7: case 8: case 9: case 10:
           minApp1=0;
           maxApp1=4;
           minApp3=0;
           maxApp3=1;
           minApp4=0;
           maxApp4=1;
           minApp5=0;
           maxApp5=3;
                minApp2 = attributeValue[tempApp1];
                maxApp2= attributeValue[tempApp1];

               // System.out.println(tempApp1+" "+minApp2+" "+maxApp2+". "+loopApp2);
                    break;

            case 11: case 12:
                minApp3 = attributeValue[tempApp1];
                maxApp3= attributeValue[tempApp1];
                  minApp1=0;
           maxApp1=4;
           minApp2=0;
           maxApp2=5;
           minApp4=0;
           maxApp4=1;
           minApp5=0;
           maxApp5=3;
                     break;

            case 13: case 14:
                minApp4 = attributeValue[tempApp1];
                maxApp4= attributeValue[tempApp1];
           minApp1=0;
           maxApp1=4;
           minApp2=0;
           maxApp2=5;
           minApp3=0;
           maxApp3=1;
           minApp5=0;
           maxApp5=3;
                     break;
            case 15: case 16: case 17: case 18:
                minApp5 = attributeValue[tempApp1];
                maxApp5= attributeValue[tempApp1];
           minApp1=0;
           maxApp1=4;
           minApp2=0;
           maxApp2=5;
           minApp3=0;
           maxApp3=1;
           minApp4=0;
           maxApp4=1;
                    break;
        }
            }
    }
 }

           for (loopApp1 = minApp1; loopApp1<=maxApp1; loopApp1++){
                for (loopApp2 = minApp2; loopApp2<=maxApp2; loopApp2++){
                    for (loopApp3 = minApp3; loopApp3<=maxApp3;loopApp3++){
                        for (loopApp4 = minApp4; loopApp4<=maxApp4; loopApp4++){
                            for (loopApp5 = minApp5; loopApp5<=maxApp5; loopApp5++) {
                        totalSum +=  profit[loopApp1][loopApp2][loopApp3][loopApp4][loopApp5];
                                  
                            }
                        }
                    }
                }
           }
    System.out.println("Total Sum: "+loopApp1+". "+loopApp2+". "+loopApp3+". "+loopApp4+ ". "+ loopApp5 +". "+ totalSum);
    
           totalSum=0;
           minApp1=0;
           maxApp1=0;
           minApp2=0;
           maxApp2=0;
           minApp3=0;
           maxApp3=0;
           minApp4=0;
           maxApp4=0;
           minApp5=0;
           maxApp5=0;
           tempApp1=0;



   // }while (queryArray!=null);
}

private void readChange()
    {
/*******************************************************************************************************************
 This method reads the query records in the queries.txt file in order to split each record line and assign the
 query request name in order to search the query request later.
******************************************************************************************************************/

    	currentRecord2 = new QueryFile (inFile2.readLine ());
        queryRecord = currentRecord2.getQuery();

         if (queryRecord.equals("ALL RECORDS"))
          {
            //  record = "ALL RECORDS";
          }
        System.out.println(queryRecord);
           queryArray= currentRecord2.getQuery().replaceAll("\\s+", " ").split("\\s");
    }

    private void DisplayHeader()
/*************************************************************************
*Method to display header for query report.
*************************************************************************/
    {

    System.out.println("===========================================================================================================");
    System.out.println("                    PROFIT TOTALS QUERY REPORT ");
    System.out.println("===========================================================================================================");
    System.out.println("     Model                Color            Transmission          Air/No Air        Year         Profit");
    System.out.println("-----------------------------------------------------------------------------------------------------------");
    }


class QueryFile
/*************************************************************************
*Class for the query file.
*************************************************************************/
{
    public String getQuery()
    {
        return query;
    }

    public void setQuery(String query)
    {
        this.query = query;
    }

    String query;

    public QueryFile(String inputLine)
/*************************************************************************
* This constructor intializes the data fields with the string information
* provided by one line from the data files.
*************************************************************************/
    {
      {
        if (inputLine == null)
        {
            System.out.printf("\n\n%23s%23s"," ","All queries have been processed..........Exiting program.\n\n");
            System.exit(1);
        }
        else
        {
            query = inputLine.trim();
            if (query.equals(""))
            {
                query ="ALL";
            }
        }
      }
    }
}

class Members
/*************************************************************************
*Class for the members file information.
*************************************************************************/
 {
    public String getModel()
    {
        return model;
    }

    public void setModel(String model)
    {
        this.model = model;
    }
    String model;

    public Members (String inputLine)
/*************************************************************************
* This constructor intializes the data fields with the string information
* provided by one line from the data files.
*************************************************************************/
    {
      {
        if (inputLine == null)
        {
        }
        else
        {
            model = inputLine.trim();

        }
      }
    }
 }
class TextFileReader
/***************************************************************************
* Class TextFileReader controls reading from a text file by opening the file,
*  reading one line at a time, keeping track
*  of the end of file, and handling I/O errors.
***************************************************************************/
  {
    private BufferedReader inputFile;
    private String fileName;
    private boolean dataLeft;

public TextFileReader (String name)
/***********************************************************************
* This constructor opens the file given by the name passed in the parameter.
***********************************************************************/
    {
     fileName = name;
        try
        {
            inputFile = new BufferedReader(new FileReader(fileName));
        }
        catch (IOException error)
        {
            error.printStackTrace();
            System.err.println ("An error occured opening file " + fileName + "!\n");
            System.exit(1);
        }
        dataLeft = true;
  } // end TextFileReader

public String readLine ()
/****************************************************************************
* This method reads and returns one line of the text file. if the file is
* empty, an empty string is returned.
****************************************************************************/
    {
    String inputLine;
    try
    {
        if ( (inputLine = inputFile.readLine()) == null )
            dataLeft = false;
        else return inputLine;
    }
    catch (IOException error)
    {
        System.err.println ("An error occured reading from file " + fileName +
                            "!\n");
        System.exit(1);
    }
    return null;
    }   // end readLine

public boolean moreData ()
/**************************************************************************
* This function returns true if the end has not
**************************************************************************/
  { return dataLeft; } // end moreData
    }// end class TextFileReader
}

And here is the output. The ones that are correct as per the input is the Black Automatic query for 200, Automatic query for 700, Gorilla Green for 100 and the 2008 query for 100, the rest are wrong. I am not sure why some are right and others are wrong.

===================================================================================================================================================================================================
PROFIT TOTALS QUERY REPORT
===========================================================================================================
Model Color Transmission Air/No Air Year Profit
-----------------------------------------------------------------------------------------------------------
OraNGUtaN Blue AUTOMATIC 2009
Total Sum: 5. 6. 2. 2. 3. 0.0
BLACK AUTOMATIC
Total Sum: 5. 6. 2. 2. 4. 200.0
automatic
Total Sum: 5. 6. 2. 2. 4. 300.0
Orangutan WHITE standard air
Total Sum: 5. 6. 2. 1. 4. 400.0
air
Total Sum: 5. 6. 2. 1. 4. 500.0
BLUe automatic NOAIR
Total Sum: 5. 6. 2. 2. 4. 0.0
automatic
Total Sum: 5. 6. 2. 2. 4. 700.0
Chimp GREEN AIR
Total Sum: 5. 6. 2. 1. 4. 800.0
GORILLA Green
Total Sum: 5. 5. 2. 2. 4. 100.0
2008
Total Sum: 5. 6. 2. 2. 2. 100.0

Process finished with exit code 0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.