Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting this error and I don\'t know why. I am working with classes and obj

ID: 3890393 • Letter: I

Question



I am getting this error and I don't know why. I am working with classes and objects and I thought it was setup right but it's not recognizing the object from the other class.

Errors: 

runner.java:13: error: cannot find symbol
        packageType box = new packageType(fileContents);
        ^
  symbol:   class packageType
  location: class Runner
runner.java:13: error: cannot find symbol
        packageType box = new packageType(fileContents);
                              ^
  symbol:   class packageType
  location: class Runner
2 errors

Code (2 separate files):

first file

package lab3Objects;

/**
 *
 * @author andy4l
 */
public class Package {

    double[] width;
    double[] height;
    double[] length;
    double[] volume;

    
    //Setters
    public void packageType() {}
    
    public void packageType(double [][] boxSize) {
        length = new double [boxSize.length];
        height = new double [boxSize.length];
        width = new double [boxSize.length];
        volume = new double [boxSize.length];
        
        for (int i = 0; i < boxSize.length; i++) {
            volume[i] = boxSize[i][0] * boxSize[i][1] + boxSize[i][2];
            length[i] = boxSize[i][0];
            width[i] = boxSize[i][1];
            height[i] = boxSize[i][2];
            
        }
        
    }
    
    //Getters
    public double[] getVolume(){
        double store;
        for (int i = 0; i < volume.length; i++) {
            for (int j = 0; j < volume.length; j++) {
                if (volume[i] > volume[j]) {
                    store = volume[i];
                    volume[i] = volume[j];
                    volume[j] = store;
                }
            }
        }
        
        System.out.println("Boxes: ");
        
        for (int i=0;i<volume.length;i++)
            System.out.printf("The volume of box " + (i + 1) + " is: %.2f ", volume[i]);
        System.out.println("");
        return volume;
    }
}

//////////////////////////////////////////////////////////////

Second File: (this is the file that is run)

package lab3Objects;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.*;

public class Runner {
    public static void main(String[] args) throws IOException { 
        
        double [][] textFile = readFile();
        double [][] fileContents = splitFile(textFile);
        

        packageType box = new packageType(fileContents);
        
        
        double[]boxVol = box.getVolume();
        
        
    }
    
    
    
    public static double[][] readFile() throws IOException{
        FileReader fr = new FileReader("input.txt");
        BufferedReader br = new BufferedReader(fr);
        int counter = 0;
        
        while (br.readLine() != null) {
            counter++;
        }
        br.close();
        
        fr = new FileReader("input.txt");
        br = new BufferedReader(fr);
        
        String[] firstArray = new String[counter];
        String[][] secondArray = new String[counter][];
        double[][] thirdArray = new double[counter][];
        
        
        for (int i = 0; i < counter; i++) {
            firstArray[i] = br.readLine();
            secondArray[i] = firstArray[i].split(" ");
            thirdArray[i]= new double[secondArray[i].length];
        }
        
        for(int i = 0; i < counter; i++) {
            for(int j = 0; j < secondArray[i].length; j++)
                thirdArray[i][j] = Double.parseDouble(secondArray[i][j]);
        }
        return thirdArray;
    }
    
    public static double[][] splitFile(double[][] array) {
        int counter = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i].length == 3) {
                counter++;
            }
        }
        
        double[][] boxes = new double[counter][3];
        for (int i = 0; i < counter; i++) {
            for (int j = 0; j < 3; j++)
                boxes[i][j] = array[i][j];
        }
        
        return boxes;
    }

}

Explanation / Answer

You are referring to packageType as it were a class instead you have to write Package there

Modification in second file

package lab3Objects;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.*;

public class Runner {
public static void main(String[] args) throws IOException {
  
double [][] textFile = readFile();
double [][] fileContents = splitFile(textFile);
  

Package box = new Package(fileContents); // Fix the class usage
  
  
double[]boxVol = box.getVolume();
  
  
}
  
  
  
public static double[][] readFile() throws IOException{
FileReader fr = new FileReader("input.txt");
BufferedReader br = new BufferedReader(fr);
int counter = 0;
  
while (br.readLine() != null) {
counter++;
}
br.close();
  
fr = new FileReader("input.txt");
br = new BufferedReader(fr);
  
String[] firstArray = new String[counter];
String[][] secondArray = new String[counter][];
double[][] thirdArray = new double[counter][];
  
  
for (int i = 0; i < counter; i++) {
firstArray[i] = br.readLine();
secondArray[i] = firstArray[i].split(" ");
thirdArray[i]= new double[secondArray[i].length];
}
  
for(int i = 0; i < counter; i++) {
for(int j = 0; j < secondArray[i].length; j++)
thirdArray[i][j] = Double.parseDouble(secondArray[i][j]);
}
return thirdArray;
}
  
public static double[][] splitFile(double[][] array) {
int counter = 0;
for (int i = 0; i < array.length; i++) {
if (array[i].length == 3) {
counter++;
}
}
  
double[][] boxes = new double[counter][3];
for (int i = 0; i < counter; i++) {
for (int j = 0; j < 3; j++)
boxes[i][j] = array[i][j];
}
  
return boxes;
}

}