Question: Core Java_OOPS Concept_Problem Statement 5 TransGlobal, an established Shipping Company provides a diverse set of logistics services to meet the ever changing need's of its
Core Java_OOPS Concept_Problem Statement 5
TransGlobal, an established Shipping Company provides a diverse set of logistics services to meet the ever changing need's of its customers and the rapidly evolving logistics market in India. It is big enough to deliver goods of any kind, to any place via air, ocean, road or rail. The Company wanted a technology brilliant automated System to accomodate such large Shipment requirements through all the above said modes of logistics.
This problem will guide you through the concept of Multilevel Inheritance, Hierarchical Inheritance and the usage of super keyword.
Implement the Inheritance hierarchy given below
Create a class named Shipment with the following private member variables / attributes
int id
String customerName
String arrivalPort
String departurePort
float weight
1) Include a 5-argument argument constructor in this class. The arguments passed to the constructor are in this order (id, customeName, arrivalPort, departurePort, weight). 2) Include appropriate getters and setters.And this class includes the following method
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, displays the shipmetId, name, source,destination and weight of the shipment details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s","Id","Customer name","Arrival port","Departure port","Weight"). Create a class named AirTransport class, which extends Shipment class with the following private member variables / attributes
String airwaysName
1) Include appropriate getters and setters. 2) Include 6 argument constructor : AirTransport (int id, String customerName, String arrivalPort, String departurePort, float weight, String airwaysName). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display the AirTransport shipment details . |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-15s","Id","Customer name","Arrival port","Departure port","Weight","Airways name"). Create a class named GroundTransport class, which extends Shipment class with the following private member variables / attributes
String capacity
1) Include appropriate getters and setters. 2) Include 6 argument constructor : GroundTransport (int id, String customerName, String arrivalPort, String departurePort, float weight, String capacity). Create a class named WaterTransport class,which extends Shipment class with the following private member variables / attributes
String capacity
1) Include appropriate getters and setters. 2) Include 6 argument constructor : WaterTransport (int id, String customerName, String arrivalPort, String departurePort, float weight, String capacity). Call the super method inside the constructor with 5 arguements, which calls the Shipment's constructor. Create a class named Truck class,which extends GroundTransport class with the following private member variables / attributes
int sizeOfContainer
1) Include appropriate getters and setters. 2) Include 7 argument constructor : Truck (int id, String customerName, String arrivalPort, String departurePort, float weight, int sizeOfContainer, String capacity). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display the Truck details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-20s%-15s","Id","Customer name","Arrival port","Departure port","Weight","Size of container","capacity"). Create a class named Rail class,which extends GroundTransport class with the following private member variables / attributes
int numberOfContainer
1) Include appropriate getters and setters. 2) Include 7 argument constructor : Truck (int id, String customerName, String arrivalPort, String departurePort, float weight, int numberOfContainer, String capacity). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display the Rail details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-20s%-15s","Id","Customer name","Arrival port","Departure port","Weight",Number of container","Capacity"). Create a BulkCarrier class,which extends WaterTransport class with the following private member variables / attributes
String companyName
1) Include appropriate getters and setters. 2) Include 7 argument constructor : BulkCarrier (int id, String customerName, String arrivalPort, String departurePort, float weight, String companyName, String capacity). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display the BulkCarrier details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-20s%-15s","Id","Customer name","Arrival port","Departure port","Weight","Company name","capacity"). Create a ContainerShip class,which extends WaterTransport class with the following private member variables / attributes
String companyName
1) Include appropriate getters and setters. 2) Include 7 argument constructor : ContainerShip (int id, String customerName, String arrivalPort, String departurePort, float weight, String companyName, String capacity). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display ContainerShip details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-20s%-15s","Id","Customer name","Arrival port","Departure port","Weight","Company name","Capacity"). Create a Ferries class,which extends WaterTransport class with the following private member variables / attributes
String agentName
1) Include appropriate getters and setters. 2) Include 7 argument: Ferries (int id, String customerName, String arrivalPort, String departurePort, float weight, String agentName, String capacity). Include the following method in this class
| No | Method Name | Method Description |
| 1 | void displayDetails() | In this method, display the Ferries details. |
Use this format for output. System.out.format("%-15s %-15s %-15s %-15s%-15s%-20s%-15s","Id","Customer name","Arrival port","Departure port","Weight","Agent name","Capacity"). Create a Main class to test the above 9 classes. Invoke the displayDetail methods in the corresponding classes and display the details. [Note :Strictly adhere to the object oriented specifications given as a part of the problem statement.Use the same class names, attribute names and method names.] [All text in bold corresponds to input and the rest corresponds to output.] Sample Input and Output 1: Enter the number of shipments 2 Enter the transportation 1 details : Select the transportation mode 1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries Enter your choice 1 Enter the shipment 1 details 1,Vicky,Chennai,Mumbai,65,KingFisher Enter the transportation 2 details : Select the transportation mode 1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries Enter your choice 6 Enter the shipment 2 details 2,Aravi,Chennai,Australia,100,Mark,1000 Enter the mode to display Ferries Mode of Transportation : Water Id Customer name Arrival port Departure port Weight Agent name Capacity 2 Aravi Chennai Australia 100.0 Mark 1000 Sample Input and Output 2: Enter the number of shipments 3 Enter the transportation 1 details : Select the transportation mode 1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries Enter your choice 1 Enter the shipment 1 details 1,Vicky,Chennai,Mumbai,65,KingFisher Enter the transportation 2 details : Select the transportation mode 1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries Enter your choice 5 Enter the shipment 2 details 2,Martin,America,India,100,12,100 Enter the transportation 3 details : Select the transportation mode 1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries Enter your choice 5 Enter the shipment 3 details 3,mark,America,Australia,1000,10,1000 Enter the mode to display Ferries No shipment available
Now, I am providing the piece of code. Please update the code and send me back.
Rail.java
public class Rail { //fill your code }
Truck.java
public class Truck{ //fill your code }
AirTransport.java
public class AirTransport{ //fill your code }
Main.java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;
public class Main { public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the number of shipments"); int n = Integer.parseInt(buf.readLine()); Shipment[] shipmentArray = new Shipment[n]; for(int i=0;i System.out.println("Enter the transportation "+(i+1)+" details :"); System.out.println("Select the transportation mode"); System.out.println("1)Air 2)Truck 3)Rail 4)BulkCarrier 5)ContainerShip 6)Ferries"); System.out.println("Enter your choice"); int option = Integer.parseInt(buf.readLine()); String details; switch(option){ case 1: System.out.println("Enter the shipment "+(i+1)+" details"); // fill code here break; case 2: System.out.println("Enter the shipment "+(i+1)+" details"); // fill code here break; case 3: System.out.println("Enter the shipment "+(i+1)+" details"); // fill code here break; case 4: System.out.println("Enter shipment "+(i+1)+" details"); // fill code here break; case 5: System.out.println("Enter shipment "+(i+1)+" details"); // fill code here break; case 6: System.out.println("Enter shipment "+(i+1)+" details"); // fill code here break; } } System.out.println("Enter the mode to display"); String mode = buf.readLine(); for(int i=0;i if(shipmentArray[i].getClass().getName().contains(mode)){ switch(mode){ case "Air": System.out.println("Mode of Transportation : Air"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-15s ","Id","Customer name","Arrival port","Departure port","Weight","AirwaysName"); break; case "Truck": System.out.println("Mode of Transportation : Ground"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-20s%-15s ","Id","Customer name","Arrival port","Departure port","Weight","Size of container","Capacity"); break; case "Rail": System.out.println("Mode of Transportation : Ground"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-20s%-15s ","Id","Customer name","Arrival port","Departure port","Weight","No of containers","Capacity"); break; case "BulkCarrier": System.out.println("Mode of Transportation : Water"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-15s%-15s ","Id","Customer name","Arrival port","Departure port","Weight","Company name","Capacity"); break; case "ContainerShip": System.out.println("Mode of Transportation : Water"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-15s%-15s ","Company name","Capacity","Sid","Customer name","Arrival port","Departure port","Weight"); break; case "Ferries": System.out.println("Mode of Transportation : Water"); System.out.format("%-15s%-15s%-15s%-15s%-15s%-15s%-15s ","Id","Customer name","Arrival port","Departure port","Weight","Agent name","Capacity"); break; } break; } } // fill code here } }
Ferries.java
public class Ferries{ //fill your code }
ContainerShip.java
public class ContainerShip { //fill your code }
BulkCarrier.java
public class BulkCarrier { //fill your code }
WaterTransport.java
public class WaterTransport{ //fill your code }
Shipment.java
public class Shipment { //fill your code }
GroundTransport.java
public class GroundTransport{ //fill your code }
Shipment AirTransport WaterTransport GroundTransport BulkCarrier Ferries ContainerShip Rail TruckStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
