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

DOTNET

Welcome to the my blog




            Course        
             
                HTML-5  
 
         
                  CSS

              javascript  

                 OpsRio


javascript


Welcome to the my blog






































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;
    }
}

Unix code

Welcome to the my blog
OPA -JAVA UNIX Student details


#!/bin/bash
read 
awk 'BEGIN{FS=",";t=0}
 {
a[t]=$1;
b[t]=$3+$4;
c[t]=$2;
 
t=t+1
 
}
END
{
for(i=0;i<t;++i)
{
   ma=0;
    pos=i;
    for(j=0;j<t;++j)
    {
        if (b[j]>ma)
        {
            ma=b[j];
            pos=j;
        }
    }
    if (b[pos]>99)
    print a[pos],c[pos];
    b[pos]=-1;
 
}
}
'

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;
}

Java Arrays - Hands on 1 Problem 1

Java Arrays - Hands on 1
Problem 1:


_______________________________________________________________

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 {
Scanner sc=new Scanner(System.in);
Document[] docsArray=new Document[4];
Document[] res=new Document[4];
for(int i=0;i<docsArray.length;i++)
{
docsArray[i]=new Document();
res[i]=new Document();
}
for(int i=0;i<docsArray.length;i++)
{
docsArray[i].id=sc.nextInt();
docsArray[i].title=sc.next();
docsArray[i].folderName=sc.next();
docsArray[i].pages=scn.nextInt();
}
res= docsWithOddPages(docsArray);
for(int i=0;i<res.length;i++)
{
if(res[i].title!=null)
System.out.println(res[i].id+" "+res[i].title+" "+res[i].folderName+" "+res[i].pages);
}
}
public static Document[] docsWithOddPages(Document[]docsArray){
Document[] oddDocs=new Document[4];
for(int i=0;i<docsArray.length;i++)
{

oddDocs[i]=new Document();
}
int k=0;
for(int i=0;i<docsArray.length;i++)
{
if(docsArray[i].pages%2!=0)
{
oddDocs[k++]=docsArray[i];
}
}
return oddDocs;
}
}
class Document
{
int id,pages;
String title,folderName;
}

JAVA array hands on 2 problem 2

JAVA handns on 2 problem 2

Problem 2:

_________________________________
import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

import java.util.*;

public class Solution {

public static void main(String args[] ) throws Exception {



Scanner scn=new Scanner(System.in);

Book[] booksArray=new Book[4];

Book[] res=new Book[4];

for(int i=0;i<booksArray.length;i++)

{
booksArray[i]=new Book();
res[i]=new Book();
}
for(int i = 0;i<4;i++)
{
booksArray[i].id = scn.nextInt();scn.nextLine();
booksArray[i].title = scn.nextLine();
booksArray[i].author = scn.nextLine();
booksArray[i].price = scn.nextDouble();
}
String value=scn.next();
res=searchTitle(value, booksArray);
int [] matchedId=new int[4];
int j=0;
for(int i=0;i<res.length;i++)

{

if(res[i].id!=0)



{

matchedId[j++]=res[i].id;

}

}

Arrays.sort(matchedId);

for(int i=0;i<matchedId.length;i++)

{

if(matchedId[i]!=0)

System.out.println(matchedId[i]);

}

}

public static Book[] searchTitle(String value, Book[] books)

{

int k=0;

Book[] matching=new Book[4];

for(int i=0;i<matching.length;i++)

matching[i]=new Book();

for(int i=0;i<books.length;i++)

{

String val=value.toLowerCase();

String bookTitle=books[i].title.toLowerCase();

if(bookTitle.contains(val))

{

matching[k++]=books[i];

}

}

return matching;

}

}

class Book

{

int id;

String title;

String author;

double price;

public int getId()

{



return this.id;

}

public void setId(int id)

{

this.id=id;

}

public String getTitle()

{

return this.title;

}

public void setTitle(String title)

{

this.title=title;

}

public String getAuthor()

{

return this.author;

}

public void setAuthor(String author)

{

this.author=author;

}

public double getPrice()

{

return this.price;

}

public void setPrice(double price)

{

this.price=price;

}

Java Arrays - Hands on 2

Java Arrays - Hands on 2
Problem 1: 

import java.util.Scanner;
public class Solution {
public static void main(String args[] ) throws Exception {

Shirt[] shirts = new Shirt[5];
Scanner sc = new Scanner(System.in);
for(int i = 0;i<5;i++)
{
int tag = sc.nextInt();
sc.nextLine();
String brand = sc.nextLine();
double price = sc.nextDouble();
sc.nextLine();
char g = sc.nextLine().charAt(0);
shirts[i] = new Shirt(tag,brand,price,g);
}
double price = sc.nextDouble();

for(Shirt s: shirts)
{
System.out.println(getDiscountPrice(s));
}
Shirt[] result = getShirtWithMoreThanSpecificPrice(shirts,price);
for(Shirt s: result)
{
if(s.getTag()!=0)
System.out.println(s.getTag()+" "+s.getPrice()+ " " + s.getBrand());
}

}
public static double getDiscountPrice(Shirt s)
{
double discount;
if(s.gender=='m')
discount=10;
else if(s.gender=='f')
discount=20;
else if(s.gender=='u')
discount=30;
else
discount=0;
return s.price-(discount*s.price)/100;
}
public static Shirt[] getShirtWithMoreThanSpecificPrice(Shirt [] shirts, double price)
{
Shirt[] res = new Shirt[5];
for(int i=0;i<res.length;i++)
res[i]=new Shirt(0,"",0,'c');
int j=0;
for(int i=0;i<shirts.length;i++)
{
if(shirts[i].price>price)
{
res[j++]= new Shirt(shirts[i].tag,shirts[i].brand,shirts[i].price,shirts[i].gender);
}
}
return res;
}
}
class Shirt
{
int tag;
String brand;

double price;
char gender;
Shirt(int tag, String brand, double price, char gender)
{
this.tag=tag;
this.brand=brand;
this.price=price;
this.gender=gender;
}
public int getTag()
{
return this.tag;
}
public void setTag(int tag)
{
this.tag=tag;
}
public String getBrand()
{
return this.brand;
}
public void setBrand(String brand)
{
this.brand=brand;
}
public double getPrice()
{
return this.price;
}
public void setPrice(double price)
{
this.price=price;
}
public char getGender()
{
return this.gender;
}
public void setGender(char gender)
{

this.gender=gender;
}
}

Java Iterations - Hands on 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);
 int []num=new int[5];
 for(int i=0;i<5;i++)
 {
 num[i]=scn.nextInt();
 String res=factorial(num[i]);
 System.out.println(res);
 }
 }
 public static String factorial(int n)
 {
 BigInteger fact=new BigInteger("1");
 for(int i=1;i<=n;i++){
 fact=fact.multiply(new BigInteger(i+""));
 }
 return fact.toString();
 }
}

Followers

Ad Space