Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution | HAS-A-Relationship Solution Java

Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution HAS-A-Relationship
Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution HAS-A-Relationship

In this post, you will get the solution to the first problem of Capgemini ADAPT Sprint 2 –  Bus Reservation System JBR-CS5A-L3-1-HAS-A-Relationship.

Note: The solutions are provided for learning purposes only. 

Sprint 2 – Problem 1: JBR-CS5A-L3-1-HAS-A-Relationship:


Capgemini ADAPT Problem Description:


Create Customer, Address and ServiceDetails class as per the given structure with setter and getter methods. Customer and Address classes are related to Has-a-relationship.

Create a constructor for the Customer and Address with all the fields of the class.

Override the toString() method to return all the fields using String concatenation.

Example: toString() method of ServiceDetails

ServiceDetails [serviceId=SID1001, busId=BUS001, deptDateTime=10/01/2022, arrDateTime=15/01/2022, arrivalCity=Bangalore, deptCity=Delhi, cost=2500, seatsLeft=9, totalSeats=70]

Sprint 2 HAS A Relationship Solution
Sprint 2 HAS A Relationship Solution

Sample Input:


Address address=new Address(“Bangalore”, “Karnataka”, 123456, “India”);

ServiceDetails serviceDetails=new ServiceDetails(“SID1001”, “BUS001”, “10/01/2022”, “15/01/2022”, “Bangalore”, “Delhi”, “2500”, “9”, “70”);

Customer customer=new Customer(“1001”, “[email protected]”, “Password”, “Raj”, “Kumar”, “Bangalore”, “Male”, “1234567890”, address, serviceDetails);

Sample Output:


Customer[userId=1001, [email protected], password=Password, firstName=Raj, lastName=Kumar, city=Bangalore, gender=Male, phoneNumber=1234567890, address=Address[city=Bangalore, state=Karnataka, zip=123456, country=India], serviceDetails=ServiceDetails[serviceId=SID1001, busId=BUS001, deptDateTime=10/01/2022, arrDateTime=15/01/2022, arrivalCity=Bangalore, deptCity=Delhi, cost=2500, seatsLeft=9, totalSeats=70]

Execution Time Limit:


10 seconds

The solution to JBR-CS5A-L3-1-HAS-A-Relationship:


 

class Customer{
String userId;
String emailId;
String password;
String firstName;
String lastName;
String city;
String gender;
String phoneNumber;

Address address;

ServiceDetails serviceDetails;

public Customer(){
super();
}

public Customer(String userId, String emailId, String password, String firstName, String lastName, String city, String gender, String phoneNumber){

this.userId = userId;
this.emailId = emailId;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
this.gender = gender;
this.phoneNumber = phoneNumber;
this.address = address;
this.serviceDetails = serviceDetails;
}

public String getUserId(){
return this.userId;
}
public void setUserId(String userId){
this.userId = userId;
}

public String getEmailId(){
return this.emailId;
}
public void setEmailId(String emailId){
this.emailId = emailId;
}

public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password = password;
}

public String getFirstName(){
return this.firstName;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}

public String getLastName(){
return this.lastName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}

public String getCity(){
return this.city;
}
public String setCity(String city){
this.city = city;
}

public String getGender(){
return this.gender;
}
public String setGender(String gender){
this.gender = gender;
}

public String getPhoneNumber(){
return this.phoneNumber;
}
public void setPhoneNumber(String phoneNumber){
this.phoneNumber = phoneNumber;
}

public Address getAddress(){
return this.address;
}
public void setAddress(Address address){
this.address = address;
}

public ServiceDetails getServiceDetails(){
return this.serviceDetails;
}
public void setServiceDetails(ServiceDetails serviceDetails){
this.serviceDetails = serviceDetails;
}

@Override
public String toString(){
return "Customer [userId="+userId+", emailId="+emailId+", password="+password+", firstName="+firstName+", lastName="+lastName+", city="+city+", gender="+gender+", phoneNumber="+phoneNumber+", address="+address+", serviceDetails="+serviceDetails+"]";
}
}

