Mock answers tcs Java and awk

<-------class college------>

import java.util.*;

class College

{

private int id,cNo,pcode;

private String name,addr;

public College(int id, int cNo, int pcode, String name, String addr)

{

super();

this.id = id;

this.cNo = cNo;

this.pcode = pcode;

this.name = name;

this.addr = addr;

}

public int getId()

{

return id;

}

public void setId(int id)

{

this.id = id;

}

public int getContactNo()

{

return cNo;

}

public void setContactNo(int cNo)

{

this.cNo = cNo;

}

public int getPincode()

{

return pcode;

}

public void setPincode(int pcode)

{

this.pcode = pcode;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public String getAddress()

{

return addr;

}

public void setAddress(String addr)

{

this.addr = addr;

}

}

public class Solution

{

public static void main(String[] args)

{

 Scanner sc = new Scanner(System.in);

 int n = sc.nextInt();

 College college[] = new College[n];

 for(int i=0; i<college.length; 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();

 college[i] = new College(id, contactNo, pincode, name,

address);

 }

 sc.nextLine();

 String searchaddress = sc.nextLine();

 College res1 = findCollegeWithMaximumPincode(college);

if(res1!=null)

{

System.out.println("id-"+res1.getId());

System.out.println("name-"+res1.getName());

System.out.println("contactNo-"+res1.getContactNo());

System.out.println("address-"+res1.getAddress());

System.out.println("pincode-"+res1.getPincode());

}

else

{

System.out.println("No College found with mentioned attribute");

}

College res2 =searchCollegeByAddress(college,searchaddress);

if(res2!=null)

{

System.out.println("id-"+res2.getId());

System.out.println("name-"+res2.getName());

System.out.println("contactNo-"+res2.getContactNo());

System.out.println("address-"+res2.getAddress());

System.out.println("pincode-"+res2.getPincode());

}

else

{

System.out.println("No College found with mentioned attribute.");

}

}

public static College findCollegeWithMaximumPincode(College col[])

{

int max=0;

College result =null;

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

 if(col[i].getPincode() > max){

 result = col[i];

 max= col[i].getPincode();

 }

 }

if(result!=null)

 return result;

else

return null;

}

public static College searchCollegeByAddress(College c[],String address)

{

College ans=null;

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

{

if(c[i].getAddress().equalsIgnoreCase(address))

{

ans=c[i];

}

}

if(ans!=null)

return ans;

else

return null;

}

}


<-----vehicle----------->


 import java.io.*;

import java.util.*;


 class Vehicle {

   

    int number;

    String name;

    double price;

    

    Vehicle(int number, String name, double price)

    {

        this.number=number;

        this.name=name;

        this.price=price;

    }

     

      public int getNumber()

      {

          return this.number;

      }

      

      public String getName()

      {

          return this.name;

      }

      

      public double getPrice()

      {

          return this.price;

      }

    }

    

    


public class Main {

    public static void main(String args[] ){

        /* Enter your code here. Read input from STDIN. Print output to STDOUT */

        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();

        Vehicle []v=new Vehicle[n];

        

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

        {

            int number=sc.nextInt();

            sc.nextLine();

            String name=sc.nextLine();

            double price=sc.nextDouble();

            sc.nextLine();

            v[i] =new Vehicle(number, name, price);  

        }

        

         String name=sc.nextLine();

         sc.close();

         

         Vehicle r1=findVehicleWithMinimumPrice(v);

         if(r1!=null)

         {

             System.out.println("number-"+r1.getNumber());

             System.out.println("name-"+r1.getName());

             System.out.println("price-"+r1.getPrice());

         }

         else{

              System.out.println("No Vehicle found with mentioned attribute");

         }

         

         Vehicle r2=searchVehicleByName(v, name);

         if(r2!=null)

         {

             System.out.println("number-"+r2.getNumber());

             System.out.println("name-"+r2.getName());

             System.out.println("price-"+r2.getPrice());

         }

         else{

              System.out.println("No Vehicle found with mentioned attribute");

         }

    }

    

