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 sc=new Scanner(System.in); int n =sc.nextInt(); sc.nextLine(); Vehicle []vl=new Vehicle[n]; for(int i=0;i<vl.length;i++){ int number=sc.nextInt(); sc.nextLine(); String name=sc.nextLine(); double price=sc.nextDouble(); sc.nextLine(); vl[i]= new Vehicle(number, name, price); } String sname=sc.nextLine(); Vehicle vr=findVehicleWithMinimumPrice(vl); 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(vl,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()); } } public static Vehicle findVehicleWithMinimumPrice(Vehicle[] vl){ // Enter your code here Vehicle vr=vl[0]; double min=vl[0].getPrice(); for(int i=0;i<vl.length;i++) { if(vl[i].getPrice()<min){ min=vl[i].getPrice(); vr=vl[i]; } } return vr; } public static Vehicle searchVehicleByName(Vehicle[] vl,String sname){ // Enter your code here Vehicle r=null; for(int i=0;i<vl.length;i++) { if(vl[i].getName().equalsIgnoreCase(sname)) { r=vl[i]; } } return r; } } class Vehicle { // Enter your code here int number; String name; double price; public int getNumber(){return number;} public String getName(){return name;} public double getPrice(){return price;} public void setNumber(int number){this.number=number;} public void setName(String name){this.name=name;} public void setPrice(double price){this.price=price;} Vehicle(int number, String name,double price){ this.number=number; this.name=name; this.price=price; } }
Write, Run & Share Bash code online using OneCompiler's Online Bash Shell for free. It's one of the robust, feature-rich Bash shell available over online and getting started with the OneCompiler's Bash Shell is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Bash
. OneCompiler also has reference scripts, where you can look for the sample scripts and start coding.
Bash (Bourne Again Shell) is a shell program written by Brian Fox and is an upgraded version of Bourne Shell program 'sh'.
name="Foo"
echo $name
echo "$name"
echo "${name}"
if [ conditional-expression ]
then
statements
fi
if [ conditional-expression ]
then
statements
else
statements
fi
if [ conditional-expression ]
then
statements
elif [ conditional-expression ]
then
statements
else
statements
fi