class Address
{
String city;
String state;
int zip;
String country;

public Address(){
super();
}

public Address(String city, String state, int zip, String country){

super();
this.city = city;
this.state = state;
this.zip = zip;
this.country = country;
}

@Override
public String toString(){
return "Address [city="+city+", state="+state+", zip="+zip+", country="+country+"]";
}
}

class ServiceDetails
{
String serviceId;
String busId;
String deptDateTime;
String arrDateTime;
String arrivalCity;
String deptCity;
String cost;
String seatsLeft;
String totalSeats;

public ServiceDetails(){
super();
}

public ServiceDetails(String serviceId, String busId, String deptDateTime, String arrDateTime, String arrivalCity, String deptCity, String cost, String seatsLeft, String totalSeats){

super();
this.serviceId = serviceId;
this.busId = busId;
this.deptDateTime = deptDateTime;
this.arrDateTime = arrDateTime;
this.arrivalCity = arrivalCity;
this.deptCity = deptCity;
this.cost = cost;
this.seatsLeft = seatsLeft;
this.totalSeats = totalSeats;
}

public String getServiceId(){
return this.serviceId;
}
public void setServiceId(String serviceId){
this.serviceId = serviceId;
}

public String getBusId(){
return this.busId;
}
public void setBusId(String busId){
this.busId = busId;
}

public String getDeptDateTime(){
return this.deptDateTime;
}
public void setDeptDateTime(String deptDateTime){
this.deptDateTime = deptDateTime;
}

public String getArrDateTime(){
return this.arrDateTime;
}
public void setArrDateTime(String arrDateTime){
this.arrDateTime = arrDateTime;
}

public String getArrivalCity(){
return this.arrivalCity;
}
public void setArrivalCity(String arrivalCity){
this.arrivalCity = arrivalCity;
}

public String getDeptCity(){
return this.deptCity;
}
public void setDeptCity(String deptCity){
this.deptCity = deptCity;
}

public String getCost(){
return this.cost;
}
public void setCost(String cost){
this.cost = cost;
}

public String getSeatsLeft(){
return this.seatsLeft;
}
public void setSeatsLeft(String seatsLeft){
this.seatsLeft = seatsLeft;
}

public String getTotalSeats(){
return this.totalSeats;
}
public void setTotalSeats(String totalSeats){
this.totalSeats = totalSeats;
}

@Override
public String toString(){
return "ServiceDetails [serviceId="+serviceId+", busId="+busId+", deptDateTime="+deptDateTime+", arrDateTime="+arrDateTime+", arrivalCity="+arrivalCity+", deptCity="+deptCity+", cost="+cost+", seatsLeft="+seatsLeft+", totalSeats="+totalSeats+"]";
}
}

public class Source{
public static void main(String args[]){
Address address = new Address("Bangalore", "Karnataka", 123456, "India");
ServiceDetails = serviceDetails = new ServiceDetails("SID1001", "BUS001", "10/01/2022", "15/01/2022", "Bangalore", "Delhi", "2500", "9", "70");
System.out.println(serviceDetails);
Customer customer = new Customer("1001", "[email protected]", "Password", "Raj", "Kumar", "Bangalore", "Male", "1234567890", address, serviceDetails);
}
}

 

TOP COMPANIES HIRING DRIVE

BATCHWISE OFF-CAMPUS DRIVES

1. TCS OFF-CAMPUS DRIVES1. 2018 BATCH
2. INFOSYS OFF-CAMPUS DRIVES2. 2019 BATCH
3. COGNIZANT OFF-CAMPUS DRIVES3. 2020 BATCH
4. WIPRO OFF-CAMPUS DRIVES4. 2021 BATCH
5. CAPGEMINI OFF-CAMPUS DRIVES5. 2022 BATCH

 

To Stay Up-to-date, Follow us on Social Media:


1.      Join our Telegram Channel:

Click Here

2.      Like us on Facebook:

Click Here

3.      Follow us on Instagram:

Click Here

4.      Follow us on LinkedIn:

Click Here

5.      Follow us on Google News:

Click Here

 

Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):


Study Materials for Interview Preparation (FREE MATERIALS):


  1. 240 Core Java Questions & Answers with PDF Download Link – Click Here
  2. 230+ SQL interview questions & answers pdf download – Click Here
  3. 50 LeetCode Interview Questions with Answers – PDF Notes – Click Here