0% found this document useful (0 votes)
13 views3 pages

UNIX Sort and Minimum Java OOPS

The document contains a script that processes vehicle data, filtering for a specific vehicle named 'Sangamithra' with high scores. It also includes a Java program that allows users to input vehicle details and find the vehicle with the minimum price or search for a vehicle by name. The program utilizes a Vehicle class to store vehicle attributes and provides methods for searching and finding vehicles.

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)
13 views3 pages

UNIX Sort and Minimum Java OOPS

The document contains a script that processes vehicle data, filtering for a specific vehicle named 'Sangamithra' with high scores. It also includes a Java program that allows users to input vehicle details and find the vehicle with the minimum price or search for a vehicle by name. The program utilizes a Vehicle class to store vehicle attributes and provides methods for searching and finding vehicles.

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/ 3

awk 'BEGIN{ FS="|"}

{
if($4=="Sangamithra" && $5>=90 && $6>=90)
{
print $1"|"$2"|"$3"|"$4"|"($5+$6)/2;
}
} END{}'|sort -k5 -t'|'

==========================================================
import java.util.Scanner;
class Vehicle
{
int number;
String name;
double price;
public Vehicle(int number,String name,double price)
{
super();
this.number=number;
this.name=name;
this.price=price;
}
public int getNumber()
{
return number;
}
public String getName()
{
return name;
}
public double getPrice()
{
return price;
}
}

public class Minimum


{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
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 sname=sc.nextLine();
Vehicle vr=findVehicleWithMinimumPrice(v);
if(vr==null)
{
System.out.println("No Vehicle found with mentioned attribute");
}
else
{
System.out.println("number-"+vr.getNumber());
System.out.println("name-"+vr.getName());
System.out.println("price-"+vr.getPrice());
}
Vehicle r=searchVehicleByName(v,sname);
if(r==null)
{
System.out.println("No Vehicle found with mentioned attribute");
}
else
{
System.out.println("number-"+r.getNumber());
System.out.println("name-"+r.getName());
System.out.println("price-"+r.getPrice());
}
sc.close();
}
public static Vehicle searchVehicleByName(Vehicle[] v,String sname)
{
int pos=-1;
for(int i=0;i<v.length;i++)
{
if(v[i].getName().equalsIgnoreCase(sname))
{
pos=i;
}
}
if(pos==-1)
return null;
else
return v[pos];
}
public static Vehicle findVehicleWithMinimumPrice(Vehicle[] v)
{
Vehicle p=v[0];
double min=v[0].getPrice();
for(int i=0;i<v.length;i++)
{
if(v[i].getPrice()<min)
{
min=v[i].getPrice();
p=v[i];
}
}
if(min!=0)
return p;
else
return null;
}
}

You might also like