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

(Java language) Use head.next, head.next.next cure, etc etc... From Lab Assignme

ID: 3587134 • Letter: #

Question

(Java language) Use head.next, head.next.next cure, etc etc... From Lab Assignment 3, you know that a sample file may look like the following one. 20 108 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 Each line contains the width, height and length of a box. The dimensions are separated by spaces. In Lab Assignment 3, you could read the input file twice. For Lab assignment 4, you can read the input file exactly once. Yes, sometimes clients can be very difficult. The client is NOT allowing the use of any array to store Box objects, or java.util lists for this revised software. Assignment: You need to write a program using object oriented programming idea for boxes. That is, each box has to be considered an object. To achieve this, you must write a class named Box. As you already know, this client likes to keep each class in a separate Java file. Therefore, make sure to create a Java file for the Box class. Some other required properties of the Box class are as follows. 1. You are allowed to keep only one of the status variables public. The rest of the status variables of the Box class must be private. 2. Write no more than two constructors. 3· The Box class must have a public method named getvolume ( ) that will return the volume of the box. 4. The Box class must have a public method named isCube() that will return true if the box is cubic, false otherwise. 5. The Box class must NOT contain any main method. Feel free to write any additional method in the Box class, as you see fit. The program file (the Java file that contains the main method) must be written in Runner.java. Runner must have the following functionalities. Each functionality must be implemented in a separate method in Runner.

Explanation / Answer

Hi Please find below code

Runner.java

package com.boxes;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.util.LinkedList;

public class Runner {

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

File file = new File("test.txt");

FileReader fileReader = new FileReader(file);

BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;

LinkedList<Box> ls = new LinkedList<Box>();

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

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

double l = Double.parseDouble(lineArray[0]);

double h = Double.parseDouble(lineArray[1]);

double w = Double.parseDouble(lineArray[2]);

Box b = new Box(l,h,w);

ls.add(b);

}

fileReader.close();

System.out.println("Contents of file:");

int small = 0;

int large = 0;

for(int i=0;i<ls.size();i++){

Box b1 = ls.get(i);

double volume = ls.get(0).getVolume();

System.out.println("Volumes:::::"+b1.getVolume());

if(volume>b1.getVolume()){

small=i;

}

if(volume<b1.getVolume()){

large=i;

}

//b1.display();

}

System.out.println("Smallest box Position::"+small+" Volume:"+ls.get(small).getVolume());

ls.get(small).display();

System.out.println("Largest box Position::"+large+" Volume:"+ls.get(large).getVolume());

ls.get(large).display();

double vols=0.0;

for(Box b:ls){

vols+=b.getVolume();

}

//System.out.println(vols+" "+ls.size());

System.out.println("Average volume of all boxes::"+vols/ls.size());

double smallVols=0.0;

int count = 0;

for(int i=0;i<ls.size();i++){

Box b=ls.get(i);

if(b.isCube()){

System.out.println("Cube box Position::"+i+" Volume:"+b.getVolume());

b.display();

smallVols += b.getVolume();

count+=1;

}

}

if(count!=0){

System.out.println("Average volume of all cube boxes::"+smallVols/count);

}

}

}

Box.java

package com.boxes;

public class Box {

private double l;

private double h;

private double w;

public double getL() {

return l;

}

public void setL(double l) {

this.l = l;

}

public double getH() {

return h;

}

public void setH(double h) {

this.h = h;

}

public double getW() {

return w;

}

public void setW(double w) {

this.w = w;

}

public boolean isCube(){

if(l == h && h == w)

return true;

else

return false;

}

public double getVolume(){

return l*h*w;

}

public Box(double l, double h, double w) {

super();

this.l = l;

this.h = h;

this.w = w;

}

public void display(){

System.out.println("Dimensions:: Length:"+l+" Height:"+h+" Width:"+w);

}

}

Thank You... All the best