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

Core Java_Collection_CC Problem Each Shipment will have a departure date and the

ID: 3909620 • Letter: C

Question

Core Java_Collection_CC Problem

Each Shipment will have a departure date and there might be situations during the shipment process to know the count of shipments based on the departure date. Write a program to display the count of the shipment entity details which have the given departure date.

Specification :
Use Collections.frequency on the ShipmentEntity with an equals method overriding on departure date.
  
Create a Main class with main method
Create a class ShipmentEntity with below private attributes,

    Integer id

    String name

    Date departureDate

Include getter and setter method for all the attributes
Include default constructor and 3 argument constructor with argument id,name,departureDate.

Input and Output Format :
Input consists of a String which corresponds to the shipment entity details in following order id,name,departureDate.
Next input consists of a String which corresponds to the departure date to be counted.
[All text in bold corresponds to input and rest corresponds to output.]

Sample Input and Output :
Enter the shipment entity details
1113,Edward,09-09-2017
Do you want to continue [yes/no]
yes
1112,Yashini,18-11-2017
Do you want to continue [yes/no]
yes
1115,Collin,18-11-2017
Do you want to continue [yes/no]
no
Enter the departure date to be counted
18-11-2017
Frequency : 2

Here I am providing the piece of code. Please update it and send me back.

Main.java

public class Main {
  
public static void main(String args[]) throws IOException, ParseException{
//fill your code
  
}
  
}

ShipmentEntity.java

public class ShipmentEntity /*fill in blanks */ {

Integer id;

String name;

Date departureDate;

ShipmentEntity(){}

public ShipmentEntity(Integer id, String name, Date departureDate ) {

this.id = id;

this.name = name;

this.departureDate = departureDate;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public Date getDepartureDate() {

return departureDate;

}

public void setDepartureDate(Date departureDate) {

this.departureDate = departureDate;

}

public void setName(String name) {

this.name = name;

}

//fill your code

}

Explanation / Answer

Main.java

import java.io.IOException;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Date;

import java.util.List;

import java.util.Scanner;

public class Main {

  

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

//fill your code

Scanner scan = new Scanner(System.in);

List<ShipmentEntity> list = new ArrayList<ShipmentEntity>();

String choice = "yes";

DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

while(choice.equals("yes")) {

System.out.println("Enter the shipment entity details:");

String str = scan.next();

String arr[] = str.split(",");

ShipmentEntity entity = new ShipmentEntity(Integer.parseInt(arr[0]), arr[1],sdf.parse(arr[2]));

list.add(entity);

System.out.println("Do you want to continue [yes/no]:");

choice = scan.next();

}

System.out.println("Enter the departure date to be counted:");

String departureDateStr = scan.next();

Date departureDate = sdf.parse(departureDateStr);

ShipmentEntity ship = new ShipmentEntity();

ship.setDepartureDate(departureDate);

System.out.println("Frequency : "+Collections.frequency(list, ship));

}

  

}

ShipmentEntity.java

import java.util.Date;

public class ShipmentEntity /*fill in blanks */ {

Integer id;

String name;

Date departureDate;

ShipmentEntity(){}

public ShipmentEntity(Integer id, String name, Date departureDate ) {

this.id = id;

this.name = name;

this.departureDate = departureDate;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public Date getDepartureDate() {

return departureDate;

}

public void setDepartureDate(Date departureDate) {

this.departureDate = departureDate;

}

public void setName(String name) {

this.name = name;

}

//fill your code

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

ShipmentEntity other = (ShipmentEntity) obj;

if (departureDate == null) {

if (other.departureDate != null)

return false;

} else if (!departureDate.equals(other.departureDate))

return false;

return true;

}

}

Output:

Enter the shipment entity details:
1113,Edward,09-09-2017
Do you want to continue [yes/no]:
yes
Enter the shipment entity details:
1112,Yashini,18-11-2017
Do you want to continue [yes/no]:
yes
Enter the shipment entity details:
1115,Collin,18-11-2017
Do you want to continue [yes/no]:
no
Enter the departure date to be counted:
18-11-2017
Frequency : 2

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