Kytcs.Blogspot.com: knownyourtcsanswer
Showing posts with label knownyourtcsanswer. Show all posts
Showing posts with label knownyourtcsanswer. Show all posts

PYthon OPA 12 may

 class ParkedVehicle:

    def __init__(self,vs,fw,pf,vp):
        self.vehicleSeq=vs
        self.fourWheeler=fw
        self.parkedFor=pf
        self.valetParking=vp
        self.parkedStatus="Parked"

class ParkingLot:
 
    def __init__(self,pv):
        self.parkedVehicle=pv
 
    def updateParkedStatus(self,lot_no):
 
        obj=self.parkedVehicle.get(lot_no,None)
        if obj==None:
            return None
        else :
            obj.parkedStatus="Cleared"
            return lot_no
 
 
 
    def getParkingCharges(self,lot_no):
        parkingCharges=0
 
        obj=self.parkedVehicle.get(lot_no,None)
 
        if obj==None:
            return None
        else:
            if obj.fourWheeler=="Yes":
                parkingCharges+=obj.parkedFor*50
            else:
                parkingCharges+=obj.parkedFor*30
 
            if obj.valetParking=="Yes":
                parkingCharges+=10
 
            return parkingCharges
 
 
 
 
N=int(input())
 
qewdkl={}
for dog in range(N):
 
    vs=int(input())
    fw=input()
    parkedfor=float(input())
    vp=input()
    lotno=int(input())
 
    q[lotno]=ParkedVehicle(vs,fw,parkedfor,vp)
 
asd=ParkingLot(q)
 
lot=int(input())
 
 
tef=asd.updateParkedStatus(lot)
 
asd=asd.getParkingCharges(lot)
 
if tef==None:
    print ("Lot Number Invalid")
else:
    print(tef,"Cleared")
 
if asd==None:
    print("Lot Number Invalid")
else:
    print(asd)

Java Movie Management

Welcome to the my blog



Java Movie Management








import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
   public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        Movie[] mv = new Movie[4];
        for(int i=0;i<4;i++)
        {
            int a = sc.nextInt();sc.nextLine();
            String b = sc.nextLine();
            int c = sc.nextInt();
            int d = sc.nextInt();
            mv[i] = new Movie(a,b,c,d);
        }
        sc.nextLine();
        String nm = sc.nextLine();
        int um = sc.nextInt();
        int dm = sc.nextInt();
        int res = findAvgBudgetByDirector(mv, nm);
        if (res>0)
        System.out.println(res);
        else
        System.out.println("Sorry - The given director has not yet directed any movie");
        Movie temp = getMovieByRatingBudget(mv, um, dm);
        if(temp == null)
        System.out.println("Sorry - No movie is available with the specified rating and budget requirement");
        else
        System.out.println(temp.id);

    }

    public static int findAvgBudgetByDirector (Movie[] mv, String nm)
      {
          //method logic
          int avg,s=0,j=0;
          for(int i=0;i<4;i++)
          {              
              if(nm.equalsIgnoreCase(mv[i].dt))
              {
                  s = s+mv[i].bt;
                  j++;
              }
          }
              if(j>0)
              {
                  avg = s/j;
                  return avg;
              }          
              else 
              return 0;
      }

    public static Movie getMovieByRatingBudget(Movie[] mv, int rating, int budget)
      {
          //method logic
          Movie temp = new Movie();
          for(int i=0;i<4;i++)
          {
              if((rating == mv[i].rt) && (budget == mv[i].bt) && (mv[i].bt % mv[i].rt == 0))
              {
                  temp.id = mv[i].id;
                  return temp;
              }
          }
          return null;   
          
      }
}

class Movie
{
    //code to build Movie class
    int id,rt,bt;
    String dt;
    Movie()
    {

    }
    Movie(int id, String dt, int rt, int bt)
    {
        this.id = id;
        this.dt = dt;
        this.rt = rt;
        this.bt = bt;
    }
}

JAVA Proctored Assessment

java pa 13 feb


Java Proctored Assessment Programming solution 13th  February



Question 1.

Write a Program to print smallest vowel in the given line…(Ascii Values)

input:
matrix

output:
a

Solution:


import java.lang.*;
import java.util.*;
import java.io.*;
import java.math.*;

public class Main
{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        s=s.toLowerCase();
        int n=s.length();
        int c=0;
        char[] ch=s.toCharArray();
        for(int i=0;i<n;i++)
        {
            if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' || s.charAt(i)=='o' || s.charAt(i)=='u')
            {
                c++;
            }
        }
        char[] c1=new char[c];
        int k=0;
        for(int i=0;i<n;i++)
        {
            if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' || s.charAt(i)=='o' || s.charAt(i)=='u')
            {
                c1[k++]=ch[i];
            }
        }
        Arrays.sort(c1);
        System.out.println(c1[0]);
       
    }
}

Question 2.


Create a Sim Class with following Attributes
int simId;
String customerName;
double balance;
double ratePerSecond;
String circle;


create a public Class Solution in which take input of 5 object and then take 2 input (circle1, circle2) for circle of matches as circle1 and choose only those objects which are match with circle1.

Create a method named as transferCircle() and passed sim object and circle1, circle2 as parameter and arrange sim object in descending order as per ratePerSecond


Print the output as simId, customerName, circle, ratePerSecond.

Input:


1
raju
130
1.32
mum
2
sachin
120
2.26
ahd
3
ram
200
2.54
kol
4
shubham
640
3.21
ahd
5
kalpesh
150
1.8
ahd
ahd
kol


