Instruments Problem Solution in Java | Capgemini ADAPT Solutions 2022
Instruments Problem Solution in Java | Capgemini ADAPT Solutions 2022

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. 

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 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
  3. Instruments Problem Solution – Click Here
  4. Check Two Person Are Same – 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