Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding New Filles #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions Antenna/Readme.md
Original file line number Diff line number Diff line change
@@ -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
```
98 changes: 98 additions & 0 deletions Antenna/Solution.java
Original file line number Diff line number Diff line change
@@ -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.length; i++){
for(int j=i+1; j<resArr.length; j++){
if(resArr[i].getantennaVSWR() > 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<resArr.length; i++){
System.out.println(resArr[i].getprojectLead());
}
}
}
}


class Antenna{
private int antennaid;
private String antennaName, projectLead;
private double antennaVSWR;

Antenna(int a, String b, String c, double d){
this.antennaid = a;
this.antennaName= b;
this.projectLead = c;
this.antennaVSWR = d;
}

public int getantennaid(){
return this.antennaid;
}
public String getantennaName(){
return this.antennaName;
}
public String getprojectLead(){
return this.projectLead;
}
public double getantennaVSWR(){
return this.antennaVSWR;
}
}