From 01f467f903daf65c22d9f0bb798f8c8b60e570a6 Mon Sep 17 00:00:00 2001 From: Subash K <81848034+subash-srk@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:18:07 +0530 Subject: [PATCH] Adding New Filles --- Antenna/Readme.md | 89 +++++++++++++++++++++++++++++++++++++++ Antenna/Solution.java | 98 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 Antenna/Readme.md create mode 100644 Antenna/Solution.java diff --git a/Antenna/Readme.md b/Antenna/Readme.md new file mode 100644 index 0000000..76f0b30 --- /dev/null +++ b/Antenna/Readme.md @@ -0,0 +1,89 @@ +create a class Antenna with below attributes. + +antennaid-int + +antennaName-String + +projectLead-String + +antennaVSWR-double + +the above attribute should be private ,write getter and setter and parametrized constructor as well. + +create class MyClass with main method. +implement two static methods searchAntennaByName and sortAntennaByVSWR in MyClass class. + + +searchAntennaByName : +--------------------------------------- +This method will take an array of Antenna objects and the string value as input parameter.The method will find out Antenna name(String parameterpassed). +It will return Antennaid if found.if there is no Antenna that matches then the method will return zero. +The main method should print the antennaid,if the returned value is not 0.if the returned value is 0 then print,"There is no antenna with the given parameter". + + +sortAntennaByVSWR: +-------------------------------------- +This method will take an array of Antenna Objects and a double value as input. +This method will return an array of Antenna objects sorted in ascending orderof their antennaVSWR, which is less than VSWR(double value passed). + +The main method should print name of the project leads from the returned array if the returned value is not null.if the returned value is null then main method +should print "No Antenna found"; + + +input1: +``` +111 +Reconfigurable +Hema +0.4 +222 +Wearable +Kavya +0.9 +333 +Microstrip +Teju +0.3 +444 +Dielectric +Sai +0.65 +Microstrip +0.5 +``` + +output: +``` +333 +Teju +Hema +``` + + +input 2: +``` +111 +Reconfigurable +Hema +0.3 +222 +Wearable +Kavya +0.9 +333 +Microstrip +Teju +0.4 +444 +Dielectric +Sai +0.65 +Resonator +0.25 +``` + +output: +``` +There is no antenna with given parameter +No Antenna found +``` \ No newline at end of file diff --git a/Antenna/Solution.java b/Antenna/Solution.java new file mode 100644 index 0000000..9c096c0 --- /dev/null +++ b/Antenna/Solution.java @@ -0,0 +1,98 @@ +import java.util.*; +class Solution{ + + static int searchAntenna(Antenna[] arr, String fName){ + for(int i=0; i<4; i++){ + if(arr[i].getantennaName().equalsIgnoreCase(fName)){ + return arr[i].getantennaid(); + } + } + return 0; + + } + + static Antenna[] sortAntenna(Antenna[] arr, double fVSWR){ + Antenna[] resArr = new Antenna[0]; + for(int i=0; i<4; i++){ + if(arr[i].getantennaVSWR() < fVSWR){ + resArr = Arrays.copyOf(resArr, resArr.length+1); + resArr[resArr.length - 1] = arr[i]; + } + } + Antenna temp; + for(int i=0; i resArr[j].getantennaVSWR()){ + temp = resArr[i]; + resArr[i] = resArr[j]; + resArr[j] = temp; + } + } + } + return resArr; + } + + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args){ + Antenna[] arr = new Antenna[4]; + for(int i=0; i<4; i++){ + int a = sc.nextInt(); + sc.nextLine(); + String b = sc.nextLine(); + String c = sc.nextLine(); + double d = sc.nextDouble(); + sc.nextLine(); + + arr[i] = new Antenna(a, b, c, d); + } + String fName = sc.nextLine(); + double fVSWR = sc.nextDouble(); + //System.out.println(fVSWR); + + int resId = searchAntenna(arr, fName); + if(resId == 0){ + System.out.println("There is no antenna with the given parameter"); + } + else{ + System.out.println(resId); + } + + Antenna[] resArr = sortAntenna(arr, fVSWR); + if(resArr.length == 0){ + System.out.println("No Antenna found"); + } + else{ + for(int i=0; i