Question: Core Java_ Exception Handling_Problem Statement 4. The DataX Shipping Company is a leading logistics Company that transports goods from one location to another. There are

Core Java_ Exception Handling_Problem Statement 4.

The DataX Shipping Company is a leading logistics Company that transports goods from one location to another. There are cases in such shipping Companies that during loading Containers, employees unknowingly add extra weight into the containers. In order to caution the employee regarding the overload, write a program to add the weight of every item added to the container and if the added weight of the items exceeds the actual capacity of the container throw an exception named"ContainerOverloadedException".

Create a class named Commodity with the following private member variables / attributes

String commodityId

Float totalWeight

Integer quantity

Include a 3-argument constructor with argument in this order --- commodityId,totalWeight,quantity.

Include appropriate getters and setters.

Create a class named Container with the following private member variables / attributes

String number

Float containerWeight

Commodity[] commodities

1) Include 3-argument construtor with arguments in this order --- number,containerWeight,commodities. 2) Include a method named as displayDetails() in Container to display the container details.

S.No Method Name Method description
1 void displayDetails() to display the commodity details

Create a class named ShipmentBO with the method validate. --- validate(Container,Commodity[]) to check whether the weight of commodities is less than capacity of the container.

S.No Method Name Method description
1 void validate(Container container, Commodity[]commodity) To check whether the weight of all the commodities is less than capacity of the container. If it satisfies the above condition display the commodity details or else throw ContainerOverloadedException.

Create a class name ContainerOverloadedException which extends Exception. If any exception occurs in the above class throw the exception to thisContainerOverloadedException class with custom message. This class will handle the exception Create a class Main and write a main method to test the above class. Hint: Invoke the displayDetails method from main class and throw ContainerOverloadedException from the ShipmentBO class. Problem Specification: 1) Commodity details are entered by comma separated values in the following order(commodityId,totalWeight,quantity). 2) Create a custom exception named as ContainerOverloaded. 3) Check whether all commodities loaded into the container.If all commodities are loaded display the commodity details or else throw ContainerOverloaded exception display the string Container is overloaded. 4) Use System.out.format("%-15s%-15s%s ", "Id","Weight","Quantity") to display the commodity details. [Note :Strictly adhere to the object oriented specifications given as a part of the problem statement.Use the same class names, method names and attribute names.] Input and Output Format: Refer sample input and output for formatting specifications.All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output 1: Enter the container number : C001 Enter the capacity of container : 40 Enter the number of commodities : 4 Enter the commodities : CM01,10,1 CM02,20,2 CM03,5,1 CM04,5,1 Commodity details are Id Weight Quantity CM01 10 1 CM02 20 2 CM03 5 1 CM04 5 1 Sample Input and Output 2: Enter the container number : C001 Enter the capacity of container : 40 Enter the number of commodities : 4 Enter the commodities : CM01,10,4 CM02,20,2 CM03,10,1 CM04,10,2 ContainerOverloadedException: Container is overloaded

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!