    public static Vehicle findVehicleWithMinimumPrice(Vehicle[] v){


        // Enter your code here

        Vehicle m=null;

        double minp=Double.MAX_VALUE;

        

        if(v!=null)

        {

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

            {

                if(v[i].getPrice()<minp)

                {

                    minp=v[i].getPrice();

                    m=v[i];

                }

            }

        }

        

        if(m==null)

        {

            return null;

        }

        else

        {

            return m;

        }

    }


public static Vehicle searchVehicleByName(Vehicle[] v,String name){

 

    // Enter your code here

         Vehicle m=null;

        

        if(v!=null)

        {

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

            {

                if(v[i].getName().equalsIgnoreCase(name))

                {

                    m=v[i];

                }

            }

        }

        

        if(m==null)

        {

            return null;

        }

        else

        {

            return m;

        }

 }


}


<-------lawyer--------->


import java.io.*;
import java.util.*;

public class Solution
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Lawyer[] arr = new Lawyer[n];
for(int i=0;i<n;i++){
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
double salary = sc.nextDouble();
sc.nextLine();
int age = sc.nextInt();
sc.nextLine();
arr[i] = new Lawyer(id,name,salary,age);
}

String name1 = sc.nextLine();
double res1 = findAverageAgeOfLawyer(arr);
if(res1==0){
System.out.println("No Lawyer found with mentioned attribute.");
}
else {System.out.println("Average of age "+res1);}

Lawyer res2 = searchLawyerByName(arr,name1);
if(res2==null){
System.out.println("No Lawyer found with mentioned attribute.");
}else{
System.out.println("id-"+ res2.id);
System.out.println( "name-" + res2.name);
System.out.println( "salary-" + res2.salary);
System.out.println("age-" + res2.age);}
}



public static double findAverageAgeOfLawyer(Lawyer[] laws)
{
double c=0;
for(int i=0;i<laws.length;i++){
c = c+laws[i].age;
}
if(c!=0){
return c/laws.length;
}else return 0;
}
public static Lawyer searchLawyerByName(Lawyer[] laws, String lname)
{
for(int i=0;i<laws.length;i++){
if(laws[i].name.equals(lname)){
return laws[i];
}
}return null;
}

}

class Lawyer
{
int id;
String name;
double salary;
int age;

Lawyer(int id,String name,double salary,int age){
this.id=id;
this.name=name;
this.salary=salary;
this.age=age;

}

}


<----------Player---------->

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


 Scanner sc = new Scanner(System.in);


 int n = sc.nextInt();


 Player[] p = new Player[n];


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


 {


 int id =sc.nextInt();


 int matchesPlayed = sc.nextInt();


 int totalRuns = sc.nextInt();sc.nextLine();


 String name = sc.nextLine();


 String team = sc.nextLine();


 p[i] = new Player(id, matchesPlayed, totalRuns, name, team);


 }


 int id1 = sc.nextInt();


 Player res1 = findPlayerWithMinimumMatchesPlayed(p);


 if(res1 == null)


 {


 System.out.println("No Player found with mentioned


attribute");


 }


 else


 {


 System.out.println("id-" + res1.getId());


 System.out.println("matchesPlayed-" +


res1.getMatchesPlayed());


 System.out.println("totalRuns-" + res1.getTotalRuns());


 System.out.println("name-" + res1.getName());


 System.out.println("team-" + res1.getTeam());


 }


 Player res2 = searchPlayerById(p, id1);


 if(res2 == null)


 {


System.out.println("No Player found with mentioned


attribute");


 }


 else{


 System.out.println("id-" + res2.getId());


 System.out.println("matchesPlayed-" +


res2.getMatchesPlayed());


 System.out.println("totalRuns-" + res2.getTotalRuns());


 System.out.println("name-" + res2.getName());


 System.out.println("team-" + res2.getTeam());


 }


 }


 public static Player findPlayerWithMinimumMatchesPlayed(Player[]


players)


 {


 Player obj1 = players[0];


 int min=players[0].getMatchesPlayed();


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


 {


 if(min > players[i].getMatchesPlayed())


 {


min=players[i].getMatchesPlayed();


obj1=players[i];


 }


 }


 return obj1;


 }


 public static Player searchPlayerById(Player[] players, int id)


 {


 //Enter your Code here


 int c = 0;


 Player pObj = null;


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


 {


 if(id == players[i].getId())


 {


 pObj=players[i];


 }


 }


 return pObj;


}


 }


