************************FedEx.java***********************************
package fedex;
import java.io.BufferedReader;
import java.io.FileReader;
/**
* The FedEx class contains the processing logic of different boxes dimensions provided in info.txt file.
*/
public class FedEx {
private double[] lengthList;
private double[] widthList;
private double[] heightList;
private int size;
private double minLength;
private double maxLength;
private double minWidth;
private double maxWidth;
private double minHeight;
private double maxHeight;
private double minVolume;
private double maxVolume;
/**
* Display volume of each boxes.
* This function first call the calculate volume method to calculate volume of each boxes
* and print the resultant volumes.
*
* @throws Exception the exception
*/
public void displayVolumeOfEachBoxes() throws Exception {
double[] calculatedVolumes = calculateVolume();
System.out.println("**************Volumes of each boxes are:*******************");
for (double vol : calculatedVolumes) {
System.out.println(vol);
}
}
/**
* Display total volumes of boxes.
* This function first call the calculate volume method to calculate volume of each boxes
* and do the sum of resultant volumes and print the results.
*
* @throws Exception the exception
*/
public void displayTotalVolumesOfBoxes() throws Exception {
double[] calculatedVolumes = calculateVolume();
double totalVolume = 0.0;
for (double vol : calculatedVolumes) {
totalVolume += vol;
}
System.out.println("******************Total volume of boxes is **************************");
System.out.println(totalVolume);
}
/**
* Display smallest dimension and volume.
* This function first call the calculate volume method to calculate volume of each boxes and
* prints the Length, Height, Width and Volume of smallest box.
*
* @throws Exception the exception
*/
public void displaySmallestDimensionAndVolume() throws Exception {
calculateVolume();
System.out.println(
"***********************Length, Height, Width and Volume of smallest box is****************************");
System.out.println("Length: " + minLength);
System.out.println("Height: " + minHeight);
System.out.println("Width: " + minWidth);
System.out.println("Volume: " + minVolume);
}
/**
* Display largest dimension and volume.
* This function first call the calculate volume method to calculate volume of each boxes and
* prints the Length, Height, Width and Volume of largest box.
*
* @throws Exception the exception
*/
public void displayLargestDimensionAndVolume() throws Exception {
calculateVolume();
System.out.println(
"***********************Length, Height, Width and Volume of largest box is****************************");
System.out.println("Length: " + maxLength);
System.out.println("Height: " + maxHeight);
System.out.println("Width: " + maxWidth);
System.out.println("Volume: " + maxVolume);
}
/**
* Calculate volume and check the min & max of the dimensions.
*
* @return the double[]
* @throws Exception the exception
*/
private double[] calculateVolume() throws Exception {
processInfoFile();
double[] volumeList = new double[size];
for (int i = 0; i < size; i++) {
double length = lengthList[i];
double width = widthList[i];
double height = heightList[i];
double volume = length * width * height;
volumeList[i] = volume;
checkForMinOrMax(length, width, height, volume);
}
return volumeList;
}
/**
* Check for min or max of dimensions.
*
* @param length the length
* @param width the width
* @param height the height
* @param volume the volume
*/
private void checkForMinOrMax(double length, double width, double height, double volume) {
if (this.minLength == 0.0 && this.maxLength == 0.0 && this.maxHeight == 0.0 && this.minHeight == 0.0
&& this.minWidth == 0.0 && this.maxWidth == 0.0 && this.minVolume == 0.0 && this.maxVolume == 0.0) {
this.minLength = length;
this.maxLength = length;
this.minWidth = width;
this.maxWidth = width;
this.minHeight = height;
this.maxHeight = height;
this.minVolume = volume;
this.maxVolume = volume;
} else {
if (length < this.minLength) {
this.minLength = length;
}
if (length > this.maxLength) {
this.maxLength = length;
}
if (width < this.minWidth) {
this.minWidth = width;
}
if (width > this.maxWidth) {
this.maxWidth = width;
}
if (height < this.minHeight) {
this.minHeight = height;
}
if (height > this.maxHeight) {
this.maxHeight = height;
}
if (volume < this.minVolume) {
this.minVolume = volume;
}
if (volume > this.maxVolume) {
this.maxVolume = volume;
}
}
}
/**
* Process info file.
* This function is used to splits the info.txt file data into it respective length, width and height list.
*
* @throws Exception the exception
*/
private void processInfoFile() throws Exception {
String[] dimensions = readFile();
String[] lengths = dimensions[0].split(" ");
String[] widths = dimensions[1].split(" ");
String[] heights = dimensions[2].split(" ");
this.lengthList = processDimensions(lengths);
this.widthList = processDimensions(widths);
this.heightList = processDimensions(heights);
this.size = lengths.length;
}
/**
* Process dimensions.
*
* @param dimensionAtr the dimension atr
* @return the double[]
*/
private double[] processDimensions(String[] dimensionAtr) {
double[] processedDimensions = new double[dimensionAtr.length];
int index = 0;
for (String atr : dimensionAtr) {
processedDimensions[index++] = Double.valueOf(atr);
}
return processedDimensions;
}
/**
* Read file.
* This function is used to process the info.txt file and return the array of data.
*
* @return the string[]
* @throws Exception the exception
*/
private String[] readFile() throws Exception {
BufferedReader br = null;
FileReader fr = null;
String[] dimensions = new String[3];
try {
fr = new FileReader("info.txt");
br = new BufferedReader(fr);
String line = null;
int i = 0;
while ((line = br.readLine()) != null) {
dimensions[i++] = line;
}
} catch (Exception ex) {
throw new Exception("info.txt file not found", ex);
} finally {
if (fr != null) {
fr.close();
}
if (br != null) {
br.close();
}
}
return dimensions;
}
}
************************************************TestFedEx.java********************************
package fedex;
// this is test class for FedEx
public class TestFedEx {
public static void main(String[] args) throws Exception {
FedEx fedEx = new FedEx();
fedEx.displayVolumeOfEachBoxes();
fedEx.displayTotalVolumesOfBoxes();
fedEx.displaySmallestDimensionAndVolume();
fedEx.displayLargestDimensionAndVolume();
}
}
*******************************Sample info.txt file******************************************
2.00 10.00 8.00 8.00 2.00
4.50 8.45 1.20 3.00 3.50
8.00 2.50 4.00 1.00 1.5
***********************Sample Output**********************************
================================================================================================================
The goal of this assignment is to practice one dimensional arrays. Objective: The goal of this...
Java Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day You will write a program to track calorie intake of a person. Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a...
Write a java program that specifies three parallel one dimensional arrays name length, width, and area. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values in the length and width arrays (thus, area[i] = length [i]* width [i]) after data has been entered display the following output: (in Java)
This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...
FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...
C ++ Implement cat command The purpose of this assignment is to provide practice using the system calls we discussed for working with files on a UNIX system. You will be writing a basic implementation of the cat command using C++. Description As you should recall, the cat command takes a list of files as command line arguments. It then opens each file in turn, writing each file’s entire contents to standard output in the order they were supplied. You...
C LANGUAGE!!! The program uses both files and two dimensional arrays. The Problem Statement Business is going well for your friend, who is selling discounts to area clubs and restaurants, which means that business is going well for you! Both of you have decided that you'll advertise on memory mall, which is roughly arranged as a rectangle. There's not enough time before a football game to hand flyers to everyone arranged on the mall. Therefore, you will only be able...
Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...
CSC151 JAVA PROGRAMMING LAB #7 OBJECTIVES . . . In this lab assignment, students will learn: To get an overview of exceptions and exception handling • To explore the advantages of using exception handling • To declare exceptions in a method header • To throw exceptions in a method • To write a try-catch block to handle exceptions To develop applications with exception handling To use the finally clause in a try-catch block To write data to a file using...
Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...