我的RunnerPackage需要帮助 2.找到阵列中最大的包装。报告最大对象的索引,尺寸和体积。 / * * 为(i = 0; ps [i] .getVolume) { 返回max_volume; * ???? 3。 阵列中有多少立方和非立方包装? 4。 报告立方包装的索引和尺寸。 5, 仅报告立方包装的平均体积
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;
}
}