class Player


{


 //Enter your Code here


 int id;


 int matchesPlayed;


 int totalRuns;


 String name;


 String team;


 public int getId()


 {


 return id;


 }


 public int getMatchesPlayed()


 {


 return matchesPlayed;


 }


 public int getTotalRuns()


 {


 return totalRuns;


 }


 public String getName()


 {


 return name;


 }


 public String getTeam()


 {


 return team;


 }


 public void setId(int id)


 {


 this.id = id;


 }


 public void setMatchesPlayed(int matchesPlayed)


 {


 this.matchesPlayed = matchesPlayed;


 }


 public void setTotalRuns(int totalRuns)


 {


 this.totalRuns = totalRuns;


 }


 public void setName(String name)


 {


 this.name= name;


 }


 public void setTeam(St

ring team)


 {


 this.team = team;


 }


 Player(int id, int matchesPlayed, int totalRuns, String name, String


team)


{


 this.id = id;


 this.matchesPlayed = matchesPlayed;


 this.totalRuns = totalRuns;


 this.name = name;


 this.team = team;


 }



Awk code:

<----------english geography ---------->

awk 'BEGIN{FS="|"; eco=0; gco=0; IGNORECASE=1}

{

 if($3 == "English")

 {eco++};

 if( $3 == "Geography")

 {gco++};

}

END{

 if(gco==0 && eco==0){

 print "No records found.";}

 else{

 print "Count of students for English Major = "eco;

 print "Count of students for Geography Major = "gco;

 }

 }'



<--------sangamithra------->

awk 'BEGIN{ FS="|"}

{

 if($4=="Sangamithra" && $5>=90 && $6>=90)

 {

 print $1"|"$2"|"$3"|"$4"|"($5+$6)/2;

 }

 } END{}'|sort -k5 -t'|'


<--------avg salary--------->

awk 'BEGIN{FS="-";sum=0;count=0;}

{

 if($4>0){

 sum=sum+$4;

 count=count+1;


 }


}END{

 avg=sum/(count-1);

 if(avg>0){

 print("Average Salary: "avg)

 }

 else

 print "Average Salary: 0";

}'



<--------total assets------->

awk 'BEGIN{FS=",";total=0;IGNORECASE=1;}

{

 if($3=="finance")

 total=total+$4;

}

END{

 if(total==0)

 print"No Asset Found";

 else

 print"Total Asset Price = "total;

}'

Internet of Things (IoT): What's Next for Smart Devices and Automation? || IOT uses and Benefits

The Internet of Things (IoT) has been rapidly transforming the way we interact with the world around us. From smart homes to wearable technology, IoT has become an integral part of our daily lives. However, the question arises, what's next for smart devices and automation? In this blog, we will explore some of the latest developments and future trends in the world of IoT.

IoT is the network of physical devices, home appliances, vehicles, and other items embedded with sensors, software, and connectivity, which enable these objects to collect and exchange data. This data can be used to automate processes, monitor performance, and improve efficiency. The advancements in technology have led to the development of smart cities, healthcare, and homes.

Smart Cities

The concept of smart cities is based on the integration of IoT with urban infrastructure to optimize city operations and improve the quality of life for residents. Smart cities use IoT technology to collect and analyze data about traffic patterns, energy consumption, and other factors. This data is then used to make data-driven decisions that help in creating a more sustainable and efficient city.

For example, smart traffic lights can adjust their timing based on real-time traffic data, reducing congestion and improving safety. Smart parking systems use sensors to detect available parking spots and communicate the information to drivers, reducing the time and fuel spent on finding a parking spot. In addition, IoT can be used to monitor air and water quality, detect and respond to natural disasters, and optimize waste management.


Healthcare

IoT has made significant progress in the healthcare industry, providing a more personalized and efficient approach to patient care. Wearable technology and other IoT devices can monitor patient health in real-time, allowing doctors to track changes in a patient's condition and intervene before a serious problem arises.

For example, continuous glucose monitoring (CGM) devices can monitor blood sugar levels in diabetic patients and alert them when their levels are too high or too low. IoT technology can also be used to optimize hospital operations, such as tracking the location of medical equipment or ensuring that patients are taking their medications as prescribed.

Smart Homes

IoT technology is becoming increasingly sophisticated in the realm of smart homes. Smart home devices can now communicate with each other and with voice-activated virtual assistants such as Amazon's Alexa or Google Home, creating a seamless and personalized home automation experience. From adjusting the temperature to turning off lights, smart home devices can be controlled with a simple voice command.

In addition, IoT-enabled security systems can provide real-time monitoring of homes and alert homeowners to potential security breaches. IoT sensors can also detect changes in temperature, humidity, and other environmental factors, allowing homeowners to optimize energy consumption and save money on utilities.

Emerging Technologies

Looking to the future, there are several emerging technologies that will shape the future of IoT. One such technology is 5G networks, which will enable faster data transfer and lower latency, allowing IoT devices to operate in real-time. This will enable the development of new applications such as autonomous vehicles and real-time remote surgeries.

Artificial intelligence and machine learning will also play a crucial role in the future of IoT. Machine learning algorithms can analyze large amounts of data generated by IoT devices and learn from it to make predictions and recommendations. This will enable more intelligent and automated decision-making, leading to more efficient and effective use of resources.

In addition, blockchain technology can be used to secure IoT networks and ensure the integrity and privacy of data generated by IoT devices. Blockchain can provide a decentralized and transparent system for storing and sharing data, which can improve trust and accountability in IoT systems.

Conclusion

IoT is a rapidly evolving field with countless possibilities for innovation and growth. The integration of IoT with various industries such as healthcare, smart cities, and homes has led to a more efficient and personalized approach to problem-solving. As technology continues to advance, it will be fascinating to see what new developments and trends emerge in the world of IoT.

The Race to Develop Quantum Computers: Who Will Cross the Finish Line First? || Know about Quantum Computers

The development of quantum computers has been a topic of intense interest in recent years. These powerful machines have the potential to revolutionize fields such as cryptography, drug discovery, and artificial intelligence. Many companies and governments around the world are racing to build the first viable quantum computer. In this blog, we will explore this race and attempt to answer the question: who will cross the finish line first?

First, let's define what a quantum computer is. A quantum computer is a device that uses quantum mechanics to perform calculations. Unlike classical computers, which use bits to represent information as either a 0 or a 1, quantum computers use quantum bits, or qubits, which can exist in multiple states simultaneously. This allows quantum computers to perform certain types of calculations much faster than classical computers.

Quantum computer

Now, let's look at the players in this race. There are several major companies and organizations that are working on quantum computers, including IBM, Google, Microsoft, Intel, and the Chinese government. Each of these players is pursuing a slightly different approach to quantum computing, with varying degrees of success.

IBM has been working on quantum computers for several decades and currently operates several quantum computers through its cloud-based platform, IBM Quantum. Google, on the other hand, made headlines in 2019 when it announced that it had achieved "quantum supremacy," meaning that its quantum computer had solved a problem that would have taken a classical computer thousands of years to solve in just a few minutes.

Microsoft is also making significant progress in quantum computing, with its Quantum Development Kit and its efforts to develop a topological qubit, which could be more stable than other types of qubits. Intel is working on developing quantum chips using silicon, which could potentially integrate with existing classical computing infrastructure.

The Chinese government has also been investing heavily in quantum computing, with the goal of becoming a world leader in the field. In 2020, China announced that it had built a quantum computer that was able to perform a calculation that would have been impossible for a classical computer.

So, who will cross the finish line first? It's difficult to say. Each of these players has strengths and weaknesses, and the field of quantum computing is still in its infancy. However, it's clear that this race is not just about building the first quantum computer, but also about developing the infrastructure and ecosystem necessary to support quantum computing. This includes developing quantum algorithms, programming languages, and tools for simulating and optimizing quantum circuits.

In conclusion, the race to develop quantum computers is a complex and dynamic field. While there are several major players vying for the title of "first to cross the finish line," the real winners will be those who are able to develop the ecosystem and infrastructure necessary to support quantum computing at scale. This will require collaboration and cooperation across industries, governments, and academic institutions. Only time will tell who will ultimately emerge as the leader in this exciting field.

Blockchain Beyond Cryptocurrency: Innovative Use Cases and Implications

Blockchain technology is often associated with cryptocurrency, but its applications go far beyond that. Blockchain is a distributed ledger technology that allows multiple parties to share and verify information in a secure and transparent manner. Each block of information is cryptographically linked to the previous one, forming a chain that's tamper-proof and immutable.

In this blog post, we will explore the innovative use cases and implications of blockchain beyond cryptocurrency.

