Skip to content

Commit e1dd492

Browse files
committed
Sim2 (IPA-35)
1 parent 09f0982 commit e1dd492

2 files changed

Lines changed: 148 additions & 37 deletions

File tree

IPA27.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import java.util.*;
2+
public class IPA27 {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
Sim2[] s = new Sim2[4];
6+
for (int i = 0; i < s.length; i++) {
7+
int a = sc.nextInt();sc.nextLine();
8+
String b = sc.nextLine();
9+
int c = sc.nextInt();sc.nextLine();
10+
double d = sc.nextDouble();sc.nextLine();
11+
String e = sc.nextLine();
12+
13+
s[i] = new Sim2(a,b,c,d,e);
14+
}
15+
String cir = sc.nextLine();
16+
double rate = sc.nextDouble();sc.nextLine();
17+
Sim2[] ans = matchAndSort(s,cir,rate);
18+
if(ans!=null)
19+
{
20+
for (int i = 0; i < ans.length; i++) {
21+
System.out.println(ans[i].getId());
22+
}
23+
}
24+
else
25+
{
26+
System.out.println();
27+
}
28+
}
29+
public static Sim2[] matchAndSort(Sim2[] s, String c, double r)
30+
{
31+
Sim2[] id = new Sim2[0];
32+
for (int i = 0; i < s.length; i++) {
33+
if(s[i].getCircle().equalsIgnoreCase(c) && r>s[i].getRps())
34+
{
35+
id = Arrays.copyOf(id, id.length+1);
36+
id[id.length-1] = s[i];
37+
}
38+
}
39+
if(id.length>0)
40+
{
41+
for (int i = 0; i < id.length-1; i++)
42+
{
43+
for (int j = i+1; j < id.length; j++)
44+
{
45+
if(id[i].getBalance()<id[j].getBalance())
46+
{
47+
Sim2 bal = id[i];
48+
id[i] = id[j];
49+
id[j] = bal;
50+
}
51+
}
52+
}
53+
54+
return id;
55+
}
56+
else
57+
{
58+
return null;
59+
}
60+
}
61+
}
62+
class Sim2
63+
{
64+
private int id;
65+
private String company;
66+
private int balance;
67+
private double rps;
68+
private String circle;
69+
public Sim2(int id, String company, int balance, double rps, String circle) {
70+
this.id = id;
71+
this.company = company;
72+
this.balance = balance;
73+
this.rps = rps;
74+
this.circle = circle;
75+
}
76+
public int getId() {
77+
return id;
78+
}
79+
public void setId(int id) {
80+
this.id = id;
81+
}
82+
public String getCompany() {
83+
return company;
84+
}
85+
public void setCompany(String company) {
86+
this.company = company;
87+
}
88+
public int getBalance() {
89+
return balance;
90+
}
91+
public void setBalance(int balance) {
92+
this.balance = balance;
93+
}
94+
public double getRps() {
95+
return rps;
96+
}
97+
public void setRps(double rps) {
98+
this.rps = rps;
99+
}
100+
public String getCircle() {
101+
return circle;
102+
}
103+
public void setCircle(String circle) {
104+
this.circle = circle;
105+
}
106+
107+
108+
}

IPA27.txt

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
1-
## Problem Statement
1+
Create class Sim2 with below attributes:
22

3-
Create class Sim with below attributes:
43
id - int
54
company - String
65
balance - int
76
ratePerSecond - double
87
circle - String
98

109
Create class Solution and implement static method "matchAndSort" in the Solution class.
10+
1111
This method will take array of Sim objects, search_circle String and search_rate double as parameters.
12-
And will return another Sim array where the search_circle matches with the circle parameter of the original Sim array and the search_rate double is greater than the original array of Sim object's ratePerSecond attribute which is also sorted by means of balance attribute in descending order.
12+
And will return another Sim array where the search_circle matches with the circle parameter of the original Sim array and
13+
the search_rate double is greater than the original array of Sim object's ratePerSecond attribute which is also sorted by
14+
means of balance attribute in descending order.
1315

1416
Write necessary getters and setters.
1517

16-
Before calling "matchAndSort" method in the main method, read values for four Sim objects referring the attributes in above sequence along with a String search_circle and a double search_rate.
17-
Then call the "matchAndSort" method and write logic in main method to print the id's of the result obtained.
18-
19-
## Input
20-
21-
1
22-
jio
23-
430
24-
1.32
25-
mumbai
26-
2
27-
idea
28-
320
29-
2.26
30-
mumbai
31-
3
32-
airtel
33-
500
34-
2.54
35-
mumbai
36-
4
37-
vodafone
38-
640
39-
3.21
40-
mumbai
41-
mumbai
42-
3.4
43-
44-
## Output
45-
46-
4
47-
3
48-
1
49-
2
18+
Before calling "matchAndSort" method in the main method, read values for four Sim objects referring the attributes in above
19+
sequence along with a String search_circle and a double search_rate. Then call the "matchAndSort" method and write logic in
20+
main method to print the id's of the result obtained.
21+
22+
Input
23+
--------------------------
24+
1
25+
jio
26+
430
27+
1.32
28+
mumbai
29+
2
30+
idea
31+
320
32+
2.26
33+
mumbai
34+
3
35+
airtel
36+
500
37+
2.54
38+
mumbai
39+
4
40+
vodafone
41+
640
42+
3.21
43+
mumbai
44+
mumbai
45+
3.4
46+
47+
Output
48+
--------------------------
49+
4
50+
3
51+
1
52+
2

0 commit comments

Comments
 (0)