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

Java The client saves dimensions of packages in the inventory in a text file. Wh

ID: 3889617 • Letter: J

Question

Java The client saves dimensions of packages in the inventory in a text file. While it sounds inefficient, the client is an angel from programmer's point of view. This is because it is possible to write a program that will directly read from the file and create a summary of the inventory. A sample file is shown below. 20 10 8 4.5 8.45 12.2 8.0 2.5 4.0 1.0 15.0 18.0 3.5 3.5 3.5 6.0 5.0 10.0 That is, each line contains the width, height, and length of a package. The dimensions are separated by spaces. Assignment: You need to write a program using object oriented programming idea for packages. That is, each package must be considered an object. To achieve this, you must write a class named Package. Make sure to create a Java file for the Package class Some other required properties of the Package class are as follows. 1. All status variables of the Package class must be private. 2. Write no more than two constructors 3. Must have a public method named getvolume() that will return the volume of the package. 4. Must have a public method named iscube() that will return true if the package is cubic, false otherwise. 5. The Package class must NOT contain any main method. Feel free to write any additional method in the Package class, as you see fit. The program file (the Java file that contains the main method) must be written in a file named Runner.java. The Runner class must not have any status variable. Runner must have the following functionalities. Each functionality must be implemented in a separate method in Runner.

Explanation / Answer

public class Package {

private double width;

private double height;

private double length;

public Package(double width, double height, double length) {

super();

this.width = width;

this.height = height;

this.length = length;

}

public Package() {

width = 0;

height = 0;

length = 0;

}

public double getWidth() {

return width;

}

public void setWidth(double width) {

this.width = width;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public double getVolume()

{

return width*height*length;

}

public boolean isCube()

{

if(width==height && width==length)

return true;

else

return false;

}

}

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Runner {

public static void main(String[] args) throws FileNotFoundException, IOException {

// TODO Auto-generated method stub

String fileName;

int count=0;

double avgVolume = 0;

int totalCubs=0;

double largestPackage=0;

List<Double>volumeList=new ArrayList();

List<Boolean>cubeList=new ArrayList();

List<Package> packageList=new ArrayList<Package>();

Scanner sc=new Scanner(System.in);

System.out.println("Enter the name of the file to be opened ");

fileName=sc.next();

File file=new File(fileName);

try (BufferedReader br = new BufferedReader(new FileReader(file))) {

String line;

while ((line = br.readLine()) != null) {

String arr[]=line.split(" ");

Package obj=new Package(Double.parseDouble(arr[0]),Double.parseDouble(arr[1]),Double.parseDouble(arr[2]));

packageList.add(obj);

  

}

}

System.out.println("Cube details are :");

for(Package packageObject:packageList)

{

count++;

double volume=packageObject.getVolume();

if(volume>largestPackage)

{

largestPackage=volume;

}

boolean cube=packageObject.isCube();

if(cube)

{

totalCubs++;

System.out.println("the index of the cube is "+count);

System.out.println("And the dimensions of the cube is"+packageObject.getHeight());

}

volumeList.add(volume);

cubeList.add(cube);

}

for(double volume:volumeList)

{

avgVolume=avgVolume+volume;

}

System.out.println("The volume of the largest package is "+largestPackage);

System.out.println("the average volume of the cube is "+avgVolume/count);

System.out.println("The total number of cubes are "+totalCubs);

System.out.println("The total nuber of non cubes are "+(count-totalCubs));

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote