Pra Solution
Pra Solution
import java.util.*;
class Employee{
int id;
String name;
double salary;
// if(salary<1000){
// throw new InvalidSalaryException("Salary is greater not greater than
1000");
// }
this.salary=salary;
}
// System.out.println("Hello World");
Scanner sc = new Scanner(System.in);
try{
for(int i=0;i<3;i++){
int id=sc.nextInt();sc.nextLine();
IdError(id);
String name = sc.next();
NameError(name);
Double salary = sc.nextDouble();
SalaryError(salary);
employees[i] = new Employee(id,name,salary);
}
}catch(InvalidIdException | InvalidSalaryException | InvalidNameException
e){
e.printStackTrace();
}
}
--------------------------------------------------------------
PRA -1:
import java.util.*;
class course{
int id;
String name;
String admin;
int quiz;
int handson;
public course(int id, String name, String admin, int quiz, int handson){
this.id = id;
this.name = name;
this.admin =admin;
this.quiz = quiz;
this.handson = handson;
}
}
public class Main {
}
}
if (result.length > 0)
{
return result;
}
else
{
return null;
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
}
}
--------------------------------------------------------------
PRA-2:
import java.util.*;
class footwear{
int id ;
String name;
String type;
int price;
public footwear(int id, String name, String type, int price) {
super();
this.id = id;
this.name = name;
this.type = type;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
if(result.length>0){
return result[1];
}
else{
return null;
}
int n=sc.nextInt();
footwear[] ft= new footwear[n];
for(int i=0;i<n;i++){
int id=sc.nextInt();sc.nextLine();
String name=sc.nextLine();
String type=sc.nextLine();
int price=sc.nextInt();sc.nextLine();
ft[i]=new footwear(id,name,type,price);
}
String ftType=sc.nextLine();
String ftName=sc.nextLine();
footwear obj=secondHighestPrice(ft,ftName);
if(obj!=null){
System.out.println(obj.getId());
System.out.println(obj.getName());
System.out.println(obj.getPrice());
}else{
System.out.println("Brand not available.");
}
----------------------------------------------------------------
PRA-3:
import java.util.*;
class student{
int roll;
String name;
String branch;
double score;
boolean dayScholar;
public student(int roll, String name, String branch, double score, boolean
dayScholar) {
super();
this.roll = roll;
this.name = name;
this.branch = branch;
this.score = score;
this.dayScholar = dayScholar;
}
public int getRoll() {
return roll;
}
public void setRoll(int roll) {
this.roll = roll;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public boolean isDayScholar() {
return dayScholar;
}
public void setDayScholar(boolean dayScholar) {
this.dayScholar = dayScholar;
}
for(int i=0;i<n;i++){
int roll=sc.nextInt();sc.nextLine();
String name = sc.nextLine();
String branch=sc.nextLine();
double score = sc.nextDouble(); sc.nextLine();
boolean dayScholar=sc.nextBoolean();
}
int ans=countOf(st);
if(ans!=0){
System.out.println(ans);
}else{
System.out.println("their no such dayScholar");
}
student obj=secondHighest(st);
if(obj!=null){
System.out.println(obj.getRoll()+"#"+obj.getName()
+"#"+obj.getScore());
}
else{
System.out.println();
}
---------------------------------------------------------------
JDBC :
package com.App;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con=DriverManager.getConnection("jdbc:derby:D:\\\\Users\\\\
2791529\\\\MyDB;create=true");
String cr="create table e23(id int,name varchar(40),salary
double,phone int)";
crt=con.prepareStatement(cr);
-----------------------------------------------------------------
PRA-4:
import java.util.*;
class college {
int id;
String name;
int contactNo;
String address;
int pinCode;
public college(int id, String name, int contactNo, String address, int
pinCode) {
super();
this.id = id;
this.name = name;
this.contactNo = contactNo;
this.address = address;
this.pinCode = pinCode;
}
for(int i=0;i<cl.length;i++){
if(cl[i].getPinCode()>max){
max=cl[i].getPinCode();
}
}
for(int i=0;i<cl.length;i++){
if(cl[i].getPinCode()==max){
return cl[i];
}
}
// if(temp==0){
// return null;
// }
// else{
// return cl[temp];
// }
return null;
}
for(int i=0;i<n;i++){
int id=sc.nextInt();sc.nextLine();
String name=sc.nextLine();
int contactNo=sc.nextInt();sc.nextLine();
String address=sc.nextLine();
int pinCode=sc.nextInt();sc.nextLine();
college obj=collegeMaxPin(cl);
if(obj!= null){
System.out.println(obj.getId());
System.out.println(obj.getName());
System.out.println(obj.getPinCode());
System.out.println(obj.getAddress());
System.out.println(obj.getContactNo());
}else{
System.out.println("not found");
}
String add=sc.nextLine();
college obj1=serachAddress(cl,add);
if(obj1!=null){
System.out.println(obj.getId());
System.out.println(obj.getName());
System.out.println(obj.getContactNo());
System.out.println(obj.getAddress());
System.out.println(obj.getPinCode());
}else{
System.out.println("not found");
}
}
}
----------------------------------------------------------------
PRA-5 :
import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class Motel {
int id;
String name;
String date;
int roomBooked;
String cabFacility;
double bill;
public Motel(int id, String name, String date, int roomBooked, String
cabFacility, double bill) {
super();
this.id = id;
this.name = name;
this.date = date;
this.roomBooked = roomBooked;
this.cabFacility = cabFacility;
this.bill = bill;
}
int count=0;
for(int i=0;i<ml.length;i++){
if(ml[i].getCabFacility().equalsIgnoreCase(add) &&
ml[i].getRoomBooked() >5){
count=ml[i].getRoomBooked();
}
}
if(count!=0){
return count;
}else{
return 0;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
int n =sc.nextInt();
Motel[] ml=new Motel[n];
for(int i=0;i<n;i++){
int id=sc.nextInt();sc.nextLine();
String name=sc.nextLine();
String dateStr=sc.next();
try {
Date date = sdf.parse(dateStr);
// System.out.println("Input date: " + sdf.format(date));
} catch (ParseException e) {
System.out.println("Invalid date format");
}
int roomBooked=sc.nextInt();sc.nextLine();
String cabFacility=sc.nextLine();
double bill=sc.nextDouble();sc.nextLine();
String add=sc.nextLine();
int obj1=totalNoOfRoomBooked(ml,add);
if(obj1!=0){
System.out.println(obj1);
}else{
System.out.println("no such room booked");
}
}
}
------------------------------------------------------------------
PRA-6:
import java.util.*;
class RRT {
int no;
String raisedBy;
String assignTo;
int priority;
String project;
public RRT(int no, String raisedBy, String assignTo, int priority, String
project) {
super();
this.no = no;
this.raisedBy = raisedBy;
this.assignTo = assignTo;
this.priority = priority;
this.project = project;
}
}
public class Main
{
for(int i=0;i<result.length;i++){
for(int j=i+1;j<result.length;j++){
if(result[i].getPriority()>result[j].getPriority()){
temp=result[i];
result[i]=result[j];
result[j]=temp;
}
}
}
if(result.length!=0){
return result[0];
}else{
return null;
}
int n =sc.nextInt();
RRT[] rt=new RRT[n];
for(int i=0;i<n;i++){
int no=sc.nextInt();sc.nextLine();
String raisedBy=sc.nextLine();
String assignTo=sc.nextLine();
int priority=sc.nextInt();sc.nextLine();
String project=sc.nextLine();
String proj=sc.nextLine();
RRT obj=withHighestPriorityTicket(rt,proj);
if(obj!=null){
System.out.println(obj.getNo());
System.out.println(obj.getRaisedBy());
System.out.println(obj.getAssignTo());
}else{
System.out.println("no");
}
}
}
---------------------------------------------------------------
PRA-7:
---------------------------------------------------------------
PRA-8:
import java.util.*;
class hotel{
int id;
String name;
String date;
int no;
String wifi;
double bill;
public hotel(int id, String name, String date, int no, String wifi, double
bill){
this.id = id;
this.name = name;
this.date = date;
this.no = no;
this.wifi = wifi;
this.bill = bill;
}
}
else{
return count;
}
}
------------------------------------------------------------
------------------------------------------------------------
PRA 11:
import java.util.*;
class player{
int id;
String skill;
String level;
int points;
}
public int getId() {
return id;
}
}
public class Main {
int sum = 0;
}
if (sum!=0){
return sum;
}
else{
return 0;
}
String s = sc.nextLine();
String l = sc.nextLine();
String st = sc.nextLine();
if (ans2 == null){
System.out.println("NO");
}
else{
System.out.println(ans2.getId());
}
}
}
-----------------------------------------------------------
// package ilp;
import java.util.*;
class empolyee {
int id;
String name;
String designation;
double salary;
class company{
int cName;
empolyee [] em;
int num;
public company(int cName, empolyee[] em, int num) {
super();
this.cName = cName;
this.em = em;
this.num = num;
}
public int getcName() {
return cName;
}
public void setcName(int cName) {
this.cName = cName;
}
public empolyee[] getEm() {
return em;
}
public void setEm(empolyee[] em) {
this.em = em;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
em[i]=new empolyee(id,name,designation,salary);
}
// company c=new company(companyName,em,n);
// System.out.println(c.getAverageSalary(em));
// System.out.println(" ");
// System.out.println(c.getMaxSalary(em));
String d=sc.nextLine();
empolyee[] obj=company.getEmployeeByDesignation(em,d);
if(obj!=null){
for(int i=0;i<obj.length;i++){
System.out.println("ID :"+obj[i].getId()
+"NAME :"+obj[i].getName()+"designation :"+obj[i].getDesignation());
}
}else{
System.out.println("no");
}
}
}
--------------------------------------------------------------
ArrayList question :(Alosh):
1:
package list;
import java.util.*;
class manfacture{
int id;
String name;
int no;
ArrayList<String> products = new ArrayList<String>();
ArrayList<Integer> prices = new ArrayList<Integer>();
}
public class Manfacture {
public double avgPriceOfProductByManfacture(ArrayList<manfacture> mf, int
mid){
int sum=0;
int count=0;
double avg=0;
for(manfacture m: mf){
if(m.getId()==mid){
for(int price:m.getPrices()){
sum=sum+price;
count++;
}
}
}
if(sum>0){
avg=sum/count;
return avg;
}else{
return 0;
}
}
----------------------------------------------------------
2:
satyam :
package list;
import java.util.*;
class Book{
int bId;
String title;
int publishedYear;
class Author{
int auId;
String auName;
String nationality;
ArrayList<Book> book=new ArrayList<Book>();
}
public class libary {
}
}
}
ArrayList<Integer> sortedList=new ArrayList<>(result);
Collections.sort(sortedList);
if(sortedList.size()>0){
return sortedList;
}else{
return null;
}
// Collections.sort(result);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();sc.nextLine();
ArrayList<Author> authors=new ArrayList<Author>();
for(int i=0;i<n;i++){
int auId=sc.nextInt();sc.nextLine();
String auName=sc.nextLine();
String nationality=sc.nextLine();
int num=sc.nextInt();sc.nextLine();
ArrayList<Book> books=new ArrayList<>();
for(int j=0;j<num;j++){
int bId=sc.nextInt();sc.nextLine();
String title=sc.nextLine();
int publishedYear=sc.nextInt();sc.nextLine();
Book ans=new Book(bId,title,publishedYear);
books.add(ans);
}
Author aut=new Author(auId,auName,nationality,books);
}
libary l=new libary();
int authorId=sc.nextInt();sc.nextLine();
ArrayList<Integer> ans=l.getUniquePublishedYear(authors, authorId);
if(ans!=null){
for(int i=0;i<ans.size();i++){
System.out.println(ans.get(i));
}
}
}
}
--------------------------------------------------------------
yatish:
import java.util.*;
class Book{
int bId;
String title;
int publishedYear;
class Author{
int auId;
String auName;
String nationality;
ArrayList<Book> book=new ArrayList<Book>();
}
public class Main {
public static void main(String[] args){
int auId=sc.nextInt();
sc.nextLine();
String auName=sc.nextLine();
String nationality=sc.nextLine();
int x = sc.nextInt();
ArrayList<Book> bk = new ArrayList<>();
for (int j = 0; j < x; j++){
if(ans2 != null){
for (int j = 0; j < ans2.size(); j++){
System.out.println(ans2.get(j));
}
}
else{
System.out.println("NO");
}
if (sortedlist.size() != 0){
return sortedlist;
}
else{
return null;
}
}
static ArrayList<String> getBooksByNationality(ArrayList<Author> authors,
String nation){
ArrayList<String> result= new ArrayList<>();
for (Author au: authors){
if(au.getNationality().equalsIgnoreCase(nation)){
for(Book y:au.getBook()){
result.add(y.getTitle());
}
}
}
if(result.size()!=0){
return result;
}else{
return null;
}
}
----------------------------------------------------------