I need help with my RunnerPackage 2.Find the largest package in the array. Report the index, dimensions, and volume of the largest object. /* * for (i=0; ps[i].getVolume) { return max_volume; *???? 3. How many cubic and non-cubic packages are there in the array? 4. Report the indices and dimensions of the cubic packages. 5. Report average volume of cubic packages only
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/*
*/
public class RunnerPackage {
public static void main(String[] args) throws FileNotFoundException
{
Package[] ps = new Package[7];
Read(ps);
}
public static void Read(Package[]ps) throws FileNotFoundException
{
Scanner s = new Scanner(
new File("PackageInput.txt"));
//call the array
int i=0;
//read the numbers
while (s.hasNextLine()){
System.out.println("Package demensions");
String line = s.nextLine();
System.out.println(line);
String[] allSplits= line.split(" ");
//create new object
ps[i]= new Package();
//read objects
ps[i].setWidth(Double.parseDouble(allSplits[0]));
ps[i].setHeight(Double.parseDouble(allSplits[1]));
ps[i].setLength(Double.parseDouble(allSplits[2]));
i++;
}
}
/*
*
for (i=0; ps[i].getVolume)
{
return max_volume;
*
*/
}
/*
* Christina Torres
* Lab 3
*/
public class Package {
//Variables
private double packageWidth;
private double packageHeight;
private double packageLength;
//Constructors
Package(){
}
//Setters
public void setLength(double length){
this.packageLength= length;
}
public void setHeight(double height){
this.packageHeight= height;
}
public void setWidth(double width){
this.packageWidth= width;
}
//Getters
public double getLength(){
return packageLength;
}
public double getWidth(){
return packageWidth;
}
public double getHeight(){
return packageHeight;
}
public boolean getisCubed(){
if (packageHeight==packageLength&&packageWidth==packageHeight)
return true;
else
return false;
}
public double getVolume(){
double volume = packageWidth*packageLength*packageHeight;
return volume;
}
}