Java SBQ
Java SBQ
*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
class Player
int id;
int matchesPlay;
int totalRun;
String name;
String team;
public Player(int id, int matchesPlay, int totalRun, String name, String team) {
super();
[Link] = id;
[Link] = matchesPlay;
[Link] = totalRun;
[Link] = name;
[Link] = team;
return id;
[Link] = id;
return name;
}
public void setName(String name) {
[Link] = name;
return team;
[Link] = team;
return matchesPlay;
[Link] = matchesPlay;
return totalRun;
[Link] = totalRun;
int n=[Link]();
for(int i=0;i<[Link];i++)
int id = [Link]();
double r = findAverageTotalRunsOfPlayer(p);
else{
Player pr = findPlayerWithMaximumMatchesPlayed(p);
else{
[Link]("id-"+[Link]());
[Link]("matchesPlayed-"+[Link]());
[Link]("totalRuns-"+[Link]());
[Link]("name-"+[Link]());
[Link]("team-"+[Link]());
[Link]();
double sum = 0;
if(sum == 0)
return 0;
else
return (sum/4);
//method logic
Player maxPlayed=player[0];
int maxMatches=0;
if (player[i].getMatchPlay()>maxMatches){
maxPlayed=player[i];
maxMatches=player[i].getMatchPlay();
}
if(maxMatches==0){return null;}
else{
return maxPlayed;
import [Link].*;
int itemId;
String itemType;
String itemName;
double itemPrice;
int yearofMFG;
for(int i=0;i<[Link];i++) {
itemId = [Link]();
[Link]();
itemType = [Link]();
itemName = [Link]();
itemPrice = [Link]();
yearofMFG = [Link]();
[Link]();
if(count>0) {
[Link](count);
}
else {
[Link]("no Item");
if(shop1 == null) {
[Link]("no item");
else {
[Link]([Link]()+";"+[Link]()+";"+[Link]());
int c =0;
for(int i=0;i<[Link];i++) {
if(shop[i].getYearofMFG() == yearofMFG ) {
c++;
return c;
int j =0;
for(int i =0;i<[Link];i++) {
if(shop[i].getItemType().equalsIgnoreCase(itemType)) {
j++;
if(j==0)
return null;
j=0;
for(int i =0;i<[Link];i++) {
if(shop[i].getItemType().equalsIgnoreCase(itemType)) {
shop2[j++] = shop[i];
for(int i=0;i<[Link];i++) {
for(int k=i+1;k<[Link];k++) {
if(shop2[i].getItemPrice()<shop2[k].getItemPrice()) {
shop2[i] = shop2[k];
shop2[k] = temp;
return shop2[0];
class ShoppingItem{
int itemId;
String itemType;
String itemName;
double itemPrice;
int yearofMFG;
public ShoppingItem(int itemId, String itemType, String itemName, double itemPrice, int
yearofMFG) {
super();
[Link] = itemId;
[Link] = itemType;
[Link] = itemName;
[Link] = itemPrice;
[Link] = yearofMFG;
return itemId;
return itemType;
return itemName;
}
public double getItemPrice() {
return itemPrice;
return yearofMFG;
import [Link].*;
class Employee{
int employeeId;
String employeeName;
double salary;
String grade;
String location;
int yearsOfExperience;
Employee(int employeeId, String employeeName, double salary, String grade, String location, int
yearsOfExperience){
[Link] = employeeId;
[Link] = employeeName;
[Link] = salary;
[Link] = grade;
[Link] = location;
[Link] = yearsOfExperience;
int getEmployeeId(){
return employeeId;
String getEmployeeName(){
return employeeName;
double getSalary(){
return salary;
String getGrade(){
return grade;
String getLocation(){
return location;
int getYearsOfExperience(){
return yearsOfExperience;
int employeeId;
String employeeName;
double salary;
String grade;
String location;
int yearsOfExperience;
for(int i=0;i<[Link];i++){
employeeId = [Link]();[Link]();
employeeName = [Link]();
salary = [Link]();[Link]();
grade = [Link]();
location = [Link]();
yearsOfExperience = [Link]();
[Link]();
[Link]();
if(countOfEmployees == 0)
else
[Link](countOfEmployees);
if(emp1 == null)
else
[Link]([Link]()+":"+[Link]()+":"+[Link]());
int count = 0;
for(int i=0;i<[Link];i++){
if([Link](emp[i].getLocation())){
if(emp[i].getYearsOfExperience()>2){
count++;
return count;
int count = 0;
for(int i=0;i<[Link];i++){
if([Link](emp[i].getGrade()))
count++;
count = 0;
for(int i=0;i<[Link];i++){
if([Link](emp[i].getGrade()))
emp1[count++] = emp[i];
for(int i=0;i<[Link];i++){
for(int j=i+1;j<[Link];j++){
if(emp1[i].getSalary()>emp1[j].getSalary()){
emp1[j] = temp;
return emp1[[Link]-1];
}
import [Link];
class Employee{
public Employee(int empId, String empName, int mgrId, String deptName, double salary){
[Link] = empId;
[Link] = empName;
[Link] = mgrId;
[Link] = deptName;
[Link] = salary;
return empId;
return empName;
return mgrId;
int empId;
String empName;
int mgrId;
String deptName;
double salary;
for(int i=0;i<[Link];i++){
empId = [Link]();[Link]();
empName = [Link]();
mgrId = [Link]();[Link]();
deptName = [Link]();
salary = [Link]();
[Link](count);
else
if(employee == null)
[Link]("No Managers");
else
[Link]([Link]()+"#"+[Link]());
int count = 0;
for(int i=0;i<[Link];i++)
if(emp[i].getSalary() > 0) {
sum += emp[i].getSalary();
count++;
count = 0;
for(int i=0;i<[Link];i++){
count++;
return count;
}
int count = 0;
for(int i=0;i<[Link];i++)
if(emp[i].getMgrId() != 0)
count++;
for(int i=0;i<[Link];i++){
if(emp[i].getMgrId() != 0)
maxSalary = emp[i].getSalary();
for(int i=0;i<[Link];i++){
if(emp[i].getSalary() == maxSalary)
return emp[i];
return null;
}
import [Link];
String vehicleId;
String vehicleType;
String modeOfPayment;
double fare;
vehicleId = [Link]();
vehicleType = [Link]();
modeOfPayment = [Link]();
fare = [Link]();
[Link]();
[Link]();
if(totalCollection == 0)
else
[Link](totalCollection);
if(findVehicle == null)
else
[Link]([Link]()+"#"+[Link]()+"#"+[Link]
deOfPayment()+"#"+[Link]());
}
double totolFare = 0;
for(int i=0;i<[Link];i++){
if([Link](tollplazaArr[i].getModeOfPayment()))
totolFare += tollplazaArr[i].getFare();
return totolFare;
for(int i=0;i<[Link];i++){
if([Link](tollplazaArr[i].getVehicleId()))
return tollplazaArr[i];
return null;
class TollPlaza{
String vehicleId;
String vehicleType;
String modeOfPayment;
double fare;
[Link] = vehicleId;
[Link] = vehicleType;
[Link] = modeOfPayment;
[Link] = fare;
String getVehicleId(){
return vehicleId;
String getVehicleType(){
return vehicleType;
String getModeOfPayment(){
return modeOfPayment;
double getFare(){
return fare;
}
import [Link].*;
for(int i=0;i<[Link];i++)
{
int policyId=[Link]();[Link]();
String policyName=[Link]();
String paymentMode=[Link]();
double policyAmount=[Link]();
int newPolicyId=[Link]();
int percentageAlreadyClaimed=[Link]();
boolean claimed=[Link]();
double minAmount=[Link]();
double maxAmount=[Link]();
[Link]();
if(newPolicyAmount==0){
else
if(newPolicy!=null){
[Link]("Policy Id:"+[Link]());
else
[Link]("No Policy available within the specified range");
double newPolicyAmount=0;
for(int i=0;i<[Link];i++)
newPolicyAmount = policy[i].getPolicyAmount() -
((policy[i].getPolicyAmount()*percentageAlreadyClaimed)/100);
policy[i].setPolicyAmount(newPolicyAmount);
return newPolicyAmount;
for(int i=0;i<[Link];i++) {
return policy[i];
return null;
}
class Policy
int policyId;
String policyName;
String paymentMode;
double policyAmount;
[Link] = policyId;
[Link] = policyName;
[Link] = paymentMode;
[Link] = policyAmount;
int getPolicyId() {
return policyId;
String getPolicyName() {
return policyName;
String getPaymentMode() {
return paymentMode;
double getPolicyAmount() {
return policyAmount;
[Link] = policyAmount;
}
Q1 :-
import [Link].*;
int billId;
String custName;
int units;
for(int i=0;i<[Link];i++) {
billId = [Link]();[Link]();
custName = [Link]();
units = [Link]();
[Link]();
Bill b = getBillWithHighAmnt(bill);
if(noOfBills == 0)
else
[Link](noOfBills);
if(b == null)
else
for(int i=0;i<[Link];i++) {
if(bills[i].getUnits()>=1000)
billAmnt = bills[i].getUnits() * 5;
billAmnt = bills[i].getUnits() * 3;
else if(bills[i].getUnits()<500)
billAmnt = bills[i].getUnits() * 1;
return count;
int maxUnits=-999;
for(int i=0;i<[Link];i++) {
if(bills[i].getUnits()>=maxUnits)
maxUnits = bills[i].getUnits();
}
for(int i=0;i<[Link];i++) {
if(maxUnits == bills[i].getUnits())
return bills[i];
return null;
class Bill{
int billId;
String custName;
int units;
[Link] = billId;
[Link] = custName;
[Link] = units;
int getBillId() {
return billId;
String getCustName() {
return custName;
int getUnits() {
return units;
}
Q2-
import [Link].*;
double ticketCost;
for(int i=0;i<[Link];i++){
busNo = [Link]();
fromStation = [Link]();
toStation = [Link]();
ticketCost = [Link]();[Link]();
[Link]();
if(cost>0)
[Link](cost);
else
if(b==null)
else
[Link]([Link]());
for(int i=0;i<[Link];i++){
if([Link](bus[i].getFromStation()) &&
[Link](bus[i].getToStation()))
return bus[i];
return null;
for(int i=0;i<[Link];i++){
minCost = bus[i].getTicketCost();
maxCost = bus[i].getTicketCost();
return minCost+maxCost;
}
class Bus{
double ticketCost;
[Link] = busNo;
[Link] = fromStation;
[Link] = toStation;
[Link] = ticketCost;
String getBusNo(){
return busNo;
String getFromStation(){
return fromStation;
String getToStation(){
return toStation;
double getTicketCost(){
return ticketCost;
Q3-
import [Link].*;
String studentName;
for(int i=0;i<[Link];i++) {
studentId = [Link]();[Link]();
studentName = [Link]();
sub1 = [Link]();
sub2 = [Link]();
sub3 = [Link]();
[Link]();
if(passedStudents == 0)
else
[Link](passedStudents);
if(stu == null)
[Link]("No one has passed");
else
[Link]([Link]()+"#"+[Link]());
int count = 0;
for(int i=0;i<[Link];i++) {
count++;
return count;
int count = 0;
for(int i=0;i<[Link];i++) {
count++;
count = 0;
for(int i=0;i<[Link];i++) {
s[count++] = students[i];
}
int sum = s[0].getSub1()+s[0].getSub2()+s[0].getSub3();
for(int i=1;i<[Link];i++) {
sum = s[i].getSub1()+s[i].getSub2()+s[i].getSub3();
for(int i=0;i<[Link];i++) {
if(sum == s[i].getSub1()+s[i].getSub2()+s[i].getSub3())
return s[i];
return null;
class Student{
String studentName;
Student(int studentId, String studentName, int sub1, int sub2, int sub3){
[Link] = studentId;
[Link] = studentName;
this.sub1 = sub1;
this.sub2 = sub2;
this.sub3 = sub3;
int getStudentId() {
return studentId;
}
String getStudentName() {
return studentName;
int getSub1() {
return sub1;
int getSub2() {
return sub2;
int getSub3() {
return sub3;
Q-4
import [Link].*;
int empId;
String empName;
int mgrId;
String deptName;
double salary;
for(int i=0;i<[Link];i++){
empId = [Link]();
empName = [Link]();
mgrId = [Link]();[Link]();
deptName = [Link]();
salary = [Link]();
[Link]();
double r1=[Link]();
double r2=[Link]();
int res=findempsWithSalRange(emp,r1,r2);
if(res==0)
else
[Link](res);
Employee res2=getEmployeeWitMaxSal(emp);
if(res2==null)
[Link]("NOT FOUND");
else
[Link]([Link]+"#"+[Link]+"#"+[Link]);
int c=0;
for(int i=0;i<[Link];i++)
c++;
if (c==0)
return 0;
else
return c;
Employee t=emp[i];
emp[i]=emp[j];
emp[j]=t;
}
}
return emp[0];
class Employee
int empId;
String empName;
int mgId;
String deptName;
double salary;
return empId;
public Employee(int empId, String empName, int mgId, String deptName, double salary) {
super();
[Link] = empId;
[Link] = empName;
[Link] = mgId;
[Link] = deptName;
[Link] = salary;
[Link] = empId;
}
return empName;
[Link] = empName;
return mgId;
[Link] = mgId;
return deptName;
[Link] = deptName;
return salary;
[Link] = salary;
}
}
Q5-
import [Link].*;
import [Link].*;
int contestId;
String contestName;
String contestWinner;
int points;
String category;
contestId = [Link]();[Link]();
contestName = [Link]();
contestWinner = [Link]();
points = [Link]();[Link]();
category = [Link]();
[Link]();
else
[Link](totalPoints);
if(contest == null)
else
[Link]([Link]()+"\n"+[Link]());;
int totalPoints = 0;
if([Link]().equalsIgnoreCase(contestWinner))
totalPoints += [Link]();
return totalPoints;
if([Link]().equalsIgnoreCase(category))
[Link](contest);
}
if([Link]()<=1) return null;
return [Link]([Link]()-2);
@Override
class Contest{
public Contest(int contestId, String contestName, String contestWinner, int points, String category){
[Link] = contestId;
[Link] = contestName;
[Link] = contestWinner;
[Link] = points;
[Link] = category;
return contestName;
return contestWinner;
return points;
return category;
Q5-
import [Link];
int bottleId;
String bottleBrand;
String bottleType;
int capacity;
String material;
double price;
bottleId = [Link]();[Link]();
bottleBrand = [Link]();
bottleType = [Link]();
capacity = [Link]();[Link]();
material = [Link]();
price = [Link]();
[Link]();
[Link]();
if(averagePriceBasedOnMaterial > 0)
[Link](averagePriceBasedOnMaterial);
else
if(secondHighestBottlePrice == null)
else
double totalCartPrice = 0;
int count = 0;
if([Link](bottles[iterator].getMaterial())){
totalCartPrice += bottles[iterator].getPrice();
count++;
if(count > 0)
else
return 0;
}
//code the second method
int count = 0;
if([Link](bottles[i].getBottleBrand()))
count++;
count = 0;
if([Link](bottles[i].getBottleBrand())){
b[count++] = bottles[i];
b[i] = b[j];
b[j] = temp;
}
return b[1];
class Bottle{
public Bottle(){}
public Bottle(int bottleId, String bottleBrand, String bottleType, int capacity, String material, double
price){
[Link] = bottleId;
[Link] = bottleBrand;
[Link] = bottleType;
[Link] = capacity;
[Link] = material;
[Link] = price;
return bottleId;
}
public String getBottleBrand(){
return bottleBrand;
return bottleType;
return capacity;
return material;
return price;
Q-6
import [Link].*;
for(int i=0;i<[Link];i++) {
[Link]();
if(b == null)
else {
for(int i=0;i<[Link];i++)
[Link](b[i].getBillNo()+"#"+b[i].getName());
if(countOfBills == 0)
else
[Link](countOfBills);
}
public static Bill[] findBillWithMaxBillAmountBasedOnStatus(Bill[] bill, boolean parameter) {
int count = 0;
for(int i=0;i<[Link];i++) {
if(bill[i].getStatus() == parameter)
count++;
count = 0;
for(int i=0;i<[Link];i++) {
if(bill[i].getStatus() == parameter) {
b[count++] = bill[i];
double maxBill = 0;
for(int i=0;i<[Link];i++) {
maxBill = b[i].getBillAmount();
count = 0;
for(int i=0;i<[Link];i++){
if(b[i].getBillAmount() == maxBill)
count++;
}
Bill[] newBill = new Bill[count];
for(int i=0;i<[Link];i++) {
for(int j=i+1;j<[Link];j++) {
if(b[i].getBillNo()>=b[j].getBillNo()) {
b[i] = b[j];
b[j] = temp;
count = 0;
for(int i=0;i<[Link];i++) {
if(maxBill == b[i].getBillAmount())
newBill[count++] = b[i];
return newBill;
int count = 0;
for(int i=0;i<[Link];i++) {
if([Link](bill[i].getTypeOfConnection()))
count++;
return count;
}
}
class Bill{
int billNo;
String name;
String typeOfConnection;
double billAmount;
boolean status;
Bill(int billNo, String name, String typeOfConnection, double billAmount, boolean status){
[Link] = billNo;
[Link] = name;
[Link] = typeOfConnection;
[Link] = billAmount;
[Link] = status;
int getBillNo() {
return billNo;
String getName() {
return name;
String getTypeOfConnection() {
return typeOfConnection;
double getBillAmount() {
return billAmount;
boolean getStatus() {
return status;
Q7:-
import [Link].*;
String songName;
int duration;
String artists;
String genre;
for(int i=0;i<[Link];i++) {
songName = [Link]();
duration = [Link]();[Link]();
artists = [Link]();
genre = [Link]();
if(findSong == null)
else
for(int i=0;i<[Link];i++) {
[Link](findSong[i]);
if(a==null)
else
for(int i=0;i<[Link];i++) {
[Link](a[i].getSongName()+"#"+a[i].getDuration()+"#"+a[i].getArtists()+"#"+a[i].get
Genre());
int count = 0;
for(int i=0;i<[Link];i++) {
if([Link](album[i].getGenre())) {
if(album[i].getDuration()>5)
count++;
}
count = 0;
for(int i=0;i<[Link];i++) {
if([Link](album[i].getGenre())) {
if(album[i].getDuration()>5)
song[count++] = album[i].getSongName();
return song;
int count = 0;
for(int i=0;i<[Link];i++) {
if(album[i].getArtists().equalsIgnoreCase(artists)){
if(album[i].getGenre().equalsIgnoreCase("Melody"))
count++;
count = 0;
for(int i=0;i<[Link];i++) {
if(album[i].getArtists().equalsIgnoreCase(artists)){
if(album[i].getGenre().equalsIgnoreCase("Melody"))
a[count++] = album[i];
for(int i=0;i<[Link];i++) {
for(int j=i+1;j<[Link];j++) {
if(a[i].getSongName().compareTo(a[j].getSongName())>0) {
a[i] = a[j];
a[j] = temp;
return a;
class Album{
String songName;
int duration;
String artists;
String genre;
[Link] = songName;
[Link] = duration;
[Link] = artists;
[Link] = genre;
String getSongName() {
return songName;
int getDuration() {
return duration;
String getArtists() {
return artists;
String getGenre() {
return genre;
Q8:-
import [Link].*;
String theatreName;
double ticketRate;
Theatre[] th = new Theatre[4];
for(int i=0;i<[Link];i++) {
theatreId = [Link]();[Link]();
theatreName = [Link]();
seatCapacity = [Link]();
ticketRate = [Link]();
theatreRating = [Link]();
[Link]();
Theatre t = findSecondHighestTicket(th);
if(theatreCategory == null)
else
[Link](theatreCategory);
if(t == null)
else
[Link]([Link]());
for(int i=0;i<[Link];i++) {
if(theatreId == th[i].getTheatreId() ) {
s = "Premium";
else
s = "Non Premium";
return s;
int count = 0;
for(int i=0;i<[Link];i++) {
if(th[i].getTheatreRating()>=2) count++;
count = 0;
for(int i=0;i<[Link];i++) {
if(th[i].getTheatreRating()>=2)
t[count++] = th[i];
for(int i=0;i<[Link];i++) {
for(int j=i+1;j<[Link];j++) {
if(t[i].getTicketRate() <= t[j].getTicketRate()) {
t[i] = t[j];
t[j] = temp;
return t[1];
class Theatre{
String theatreName;
double ticketRate;
[Link] = theatreId;
[Link] = theatreName;
[Link] = seatCapacity;
[Link] = ticketRate;
[Link] = theatreRating;
int getTheatreId() {
return theatreId;
String getTheatreName() {
return theatreName;
int getSeatCapacity() {
return seatCapacity;
double getTicketRate() {
return ticketRate;
int getTheatreRating() {
return theatreRating;
Q9:-
import [Link].*;
int soapId;
String soapName;
String brand;
double price;
boolean isGlycerin;
for(int i=0;i<[Link];i++) {
soapId = [Link]();[Link]();
soapName = [Link]();
brand = [Link]();
price = [Link]();
isGlycerin = [Link]();
[Link]();
if(sp == null)
else {
[Link]([Link]()+"#"+[Link]()+"#"+[Link]()+"#"+[Link]());
for(int i=0;i<[Link];i++) {
[Link](ss[i].getSoapId()+"-"+ss[i].getSoapName()+"-
"+ss[i].getPrice());
{
//method logic
double maxPrice = 0;
for(int i=0;i<[Link];i++) {
for(int j=0;j<[Link];j++) {
if(soapArr[i].getPrice()<=soapArr[i].getPrice()) {
soapArr[i] = soapArr[j];
soapArr[j] = temp;
for(int i=0;i<[Link];i++) {
if([Link](soapArr[i].getBrand()))
return soapArr[i];
return null;
//method logic
int count = 0;
for(int i=0;i<[Link];i++) {
count = 0;
for(int i=0;i<[Link];i++) {
soap[count++] = soapArr[i];
for(int i=0;i<[Link];i++) {
for(int j=0;j<[Link];j++) {
if(soap[i].getPrice()<=soap[i].getPrice()) {
soap[i] = soap[j];
soap[j] = temp;
return soap;
class Soap{
int soapId;
String soapName;
String brand;
double price;
boolean isGlycerin;
Soap(){}
Soap(int soapId, String soapName, String brand, double price, boolean isGlycerin){
[Link] = soapId;
[Link] = soapName;
[Link] = brand;
[Link] = price;
[Link] = isGlycerin;
int getSoapId() {
return soapId;
String getSoapName() {
return soapName;
String getBrand() {
return brand;
double getPrice() {
return price;
boolean getIsGlycerin() {
return isGlycerin;
Q10:-
import [Link].*;
int playerId;
String playerName;
String country;
int goals;
for(int i=0;i<[Link];i++) {
playerId = [Link]();[Link]();
playerName = [Link]();
country = [Link]();
goals = [Link]();
[Link]();
[Link]();
int totalGoals = findGoalsForCountry(football, getCountry1);
if(totalGoals == 0)
else
[Link](totalGoals);
if(fb == null)
else {
[Link](fb[i].getPlayerId()+"#"+fb[i].getPlayerName()+"#"+fb[i].getCountry()+"#"+fb[i
].getGoals());
int sum = 0;
if([Link](football[i].getCountry())) {
sum += football[i].getGoals();
return sum;
}
int count = 0;
if([Link](football[i].getCountry())) {
count++;
if(count == 0)
return null;
count = 0;
if([Link](football[i].getCountry())) {
fb[count++] = football[i];
fb[i] = fb[j];
fb[j] = temp;
}
}
return fb;
class Football{
int playerId;
String playerName;
String country;
int goals;
[Link] = playerId;
[Link] = playerName;
[Link] = country;
[Link] = goals;
int getPlayerId() {
return playerId;
String getPlayerName() {
return playerName;
String getCountry() {
return country;
}
int getGoals() {
return goals;
Q11:-
import [Link];
for(int i=0;i<4;i++)
int a=[Link]();[Link]();
String b=[Link]();
int c=[Link]();[Link]();
String d=[Link]();
int e=[Link]();[Link]();
ap[i]=new Amazonprime(a,b,c,d,e);
int par1=[Link]();[Link]();
int par=[Link]();[Link]();
String show=[Link]();
int remaindays=findRemainingSubcriptionDays(ap,par,par1);
if(remaindays!=0)
[Link](remaindays);
else
Amazonprime amp[]=findDetailsForGivenShow(ap,show);
if(amp!=null)
for(int i=0;i<[Link];i++)
if(amp[i]!=null){
[Link](amp[i].getPrimeId()+"$"+amp[i].getUserName()+"$"+amp[i].getViews());
else{
int remaindays=0;
for(int i=0;i<[Link];i++)
if(ap[i].getPrimeId()==par)
remaindays=((ap[i].getSubscribedPackage())-par1);
return remaindays;
int j=0;
for(int i=0;i<[Link];i++)
if(ap[i].getShowStreaming().equalsIgnoreCase(show))
amp[j++]=ap[i];
for(int i=0;i<j-1;i++)
for(int k=0;k<j-1-i;k++)
if(amp[k].getViews()>amp[k+1].getViews())
{
Amazonprime aja=amp[k];
amp[k]=amp[k+1];
amp[k+1]=aja;
if(j!=0)
return amp;
else{
return null;
class Amazonprime
int primeId;
String userName;
int subscribedPackage;
String showStreaming;
int views;
public Amazonprime(int primeId, String userName, int subscribedPackage, String showStreaming, int
views) {
[Link] = primeId;
[Link] = userName;
[Link] = subscribedPackage;
[Link] = showStreaming;
[Link] = views;
return primeId;
[Link] = primeId;
return userName;
[Link] = userName;
return subscribedPackage;
[Link] = subscribedPackage;
return showStreaming;
}
[Link] = showStreaming;
return views;
[Link] = views;
Q13:-
import [Link].*;
int playerId;
String skill;
String level;
int points;
playerId = [Link]();[Link]();
skill = [Link]();
level = [Link]();
points = [Link]();
[Link]();
[Link]();
if(getPoints == 0)
else
[Link](getPoints);
if(p == null)
[Link]("No player is available with specified level, skill and eligibility points");
else
[Link]([Link]());
int count = 0;
if([Link](players[i].getSkill()))
count += players[i].getPoints();
return count;
if([Link](players[i].getSkill()) &&
[Link](players[i].getLevel()) && players[i].getPoints()>=20)
return players[i];
return null;
class Player{
int playerId;
String skill;
String level;
int points;
Player(){}
[Link] = playerId;
[Link] = skill;
[Link] = level;
[Link] = points;
int getPlayerId() {
return playerId;
String getSkill() {
return skill;
String getLevel() {
return level;
int getPoints() {
return points;
Q14:-
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int contentId;
String content;
String category;
int likes;
int dislikes;
int shares;
contentId = [Link]();[Link]();
content = [Link]();
category = [Link]();
likes = [Link]();
dislikes = [Link]();
shares = [Link]();
[Link]();
[Link]();
if(newContent == null)
else
if(newString == null)
[Link]("Content not available for the category");
else
[Link]("Content Details:"+newString);
Content c = null;
int maxShare = 0;
for(int i=0;i<[Link];i++){
maxShare = contentArray[i].getShares();
c = contentArray[i];
return c;
String newString;
newString =
contentArray[i].getContentId()+"#"+contentArray[i].getContent()+"#"+contentArray[i].getCategory();
return newString;
return null;
}
class Content{
int contentId;
String content;
String category;
int likes;
int dislikes;
int shares;
Content(){}
Content(int contentId, String content, String category, int likes, int dislikes, int shares){
[Link] = contentId;
[Link] = content;
[Link] = category;
[Link] = likes;
[Link] = dislikes;
[Link] = shares;
int getContentId(){
return contentId;
String getContent(){
return content;
String getCategory(){
return category;
int getLikes(){
return likes;
int getDislikes(){
return dislikes;
int getShares(){
return shares;
Q15:-
import [Link].*;
String songName;
int duration;
double rating;
songName = [Link]();
duration = [Link]();[Link]();
artists = [Link]();
language = [Link]();
rating = [Link]();[Link]();
[Link]();
if(newSongs == null)
else
for(String i: newSongs)
[Link](i);
if(songs1 == null)
else
[Link]([Link]()+"\n"+[Link]());
if([Link]().equalsIgnoreCase(language))
[Link]([Link]());
[Link](newList, [Link]());
return arr;
if([Link]().equalsIgnoreCase(artist))
[Link](song);
return arr;
class Songs{
private String songName;
public Songs(String songName, int duration, String artists, String language, double rating){
[Link] = songName;
[Link] = duration;
[Link] = artists;
[Link] = language;
[Link] = rating;
return songName;
return duration;
return artists;
return language;
Q16:-
import [Link].*;
import [Link].*;
[Link]();
if(theatreCategory == null)
[Link](theatreCategory);
if(newTheatres == null)
else
[Link]([Link]());
if([Link]() == theatreId) {
return "Premium";
else
return "Normal";
return null;
[Link](theatre);
return newTheatres;
class Theatre{
public Theatre(int theatreId, String theatreName, int seatCapacity, double ticketRate, double
theatreRating, boolean balconyAvailable){
[Link] = theatreId;
[Link] = theatreName;
[Link] = seatCapacity;
[Link] = ticketRate;
[Link] = theatreRating;
[Link] = balconyAvailable;
return theatreId;
return theatreName;
return seatCapacity;
return ticketRate;
return theatreRating;
return balconyAvailable;
}
Q17:-
import [Link].*;
import [Link].*;
[Link]();
[Link]();
if(count > 0)
[Link](count);
else
else
[Link]([Link]()+"\n"+[Link]());
int count = 0;
count++;
return count;
if(![Link]())
[Link](employee);
return [Link]([Link]()-2);
class Employee{
public Employee(int employeeId, String name, String branch, double rating, boolean
companyTransport){
[Link] = employeeId;
[Link] = name;
[Link] = branch;
[Link] = rating;
[Link] = companyTransport;
return employeeId;
return name;
return branch;
}
public double getRating() {
return rating;
return companyTransport;
Q18:-
import [Link].*;
for(int i=0;i<[Link];i++) {
int id=[Link]();[Link]();
boolean avail=[Link]();[Link]();
String dp = [Link]();
if(totalFee == 0) {
else {
[Link](totalFee);
if(list == null) {
else {
double total=0;
for(Doctor i : d) {
if([Link]().equalsIgnoreCase(dept)) {
total += [Link]();
if(total == 0) {
return 0;
else {
return total;
}
}
for(Doctor i : d) {
if([Link]()) {
[Link](i);
if([Link]() == 0) {
return null;
else {
[Link](list,mylist);
return list;
class Doctor{
boolean available;
public Doctor(int id, String name, double fee, boolean available, String dept) {
[Link] = id;
[Link] = name;
[Link] = fee;
[Link] = available;
[Link] = dept;
return id;
return name;
return fee;
return available;
return dept;
Q19:-
import [Link].*;
class MyClass
{
int invoicenumber;
String fromcity;
String tocity;
String orderdate;
String deliverydate;
double price;
for(int i=0;i<[Link];i++)
invoicenumber=[Link]();
[Link]();
fromcity=[Link]();
tocity=[Link]();
orderdate=[Link]();
deliverydate=[Link]();
price=[Link]();
p[i]=new Package(invoicenumber,fromcity,tocity,orderdate,deliverydate,price);
[Link]();
String c1=[Link]();
String c2=[Link]();
[Link]();
int count=countOrdersDeliveredInAWeek(p,c1);
if(count!=0)
[Link](count);
else
Package pck=searchPackageByCity(p,c2);
if(pck!=null)
[Link]([Link]());
[Link]([Link]());
else
int count=0;
for(Package i:p)
if([Link]([Link]()))
String od=[Link]().substring(0,2);
String dd=[Link]().substring(0,2);
int od1=[Link](od);
int dd1=[Link](dd);
if(dd1-od1<7)
count++;
return count;
for(Package i:p)
if([Link]([Link]()))
[Link]([Link]());
if([Link]()!=0)
[Link](ar,[Link]());
double pr=[Link](1);
for(Package i:p)
{
if(pr==[Link]())
pck=i;
return pck;
return null;
class Package
Package()
Package(int invoicenumber, String fromcity, String tocity, String orderdate, String deliverydate, double
price)
[Link]=invoicenumber;
[Link]=fromcity;
[Link]=tocity;
[Link]=orderdate;
[Link]=deliverydate;
[Link]=price;
return invoicenumber;
return fromcity;
return tocity;
return orderdate;
return deliverydate;
{
return price;
import [Link].*;
import [Link].*;
int guestId;
String guestName;
String dateOfBooking;
int noOfRoomsBooked;
String mealOption;
double totalBill;
guestId = [Link]();[Link]();
guestName = [Link]();
dateOfBooking = [Link]();
noOfRoomsBooked = [Link]();[Link]();
mealOption = [Link]();
totalBill = [Link]();
[Link]();
String month = [Link]();
[Link]();
if(roomsBooked == 0)
else
[Link](roomsBooked);
if(resortGuest == null)
else
[Link]([Link]());
int countOfRoomsBooked = 0;
if([Link](month))
countOfRoomsBooked++;
return countOfRoomsBooked;
}
public static ResortGuest searchResortGuestByMealOpted(ResortGuest[] resortGuests, String
mealOpted){
if([Link]().equalsIgnoreCase(mealOpted)){
[Link](resortGuest);
return [Link]([Link]()-2);
class ResortGuest{
[Link] = guestId;
[Link] = guestName;
[Link] = dateOfBooking;
[Link] = noOfRoomsBooked;
[Link] = mealOption;
[Link] = totalBill;
return guestId;
return guestName;
return dateOfBooking;
return noOfRoomsBooked;
return mealOption;
return totalBill;
}
Q20:-
import [Link].*;
import [Link].*;
int voterId;
String voterName;
int voterAge;
boolean isVoteCasted;
String constituency;
voterId = [Link]();[Link]();
voterName = [Link]();
voterAge = [Link]();
isVoteCasted = [Link]();[Link]();
constituency = [Link]();
[Link]();
int totalVotesCasted = findTotalVotesCastedByConstituency(votes, checkConstituency);
if(totalVotesCasted == 0)
else
[Link](totalVotesCasted);
if(voterAgeArray == null)
else
[Link](voter);
int totalVotesCasted = 0;
if([Link]([Link]())){
if([Link]())
totalVotesCasted++;
return totalVotesCasted;
[Link]([Link]());
[Link](arrayOfVoterIdList);
return array;
class Vote{
public Vote(int voterId, String voterName, int voterAge, boolean isVoteCasted, String constituency){
[Link] = voterId;
[Link] = voterName;
[Link] = voterAge;
[Link] = isVoteCasted;
[Link] = constituency;
return voterName;
return voterAge;
return isVoteCasted;
return constituency;
Q21:-
import [Link].*;
int applianceId;
String applianceName;
String applianceCategory;
double applianceAmount;
boolean insurance;
Appliance[] appliances = new Appliance[4];
for(int i=0;i<[Link];i++){
applianceId = [Link]();[Link]();
applianceName = [Link]();
applianceCategory = [Link]();
applianceAmount = [Link]();
[Link]();
[Link](applianceAmount1);
double newApplianceAmount = 0;
for(int i=0;i<[Link];i++){
if(appliances[i].getApplianceId() == applianceId){
if(insurance == true){
newApplianceAmount = appliances[i].getApplianceAmount() +
((appliances[i].getApplianceAmount() * 20)/100);
appliances[i].setApplianceAmount(newApplianceAmount);
return newApplianceAmount;
for(int i=0;i<[Link];i++){
if([Link](appliances[i].getApplianceCategory())){
maxCost = appliances[i].getApplianceAmount();
appliances1 = appliances[i];
return appliances1;
}
class Appliance{
[Link] = applianceId;
[Link] = applianceName;
[Link] = applianceCategory;
[Link] = applianceAmount;
return applianceId;
return applianceCategory;
return applianceName;
[Link] = applianceAmount;
Q22:-
public class Solution{ //this program is executed in Onlinegdb, so class name is Main
int regNo;
String agencyName;
String packageType;
int price;
regNo = [Link]();[Link]();
agencyName = [Link]();
packageType = [Link]();
price = [Link]();
flightFacility = [Link]();
}
int getRegNo = [Link]();[Link](); //constraint 1 from question
if(travelAgencies == null)
else
[Link]([Link]()+"\n"+[Link]());
for(int i=1;i<[Link];i++){
for(int i=0;i<[Link];i++){
if(agencies[i].getRegNo()==regNo &&
[Link](agencies[i].getPackageType())){ //condition 2 checking
class TravelAgencies{
int regNo;
String agencyName;
String packageType;
int price;
boolean flightFacility;
TravelAgencies(int regNo, String agencyName, String packageType, int price, boolean flightFacility){
//parameterized constructor
super();
[Link] = regNo;
[Link] = agencyName;
[Link] = packageType;
[Link] = price;
[Link] = flightFacility;
return regNo;
return agencyName;
return packageType;
return price;
return flightFacility;
class Item{
int itemId;
String itemName;
String itemType;
double itemPrice;
[Link] = itemId;
[Link] = itemName;
[Link] = itemType;
[Link] = itemPrice;
int getItemId(){
return itemId;
String getItemName(){
return itemName;
String getItemType(){
return itemType;
double getItemPrice(){
return itemPrice;
int itemId;
String itemName;
String itemType;
double itemPrice;
for(int i=0;i<[Link];i++){
itemId = [Link]();[Link]();
itemName = [Link]();
itemType = [Link]();
itemPrice = [Link]();
[Link]();
[Link]();
if(avgItemPrice > 0)
[Link](avgItemPrice);
else
else{
for(int i=0;i<[Link];i++){
[Link](items[i].getItemId());
double sum = 0;
for(int i=0;i<[Link];i++){
if([Link](item[i].getItemType())) {
sum += item[i].getItemPrice();
count++;
avgPrice = (int)(sum/count);
return avgPrice;
int count = 0;
for(int i=0;i<[Link];i++){
if([Link](item[i].getItemName()))
count++;
}
count = 0;
for(int i=0;i<[Link];i++){
if([Link](item[i].getItemName())){
items[count++] = item[i];
for(int i=0;i<[Link];i++){
for(int j=i+1;j<[Link];j++){
items[i] = items[j];
items[j] = temp;
return items;
Q24:-
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int songId;
String title;
String artist;
int rating;
for(int i=0;i<5;i++){
songId = [Link]();[Link]();
title = [Link]();
artist = [Link]();
rating = [Link]();
[Link]();
String artist1 = [Link]();
[Link]();
if(findAvg == 0)
else
[Link](findAvg);
if(newSong == null)
else{
for(int i=0;i<[Link];i++){
[Link](newSong[i].getSongId());
//method logic
int avgRating = 0, count = 0;
for(int i=0;i<[Link];i++){
if([Link](song[i].getArtist())){
avgRating += song[i].getRating();
count++;
//method logic
int count = 0;
for(int i=0;i<[Link];i++){
if([Link](song[i].getArtist()))
count++;
if(count == 0)
return null;
count = 0;
for(int i=0;i<[Link];i++){
if([Link](song[i].getArtist())){
s[count++] = song[i];
for(int i=0;i<[Link];i++){
for(int j=i+1;j<[Link];j++){
if(s[i].getSongId()<=s[j].getSongId()){
s[i] = s[j];
s[j] = temp;
return s;
class Song
int songId;
String title;
String artist;
int rating;
[Link] = songId;
[Link] = title;
[Link] = artist;
[Link] = rating;
int getSongId(){
return songId;
String getTitle(){
return title;
String getArtist(){
return artist;
int getRating(){
return rating;
Q25:-
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int playerId;
String playerName;
playerId = [Link]();[Link]();
playerName = [Link]();
score1 = [Link]();
score2 = [Link]();
score3 = [Link]();
if(maxScore != 0)
[Link](maxScore);
else
[Link]("No Hundreds Scored in Tournament");
[Link]([Link]()+"#"+[Link]());
//method logic
int count = 0;
if(players[i].getScore1()>=100)count++;
if(players[i].getScore2()>=100)count++;
if(players[i].getScore3()>=100)count++;
return count;
//method logic
player = players[0];
for(int i=1;i<[Link];i++){
if(newScore>=maxScore){
maxScore = newScore;
player = players[i];
return player;
class Player
int playerId;
String playerName;
Player(){}
Player(int playerId, String playerName, int score1, int score2, int score3){
[Link] = playerId;
[Link] = playerName;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
int getPlayerId(){
return playerId;
}
String getPlayerName(){
return playerName;
int getScore1(){
return score1;
int getScore2(){
return score2;
int getScore3(){
return score3;
Q26:-
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
//Creating variables
//creating a scanner 's' object to read values from the keyboard and the syntax is shown below
iMEICode = [Link]();
isSingleSIM = [Link]();[Link]();
//here we need to use one more [Link]() statement inorder to read string correctly
processor = [Link]();
price = [Link]();[Link]();
manufacturer = [Link]();
//reading discountPercentage
//reading manufacturerName
[Link](countOfValidIMEIMobiles);
else
[Link]([Link]()+"@"+[Link]());
//count variable to count number of Mobiles which have 15 digit IMEI code
int count = 0;
double newPrice;
for(int i=0;i<[Link];i++){
if([Link](listOfMobiles[i].getManufacturer())){
//setting newPrice for the mobile object which matches with manufacturer
listOfMobiles[i].setPrice(newPrice);
mobile = listOfMobiles[i];
return null;
}
class Mobile{
String iMEICode;
boolean isSingleSIM;
String processor;
double price;
String manufacturer;
Mobile(){}
Mobile(String iMEICode, boolean isSingleSIM, String processor, double price, String manufacturer){
//if we have same variable names, we should use this keyword to store valules
[Link] = iMEICode;
[Link] = isSingleSIM;
[Link] = processor;
[Link] = price;
[Link] = manufacturer;
String getIMEICode(){
return iMEICode;
boolean getIsSingleSIM(){
return isSingleSIM;
}
String getProcessor(){
return processor;
void setPrice(double price){ //we need a setter to assign new price to object
[Link] = price;
double getPrice(){
return price;
String getManufacturer(){
return manufacturer;
Q27:-
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
{
//code to read values
for(int i=0;i<[Link];i++){
vesselId = [Link]();[Link]();
vesselName = [Link]();
noOfVoyagesPlanned = [Link]();
noOfVoyagesCompleted = [Link]();[Link]();
purpose = [Link]();
if(avgOfVoyagesCompleted>0)
[Link](avgOfVoyagesCompleted);
else
else
[Link]([Link]()+"%"+[Link]());
//method logic
for(int i=0;i<[Link];i++){
avg += nvArray[i].getNoOfVoyagesCompleted();
count++;
if(avg == 0)
return 0;
else
return avg/count;
{
//method logic
for(int i=0;i<[Link];i++){
if([Link](nvArray[i].getPurpose())){
int percentage =
(nvArray[i].getNoOfVoyagesCompleted()*100)/nvArray[i].getNoOfVoyagesPlanned(); //finding
percentage
if(percentage==100) nvArray[i].setClassification("Star");
else
nvArray[i].setClassification("Striver");
nv = nvArray[i];
return nv;
return null;
class NavalVessel
NavalVessel(){}
NavalVessel(int vesselId, String vesselName, int noOfVoyagesPlanned, int noOfVoyagesCompleted,
String purpose){
super();
[Link] = vesselId;
[Link] = vesselName;
[Link] = noOfVoyagesPlanned;
[Link] = noOfVoyagesCompleted;
[Link] = purpose;
int getVesselId(){
return vesselId;
String getVesselName(){
return vesselName;
int getNoOfVoyagesPlanned(){
return noOfVoyagesPlanned;
int getNoOfVoyagesCompleted(){
return noOfVoyagesCompleted;
String getPurpose(){
return purpose;
[Link] = classification;
}
String getClassification(){
return classification;
Q28:-
import [Link].*;
class Main{
String director;
for(int i=0;i<4;i++){
movieId = [Link]();[Link]();
director = [Link]();
rating = [Link]();
budget = [Link]();
[Link]();
[Link](findAvg);
else
[Link]("Sorry - The given director has not directed any movie yet");
if(m == null)
else
[Link]([Link]());
for(int i=0;i<4;i++){
count++;
if(sum>0)
else
return 0;
for(int i=0;i<4;i++){
if(movies[i].getBudget()%movies[i].getRating() == 0){
m = movies[i];
return m;
return null;
class Movie{
int movieId,rating,budget;
String director;
Movie(){}
super();
[Link] = movieId;
[Link] = director;
[Link] = rating;
[Link] = budget;
int getMovieId(){
return movieId;
String getDirector(){
return director;
int getRating(){
return rating;
int getBudget(){
return budget;