0% found this document useful (0 votes)
9 views4 pages

UNIX Total and Sort Java OOPS

The document contains a script that processes financial data using AWK to calculate total asset prices based on a specific category. It also includes a Java program that defines a Player class and implements methods to find a player with the minimum matches played and to search for a player by their ID. The program takes user input to create an array of Player objects and displays relevant information based on the search criteria.

Uploaded by

mishra.ayush2919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

UNIX Total and Sort Java OOPS

The document contains a script that processes financial data using AWK to calculate total asset prices based on a specific category. It also includes a Java program that defines a Player class and implements methods to find a player with the minimum matches played and to search for a player by their ID. The program takes user input to create an array of Player objects and displays relevant information based on the search criteria.

Uploaded by

mishra.ayush2919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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;
}'
=================================================
import java.util.Scanner;
class Player
{
//Enter your Code here
int id;
int matchesPlayed;
int totalRuns;
String name;
String 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;
}
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 class Sort {


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;

You might also like