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