  1. Supply Chain Management: Blockchain can be used to track and verify the authenticity of goods as they move through the supply chain. This can help prevent fraud, and counterfeiting, and ensure that products meet regulatory standards. For instance, Walmart is using blockchain to track the source of its products, which allows them to quickly identify and remove contaminated food from its shelves.

  2. Digital Identity: Blockchain can provide a decentralized and secure platform for managing digital identities. By storing identity information on a blockchain, individuals can control their own data and share it securely with third parties. Blockchain-based identity systems can help reduce identity theft and fraud while giving individuals more control over their personal data.

  3. Voting Systems: Blockchain can be used to develop secure and transparent voting systems that eliminate the possibility of fraud or vote tampering. A blockchain-based voting system could also enable secure and remote voting, making it more convenient for voters to cast their ballots.

  4. Real Estate Transactions: Blockchain can be used to streamline and secure real estate transactions, reducing the need for intermediaries and ensuring that transactions are executed efficiently and transparently. Blockchain-based real estate platforms can help eliminate fraud, reduce transaction costs, and make it easier for buyers and sellers to transact.

  5. Healthcare: Blockchain can be used to securely store and share patient data, ensuring that sensitive information is protected and accessible only to authorized parties. A blockchain-based healthcare system can also help reduce administrative costs and improve patient outcomes by enabling better coordination between healthcare providers.

In addition to these use cases, blockchain technology has broader implications for society. By enabling decentralized and trustless systems, blockchain has the potential to reduce reliance on centralized institutions and increase transparency and accountability.

In conclusion, blockchain technology has the potential to transform industries and society as a whole. From supply chain management to digital identity, voting systems to real estate transactions, and healthcare to societal implications, blockchain technology has numerous innovative use cases and implications beyond cryptocurrency. As technology continues to evolve, it's important to consider the implications of blockchain and develop solutions that are both innovative and responsible. 

"The Future of Artificial Intelligence: Exploring Possibilities and Predictions" | How AI will change the Future

As technology continues to evolve, we find ourselves at the forefront of a revolution that promises to change the world as we know it. Artificial intelligence (AI) is one such technology that has captured the imagination of scientists, entrepreneurs, and futurists alike. In this blog, we'll explore the future of AI and the potential it holds for transforming our lives.

First, let's define AI. It's a field of computer science that involves developing machines that can perform tasks that typically require human intelligence, such as visual perception, speech recognition, decision-making, and natural language processing. AI systems can be trained to learn from data and improve their performance over time, making them increasingly efficient at performing complex tasks.

So, what's in store for the future of AI? Here are some predictions and possibilities:

