0

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;
 }


 }
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
  • Please see: _[What's the difference between JavaScript and Java?](https://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java)_ – Luca Kiebel Sep 26 '18 at 17:23
  • (I'm assuming this is a homework project) What have you been learning in class that would be applicable to this problem? (Hint: create a separate method to find the biggest package.) – GBlodgett Sep 26 '18 at 17:48
  • It is. The last class was on linked list. I think I have just been looking at this code too long. I know it's something simple. Just brain dead lol. In my package class I have the get volume ready to go. In my runner i'm thinking of.. Idk I keep thinking – Christina Torres Sep 26 '18 at 17:57
  • So you'll want to create a method (Maybe something like `public void findBiggest()`) and then iterate through the `Array` of `Package` objects and compare the volumes – GBlodgett Sep 26 '18 at 18:00

0 Answers0