Output:


4 shubham kol 3.21
2 sachin kol 2.26
5 kalpesh kol 1.8

Solution:


import java.util.Scanner;
public class SimSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Sim1[] sim = new Sim1[5];
for (int i = 0; i < sim.length; i++) {
int simId = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
double balance = sc.nextDouble();
double ratePersecond = sc.nextDouble();
sc.nextLine();
String circle = sc.nextLine();
sim[i] = new Sim1(simId, name, balance,
ratePersecond, circle);
}
String circle1 = sc.nextLine();
String circle2 = sc.nextLine();
Sim1[] result = transferCircle(sim, circle1, circle2);
for (int i = 0; i < result.length; i++) {
System.out.println(result[i].getSimId() + " " +
result[i].getName() + " " + result[i].getCircle() + " "
+ result[i].getRatePersecond());
}
sc.close();
}
public static Sim1[] transferCircle(Sim1[] sim, String
circle1, String circle2) {
Sim1[] temp;
int j = 0;
for (int i = 0; i < sim.length; i++) {
if (sim[i].getCircle().equals(circle1)) {
j++;
}
}
temp = new Sim1[j];
j = 0;
for (int i = 0; i < sim.length; i++) {
if (sim[i].getCircle().equals(circle1)) {
temp[j] = sim[i];
temp[j++].setCircle(circle2);
}
}
for (int i = 0; i < j - 1; i++) {
for (int k = 0; k < j - 1; k++) {
if (temp[k].getRatePersecond() < temp[k +
1].getRatePersecond()) {
Sim1 a = temp[k];
temp[k] = temp[k + 1];
temp[k + 1] = a;
}
}
}
return temp;
}
}
class Sim1 {
private int simId;
private String name;
private double balance;
private double ratePersecond;
private String circle;
public Sim1(int simId, String name, double balance, double
ratePersecond, String circle) {
this.simId = simId;
this.name = name;
this.balance = balance;
this.ratePersecond = ratePersecond;
this.circle = circle;
}
public int getSimId() {
return simId;
}
public void setSimId(int simId) {
this.simId = simId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getRatePersecond() {
return ratePersecond;
}
public void setRatePersecond(double ratePersecond) {
this.ratePersecond = ratePersecond;
}
public String getCircle() {
return circle;
}
public void setCircle(String circle) {
this.circle = circle;
}
}

PL SQL Blocks


PL SQL Blocks Answer

1.What is the clause we need to add in function body to return variable?
Answer: Return varchar2


2.What is the clause we need to add in function header to return variable?
Answer: Return varchar2

3.Function can be used in select statments only if function not having any dml operation?
Answer: True

4.Which of the folling is the examples of named book?
Answer: All of the above

5.Function can return more than one value.
answer: False.

6.Cursor should be declared in begin block in pl/sql
Answer: False.

7.Which of the folling is not a cursor attribute?
Answer: None of the above

8.what is the exit condition we should include in pl\sql block to terminate the loop?
Answer: exit when SQL%NOTFOUND.

9.   .......... is the pointer to context are  which is used to process the sql result set in pl\sql?
answer Cursor
10.  In pl\sql, you can refer to the most recent implicit cursor as sql cursor
Answer: True


SQL HAND ON 5


select distinct Item_Name from Items where Item_id not in(select distinct Item_Id from orders);


SQL HAND ON 4


SQL HAND ON 4

select distinct Dept_name,Emp_skill from Departments,Employees where Dept_ID=Emp_Dept_Id
order by Dept_Name desc,Emp_Skill;


SQL HAND ON 3





SQL HAND ON 3

select distinct Dept_name from Departments,Employees where Dept_ID=Emp_Dept_Id and Dept_name not in (select distinct Dept_name from Departments,Employees where Dept_id=Emp_Dept_Id and Emp_Skill like'programmer');

SQL HAND ON 2


SQL HAND ON 2



select Dept_Id,Dept_Name from Department where Dept_Location='Ground Floor';

SQL HAND ON 1



SQL HAND ON 1




select Departments.deptName,COUNT(Employees.eDeptId) From departments LEFT Join Employees on Departments.deptId=Employees.eDeptId Group By Departments.deptId,Departments.deptName Order by count(Employees.eDeptId) Desc, departments.deptName;

Java Arrays - Hands on 1 Problem 2:


Java Arrays - Hands on 1
Problem 2:
_____________________________________


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner scn=new Scanner(System.in);
Book[] booksArray=new Book[4];
Book[] sorted=new Book[4];
for(int i=0;i<booksArray.length;i++)
{
booksArray[i]=new Book();
sorted[i]=new Book();

}
for(int i=0;i<booksArray.length;i++)
{
booksArray[i].id=scn.nextInt();
booksArray[i].title=scn.next();
booksArray[i].author=scn.next();
booksArray[i].price=scn.nextDouble();
}
sorted=sortBooksByPrice(booksArray);
for(int i=0;i<sorted.length;i++)
{
System.out.println(sorted[i].id+" "+sorted[i].title+" "+sorted[i].author+"
"+sorted[i].price);
}
}
public static Book[] sortBooksByPrice(Book[]booksArray){
int n=booksArray.length;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(booksArray[j].price>booksArray[j+1].price)
{
Book temp=booksArray[j];
booksArray[j]=booksArray[j+1];
booksArray[j+1]=temp;
}
}
}
return booksArray;
}
}
class Book
{
int id;
String title,author;
double price;
}

Followers

Ad Space