  1. AI in Healthcare: AI-powered medical diagnostics could revolutionize the healthcare industry, making it more efficient and accurate. AI algorithms can analyze vast amounts of medical data to identify patterns and predict outcomes, aiding in the early detection and prevention of diseases.


  2. AI in Education: AI could play a vital role in personalized learning, allowing students to learn at their own pace and style. AI systems can identify learning gaps, recommend personalized content, and offer feedback to both students and teachers.


  3. Autonomous Vehicles: The development of self-driving cars is a prime example of how AI can transform transportation. With AI-powered systems, vehicles can make decisions in real-time, detect and avoid obstacles, and optimize routes for maximum efficiency.


  4. Business Automation: AI can automate various business processes, from customer service to marketing and sales. This can help companies save time and money while improving customer satisfaction.


  5. Ethical Considerations: As AI continues to evolve, we must consider the ethical implications of this technology. It's important to ensure that AI systems are transparent, fair, and accountable and that they don't perpetuate biases or discriminate against individuals or groups.

In conclusion, the future of AI is promising and full of possibilities. From healthcare to education, transportation to business automation, AI has the potential to transform our lives and make the world a better place. As we continue to explore the possibilities of AI, we must ensure that we do so ethically and responsibly to reap the maximum benefits.

"Explore the World of Netflix: A Guide to the Different Categories of Shows" | Codes to find the netflix shows


Netflix is a popular streaming service that offers a vast selection of TV shows and movies. To help users find content that interests them, Netflix has organized its content into various categories. One of the categories is action comedies, which combine action-packed scenes with humor. Other categories include biographical dramas, classic TV shows, crime thrillers, and more.

Biographical documentaries provide a unique look into the lives of notable individuals, while courtroom dramas offer suspenseful stories that revolve around legal proceedings. Miniseries are perfect for viewers who want to binge-watch a show in one sitting, while science and nature documentaries offer informative content on various topics.

Sports dramas are perfect for fans of sports, while steamy thrillers provide a thrilling and suspenseful storyline. TV mysteries offer suspenseful storylines that revolve around solving a mystery, while TV sci-fi and fantasy offer viewers a chance to escape into a world of their own.

No matter what your interests may be, Netflix offers a wide variety of content for viewers of all ages. With thousands of TV shows and movies to choose from, there's sure to be something for everyone on this popular streaming service.

In this blog, I will be providing you with a list of codes that will make your life easier for finding your favorite shows. With this list, you can easily find the best match according to the genre.

