Capgemini ADAPT Solution | Batsman & Bowler Problem Solution in JAVA

Capgemini ADAPT 2022 Solution | Batsman & Bowler Problem Solution in Java
Capgemini ADAPT 2022 Solution | Batsman & Bowler Problem Solution in Java

In this post, you will get the solution to the Capgemini ADAPT 2022 solution to the problem Batsman & Bowler in Java.

Note: The solutions are provided for learning purposes only. 

Table of Contents

Batsman & Bowler Problem Description:


Create a java class Coach.

The coach’s job is to coach the Batsman and Bowler.

Implement loose coupling by introducing an Interface IPlayer

Create both the Batsman and Bowler classes, they must implement the interface IPlayer.

IPlayer interface must have play() method which returns String.

play(): String

Coach class has one private attribute:

player: IPlayer

and two methods:-

setplayer(IPlayer player): void – will set IPlayer

coach(): String – will play() using player object

will return “Batsman is batting”, if Batsman object is passed and

“Bowler is bowling”, if Bowler Object is passed to the setIPlayer method.

Print “Invalid Input”, if other than Batsman or Bowler is given as Sample Input.

Pass the Batsman object or Bowler object to the setIPlayer method and call the coach() method to return the information.

Print the returned information coach() method.

 

Batsman & Bowler Problem Solution in Java:


import java.io.*;
import java.util.*;
import java.text.*;
import.math.*;
import java.util.regex.*;
import java.util.Scanner;
interface IPlayer{
String play();
}
class Batsman implements IPlayer{
public String play(){
return("Batsman is batting");
}
}
class Bowler implements IPlayer{
public String play(){
return("Bowler is bowling");
}
}
class coach{
private IPlayer player;
void setPlayer(IPlayer player){
this.player = player;
}
String coach(){
return player.play();
}
}
public class Source{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String s = sc.next();
coach c = new coach();
if (s.equals("Batsman")){
Batsman ip = new Batsman();
c.setPlayer(ip);
System.out.println(c.coach());
}
else if (s.equals("Bowler")){
Bowler ip = new Bowler();
c.setPlayer(ip);
System.out.println(c.coach());
}
else
{
System.out.println("Invalid Input");
}
}
}

 

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

 

ADAPT Different Coding Solutions:


  1. Largest Array Solution – Click Here
  2. Batsman & Bowler Solution – Click Here

Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):


Capgemini ADAPT Sprint 2 (Bus Reservation System):


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
Previous articleCapgemini ADAPT 2022 Solution | Largest Array Problem Solution in Java
Next articleCheck Two Persons Are Same Problem Solution in Java | Capgemini ADAPT 2022 Solutions
Job Seeker 24 provides Off-Campus Drive Updates, Engineering Job Updates, IT Job Updates, Jobs for Freshers, Private Sector Jobs, Public Sector Jobs, various Educational Opportunities, etc.