In this post, you will get the solution to the Capgemini ADAPT 2022 solution to the problem Instruments in Java. Capgemini ADAPT Java Solutions 2022, Instruments.
Note: The solutions are provided for learning purposes only.
Table of Contents
- Instruments Problem Description:
- Instruments Problem Solution in Java – Capgemini ADAPT 2022:
- To Stay Up-to-date, Follow us on Social Media:
- ADAPT Different Coding Solutions:
- Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):
- Capgemini ADAPT Sprint 2 (Bus Reservation System):
- Study Materials for Interview Preparation (FREE MATERIALS):
Instruments Problem Description:
Create an abstract class Instruments which is having the abstract function play.
*Create three more subclasses from Instrument which is Piano, Flute, and Guitar.
*Override the play mentioned inside all three classes printing a message
*”Piano” for Piano Class
*”Flute” for Flute class
*”Guitar” for Guitar class
* You must not allow the user to declare an object of the Instrument class.
*Create an array of 10 Instruments.
*Assign different types of instruments to Instrument reference.
*Check for the polymorphic behaviour of the play method.
*Use the instance of the operator to print which object is stored at which index of the Instrument array.
Instruments Problem Solution in Java – Capgemini ADAPT 2022:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
abstract class Instrument
{
abstract void play();
}
class Piano extends Instrument {
@Override
void play() {
System.out.println("Piano");
}
}
class Flute extends Instrument
{
@Override
void play()
{
System.out.println("Flute");
}
}
class Guitar extends Instrument
{
@Override
void play()
{
System.out.println("Guitar");
}
}
public class Source{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
Instrument[] is = new Instrument[10];
int a;
a = in.nextInt();
if(a == 1){
for(int i = 0; i < 10; i++){
is[i] = new Piano();
}
for(int i = 0; i < 10; i++){
is[i].play();
}
}
else if(a==2)
{
for(int i = 0; i < 10; i++)
{
is[i] = new Flute();
}
for(int i = 0; i < 10; i++){
is[i].play();
}
else
{
for(int i = 0; i < 10; i++)
{
is[i] = new Guitar();
}
for(int i = 0; i < 10; i++)
{
is[i].play();
}
}
}
}
TOP COMPANIES HIRING DRIVE |
BATCHWISE OFF-CAMPUS DRIVES |
| 1. TCS OFF-CAMPUS DRIVES | 1. 2018 BATCH |
| 2. INFOSYS OFF-CAMPUS DRIVES | 2. 2019 BATCH |
| 3. COGNIZANT OFF-CAMPUS DRIVES | 3. 2020 BATCH |
| 4. WIPRO OFF-CAMPUS DRIVES | 4. 2021 BATCH |
| 5. CAPGEMINI OFF-CAMPUS DRIVES | 5. 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:
- Largest Array Solution – Click Here
- Batsman & Bowler Solution – Click Here
- Instruments Problem Solution – Click Here
- Check Two Person Are Same – Click Here
Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):
- 1. Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerInAscendingOrder Problem Solution
- 2. Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerByFirstName Problem Solution
- 3. Capgemini ADAPT Sprint 1 Bus Reservation System – SortByCustomerId Problem Solution
- 4. Capgemini ADAPT Sprint 1 Solution Java | LSAByCustomerName Problem Solution
- 5. Capgemini ADAPT Sprint 1 Case Study Solution Java | BSAByCustomerId Problem Solution
Capgemini ADAPT Sprint 2 (Bus Reservation System):
- 1. Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution | HAS-A-Relationship Solution Java
- 2. Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution OOPs-Para-Constructor Java
- 3. Capgemini ADAPT Sprint 2 Bus Reservation System (CRUDOperations) Problem Solution
Study Materials for Interview Preparation (FREE MATERIALS):
- 240 Core Java Questions & Answers with PDF Download Link – Click Here
- 230+ SQL interview questions & answers pdf download – Click Here
- 50 LeetCode Interview Questions with Answers – PDF Notes – Click Here