  • Action Comedies - 43040
  • Action Thrillers - 43048
  • Adventures-7442
  • Biographical Documentaries - 3652
  • Biographical Dramas - 3179
  • British TV Shows - 52117
  • Classic Action & Adventure - 46576
  • Classic Comedies - 31694
  • Classic Dramas - 29809
  • Classic Sci-Fi & Fantasy - 47147
  • Classic Thrillers - 46588
  • Classic TV Shows - 46553
  • Classic War Movies- 48744
  • Classic Westerns - 47465
  • Comic Book and Superhero Movies - 10118
  • Courtroom Dramas - 2748
  • Crime Action & Adventure - 9584
  • Crime Documentaries - 9875
  • Crime Dramas - 6889
  • Crime Thrillers - 10499
  • Cult TV Shows - 74652
  • Documentaries based on Books - 4961
  • Documentaries based on real life - 3653
  • Miniseries-4814
  • Music & Concert Documentaries - 90361
  • Mysteries - 9994
  • Sci-Fi Thrillers - 11014
  • Science & Nature Documentaries - 2595
  • Science & Nature TV - 52780
  • Sports Dramas - 7243
  • Steamy Thrillers - 972
  • Spy Thrillers 9147
  • TV Mysteries - 4366
  • TV Sci-Fi & Fantasy - 1372
Enjoy watching your favorite Netflix shows. For your reference, I am providing an example below:
I have used code 11014 which shows the movies and TV shows related to Sci-Fi Thrillers.



Thank You