BSCCS2005: Jan 2026 NEW Questions
with Test Cases and Solutions
1. In a games event,Player p1 participates a set of games,Player p2 also participates all
the games participating by p1 except the second game, in place of which p2 participates
another [Link] a program that defines two classes Player and Event. Define copy
constructor to create p2 from p1 such that changing the values of instance variables of
either p2 or p1 does not affect the other one. The code takes name of player p2 and
the new game participating by p2 as input.
• Class Player has the following members.
– Private instance variables String name and String[] games to store name
and games participated respectively
– Define required constructor(s)
– Accessor methods getName() and getGames(int) to get the name of the player
and the game at a specific index respectively.
– Mutator methods setName(String) and setGames(int,String) to set the
name of the player and the game at a specific index respectively.
• Class Event has method main that does the following.
– Two objects of Player p1 and p2 are created. p2 is created using p1
– name of p2 and second game participated by p2 are updated by taking the
input
– Finally,name of p1, p2 and second game participated by p1 and p2 are printed
Template Code
import [Link].*;
class Player{
String name;
String[] games;
//*****Define constructor(s) here
public void setName(String n) {
name = n;
}
public void setGames(int indx, String g) {
games[indx] = g;
}
public String getName() {
return name;
}
public String getGames(int indx) {
return games[indx];
}
}
public class Main{
public static void main(String[] args) {
Page 2
Scanner sc = new Scanner([Link]);
String[] games = {"Throwball","Javelin","Volleyball"};
Player p1 = new Player("Ranjit", games);
Player p2 = new Player(p1);
[Link]([Link]());
[Link](1,[Link]());
[Link]([Link]() + ": "+ [Link](1));
[Link]([Link]() + ": " + [Link](1));
}
}
Public test case 1:
Input:
Sunil Football
Output:
Ranjit: Javelin
Sunil: Football
Public test case 2:
Input:
Pai Cricket
Output:
Ranjit: Javelin
Pai: Cricket
Private test case 1:
Input:
Kapil Cricket
Output:
Ranjit: Javelin
Kapil: Cricket
Page 3
2. Given an array of Staff objects of a Restaurant, that contains two Chef objects and
two Waiter objects. Each staff object contains the name,duty,and num (Number of
times he assigned to the duty). Here Chef only assigned to prepareFood, and he will
get rupees 500/duty, and Waiter only assigned to serveFood, and he will get rupees
200/duty.
• Abstract class Staff has the following members:
– String name, String duty and int num as private instance variables
– A constructor to initialize the instance variables
– Required accessor methods
– Method toString() is overridden to return the name of the staff
– Abstract method abstract String remuneration()
• Class Chef is a child class of class Staff and has the following members:
– A constructor to initialize the instance variables
– Method remuneration() is overridden to return num*500, if the duty is "prepareFood",
otherwise returns the string "Wrong duty assigned"
• Class Chef is a child class of class Staff and has the following members:
– A constructor to initialize the instance variables
– Method remuneration() is overridden to return num*200, if the duty is "serveFood",
otherwise returns the string "Wrong duty assigned"
• Class Test has/should have the following members:
– Define method printStaffRemunerations that prints the name and remuner-
ation of the staff if they are assigned valid duty, otherwise prints the name and
the correspond- ing error message for each staff.
– main method accepts the name, duty and num of two Chef members followed
by that of two Waiter, and invokes method printStaffRemunerations.
Template Code
import [Link].*;
abstract class Staff {
private String name;
private String duty;
private int num;
public Staff(String name, String duty, int num) {
[Link] = name;
[Link] = duty;
[Link] = num;
}
public String getDuty() {
return duty;
Page 4
}
public int getNum() {
return num;
}
public String toString() {
return name;
}
abstract String remuneration();
}
class Chef extends Staff{
public Chef(String name, String duty, int num) {
super(name, duty, num);
}
public String remuneration() {
if(getDuty().equals("prepareFood"))
return getNum()*500+"";
else
return "Wrong duty assigned";
}
}
class Waiter extends Staff{
public Waiter(String name, String duty, int num) {
super(name, duty, num);
}
public String remuneration() {
if(getDuty().equals("serveFood"))
return getNum()*200+"";
else
return "Wrong duty assigned";
}
}
public class Main {
//****** Define method printStaffRemunerations here
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Staff[] sArr = new Staff[4];
sArr[0] = new Chef([Link](), [Link](), [Link]());
sArr[1] = new Chef([Link](), [Link](), [Link]());
sArr[2] = new Waiter([Link](), [Link](), [Link]());
sArr[3] = new Waiter([Link](), [Link](), [Link]());
printStaffRemunerations(sArr);
}
}
Page 5
Public test case 1:
Input:
Vishnu serveFood 3
Diya prepareFood 4
Vaniha prepareFood 2
Lijo serveFood 4
Output:
Vishnu : Wrong duty assigned
Diya : 2000
Vaniha : Wrong duty assigned
Lijo : 800
Public test case 2:
Input:
Ayman prepareFood 3
Kailash prepareFood 4
Rani serveFood 2
Parvathi serveFood 4
Output:
Ayman : 1500
Kailash : 2000
Rani : 400
Parvathi : 800
Private test case 1:
Input:
Nila prepareFood 1
Pillai serveFood 2
Vijay serveFood 2
Latha serveFood 2
Output:
Nila : 500
Pillai : Wrong duty assigned
Vijay : 400
Latha : 400
Page 6
[Innerclass ]
3. Write a Java code that gives a simple demonstration of how a set of student registration
requests are processed in a department in a college. It accepts a specific number of seats
as input, and prints whether the registration is successful or not, based on the remaining
seats left. The code uses the concept of inner classes, and has the following components:
Registerable has an abstract method register()
• Class Department has the following members:
– name as an instance variable which represents department name
– constructor to initialize the instance variable
– an inner private class DeptEnquiry that has / does the following:
∗ reqseats, avalseats as instance variables that hold the number of requested
seats and available seats, respectively.
∗ implements interface Registerable (that has method register which re- turns
a string that describes whether registration is successful or not) that
enables its object to be accessible from outside the class Department.
∗ constructor to initialize the instance variables
∗ method public String register() checks whether avalseats is less than re-
qseats. If it is less, then it returns ”Cannot register”, else it returns ”Reg-
istered successfully available seats are ¡available seats¿”.
– method enrollRequest(int) that takes as input the number of seats to be reg-
istered as an argument and returns a Registerable object on which method
register() can be invoked.
Class Student has method main that does the following:
– creates an object of Department with the name DCSE. Using this object, it
invokes method enrollRequest to obtain a Registerable object, which invokes
method register on it.
What you have to do
– Define method enrollRequest(int) in class Department
Template Code
import [Link].*;
interface Registerable{
public abstract String register();
}
class Department{
String name;
public Department(String n){
name = n;
Page 7
}
private class DeptEnquiry implements Registerable{
int reqseats;
int avalseats;
public DeptEnquiry(int s) {
reqseats = s;
avalseats = 5;
}
public String register() {
if(avalseats < reqseats)
return "Cannot register";
else {
avalseats = avalseats - reqseats;
return "Registered successfully available seats are "+ avalseats;
}
}
}
//****** Define the method enrollRequest() here
}
public class Student {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Department d1 = new Department("DCSE");
[Link]([Link]());
[Link]([Link]());
}
}
Public test case 1:
Input:
1001
Output:
Failed transaction
Public test case 2:
Input:
999
Output:
Page 8
Money debited current balance is 1.0
Private test case 1:
Input:
699
Output:
Money debited current balance is 301.0
Private test case 2:
Input:
1000
Output:
Money debited current balance is 0.0
Page 9
4. Problem Statement
The Java program below takes as input the names of cricket players in a team and the
runs scored by each of them in 3 consecutive matches. The program is supposed to print
the names of those players who have scored at least 80 runs in all the matches. Complete
the code to obtain the specified output.
Class Team has the following members:
• Instance variable Map<String, ArrayList<Integer>> playerMap (maps the player
name to the list of runs scored by him/her in each match).
• A constructor to initialize the instance variable.
• An accessor method to access the instance variable.
Class FClass has the following members:
• A method getFinalList( ) that accepts an object of class Team as input and
returns the list of player names who has/have scored at least 80 runs in all the
matches.
• main( ) method does the following:
– accepts inputs to instantiate an object of Team. The input is accepted in the
order - player name followed by the list of his/her runs.
– invokes method getFinalList( ) by passing an object of Team as input, to
return the list of player names who has/have scored at least 80 runs in all the
matches.
– prints the list returned by the method getFinalList( )
What you have to do
• Define method getFinalList( ) of class FClass
Test Cases
Public test case 1 (Input):
Ravi 76 76 76
sonu 80 80 89
viral 98 47 99
Output:
[sonu]
Page 10
Test Cases
Public test case 2 (Input):
P1 79 80 45
P2 88 46 90
P3 89 56 21
Output:
[]
Private test case 1 (Input):
P1 82 97 120
P2 80 90 99
P3 87 112 145
Output:
[P1, P2, P3]
Private test case 2 (Input):
P1 23 90 92
P2 88 65 78
P3 80 80 80
Output:
[P3]
Template Code
import [Link].*;
class Team{
private Map<String, ArrayList<Integer>> playerMap;
public Team( Map<String, ArrayList<Integer>> m) {
playerMap = m;
}
public Map<String, ArrayList<Integer>> getPlayerMap(){
return playerMap;
}
Page 11
}
public class FClass{
public static ArrayList<String> getFinalList(Team t) {
// Define the method getFinalList( ) here
}
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Map<String, ArrayList<Integer>> pmap =
new LinkedHashMap<String, ArrayList<Integer>>();
for(int i = 0; i < 3; i++) {
ArrayList<Integer> pruns = new ArrayList<Integer>();
String name = [Link]();
for(int j = 0; j < 3; j++) {
[Link]([Link]());
}
[Link](name, pruns);
}
Team t = new Team(pmap);
[Link](getFinalList(t));
}
}
Page 12
5. Problem Statement
Write a Java program to find the sum of two complex numbers. You are given as input
two integers n1, n2 and two double values d1, d2, from which two complex numbers
c1 and c2 are obtained as described below.
• The real parts of c1 and c2 are n1 and d1 respectively, whereas their imaginary
parts are n2 and d2, respectively.
Class ComplexNum is a generic class with the following members.
• Instance variables r and i
• A constructor to initialize rand i
• Method add to return the sum of two instances of generic type ComplexNum
• Method toString() to format the output as is given in the test cases.
Class FClass has method main that does the following:
• Accepts two integers n1 and n2, and two doubles d1 and d2 as input
• Creates two objects of ComplexNum using the input values
• Invokes method add to obtain the sum
• prints the sum
What you have to do
• Define class ComplexNum
Template code
import [Link].*;
//DEFINE class ComplexNum
class FClass{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n1, n2;
double d1, d2;
n1 = [Link]();
n2 = [Link]();
d1 = [Link]();
d2 = [Link]();
ComplexNum<Integer> c1 = new ComplexNum<Integer>(n1, n2);
ComplexNum<Double> c2 = new ComplexNum<Double>(d1, d2);
ComplexNum<Double> c3 = [Link](c2);
Page 13
[Link](c1 + " + " + c2 + " = " + c3);
}
}
Public test case 1:
Input:
6 10
10.3 15.6
Output:
6.0 + 10.0i + 10.3 + 15.6i = 16.3 + 25.6i
Public test case 2:
Input:
10 15
5.4 1.6
Output:
10.0 + 15.0i + 5.4 + 1.6i = 15.4 + 16.6i
Private test case 1:
Input:
3 15
5.4 2.8
Output:
3.0 + 15.0i + 5.4 + 2.8i = 8.4 + 17.8i
Private test case 1:
Input:
10 20
13.3 5.12
Output:
10.0 + 20.0i + 13.3 + 5.12i = 23.3 + 25.12i
Page 14
Solution:
import [Link].*;
class ComplexNum<T extends Number>{
private T r, i;
public ComplexNum(T r, T i) {
this.r = r;
this.i = i;
}
public ComplexNum<Double> add(ComplexNum<?> c){
ComplexNum<Double> dc = new ComplexNum<Double>(0.0, 0.0);
dc.r = [Link]() + [Link]();
dc.i = [Link]() + [Link]();
return dc;
}
public String toString() {
return [Link]() + " + " + [Link]() + "i";
}
}
class FClass{
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n1, n2;
double d1, d2;
n1 = [Link]();
n2 = [Link]();
d1 = [Link]();
d2 = [Link]();
ComplexNum<Integer> c1 = new ComplexNum<Integer>(n1, n2);
ComplexNum<Double> c2 = new ComplexNum<Double>(d1, d2);
ComplexNum<Double> c3 = [Link](c2);
[Link](c1 + " + " + c2 + " = " + c3);
}
}
Page 15