Skip to content

Commit 8b98606

Browse files
committed
College (IPA-35)
1 parent 1c849f0 commit 8b98606

File tree

2 files changed

+306
-305
lines changed

2 files changed

+306
-305
lines changed
Lines changed: 132 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,132 @@
1-
import java.util.*;
2-
public class IPA4 {
3-
public static void main(String[] args) {
4-
Scanner sc = new Scanner(System.in);
5-
int n = sc.nextInt();sc.nextLine();
6-
College[] college = new College[n];
7-
8-
for (int i=0; i<n; i++)
9-
{
10-
int a = sc.nextInt();sc.nextLine();
11-
String b = sc.nextLine();
12-
int c = sc.nextInt();sc.nextLine();
13-
String d = sc.nextLine();
14-
int e = sc.nextInt();sc.nextLine();
15-
16-
college[i]= new College(a,b,c,d,e);
17-
}
18-
19-
String address = sc.nextLine();
20-
College pin = findCollegeWithMaximumPincode(college);
21-
if(pin!=null)
22-
{
23-
System.out.println("ID : "+pin.getId());
24-
System.out.println("Name : "+pin.getName());
25-
System.out.println("Contact No : "+pin.getContactNo());
26-
System.out.println("Address : "+pin.getAddress());
27-
System.out.println("Pin : "+pin.getPin());
28-
}
29-
else{
30-
System.out.println("No college found with mentioned attribute");
31-
}
32-
33-
College add = searchCollegeByAddress(college,address);
34-
if(add!=null)
35-
{
36-
System.out.println("ID : "+add.getId());
37-
System.out.println("Name : "+add.getName());
38-
System.out.println("Contact No : "+add.getContactNo());
39-
System.out.println("Address : "+add.getAddress());
40-
System.out.println("Pin : "+add.getPin());
41-
}
42-
else{
43-
System.out.println("No college found with mentioned attribute");
44-
}
45-
}
46-
public static College findCollegeWithMaximumPincode(College[] college)
47-
{
48-
int max = 0;
49-
for(int i =0; i<college.length; i++)
50-
{
51-
if(college[i].getPin()>max)
52-
{
53-
max = college[i].getPin();
54-
}
55-
}
56-
for(int i=0; i<college.length; i++)
57-
{
58-
if(college[i].getPin()==max)
59-
{
60-
return college[i];
61-
}
62-
}
63-
return null;
64-
}
65-
public static College searchCollegeByAddress(College[] college,String add)
66-
{
67-
for(int i=0; i<college.length; i++)
68-
{
69-
if(college[i].getAddress().equalsIgnoreCase(add))
70-
{
71-
return college[i];
72-
}
73-
}
74-
return null;
75-
}
76-
}
77-
class College
78-
{
79-
int id, contactNo, pin;
80-
String name, address;
81-
82-
public College(int id, String name, int contactNo, String address, int pin)
83-
{
84-
this.id = id;
85-
this.name = name;
86-
this.contactNo = contactNo;
87-
this.address = address;
88-
this.pin = pin;
89-
}
90-
91-
public int getId()
92-
{
93-
return id;
94-
}
95-
public void setId(int id)
96-
{
97-
this.id = id;
98-
}
99-
public String getName()
100-
{
101-
return name;
102-
}
103-
public void setName(String name)
104-
{
105-
this.name = name;
106-
}
107-
public int getContactNo()
108-
{
109-
return contactNo;
110-
}
111-
public void setContactNo(int contactNo)
112-
{
113-
this.contactNo = contactNo;
114-
}
115-
public String getAddress()
116-
{
117-
return address;
118-
}
119-
public void setAddress(String address)
120-
{
121-
this.address = address;
122-
}
123-
public int getPin()
124-
{
125-
return pin;
126-
}
127-
public void setPin(int pin)
128-
{
129-
this.pin= pin;
130-
}
131-
}
1+
package IPA4;
2+
import java.util.*;
3+
public class IPA4 {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
int n = sc.nextInt();sc.nextLine();
7+
College[] college = new College[n];
8+
9+
for (int i=0; i<n; i++)
10+
{
11+
int a = sc.nextInt();sc.nextLine();
12+
String b = sc.nextLine();
13+
int c = sc.nextInt();sc.nextLine();
14+
String d = sc.nextLine();
15+
int e = sc.nextInt();sc.nextLine();
16+
17+
college[i]= new College(a,b,c,d,e);
18+
}
19+
20+
String address = sc.nextLine();
21+
College pin = findCollegeWithMaximumPincode(college);
22+
if(pin!=null)
23+
{
24+
System.out.println("ID : "+pin.getId());
25+
System.out.println("Name : "+pin.getName());
26+
System.out.println("Contact No : "+pin.getContactNo());
27+
System.out.println("Address : "+pin.getAddress());
28+
System.out.println("Pin : "+pin.getPin());
29+
}
30+
else{
31+
System.out.println("No college found with mentioned attribute");
32+
}
33+
34+
College add = searchCollegeByAddress(college,address);
35+
if(add!=null)
36+
{
37+
System.out.println("ID : "+add.getId());
38+
System.out.println("Name : "+add.getName());
39+
System.out.println("Contact No : "+add.getContactNo());
40+
System.out.println("Address : "+add.getAddress());
41+
System.out.println("Pin : "+add.getPin());
42+
}
43+
else{
44+
System.out.println("No college found with mentioned attribute");
45+
}
46+
}
47+
public static College findCollegeWithMaximumPincode(College[] college)
48+
{
49+
int max = 0;
50+
for(int i =0; i<college.length; i++)
51+
{
52+
if(college[i].getPin()>max)
53+
{
54+
max = college[i].getPin();
55+
}
56+
}
57+
for(int i=0; i<college.length; i++)
58+
{
59+
if(college[i].getPin()==max)
60+
{
61+
return college[i];
62+
}
63+
}
64+
return null;
65+
}
66+
public static College searchCollegeByAddress(College[] college,String add)
67+
{
68+
for(int i=0; i<college.length; i++)
69+
{
70+
if(college[i].getAddress().equalsIgnoreCase(add))
71+
{
72+
return college[i];
73+
}
74+
}
75+
return null;
76+
}
77+
}
78+
class College
79+
{
80+
int id, contactNo, pin;
81+
String name, address;
82+
83+
public College(int id, String name, int contactNo, String address, int pin)
84+
{
85+
this.id = id;
86+
this.name = name;
87+
this.contactNo = contactNo;
88+
this.address = address;
89+
this.pin = pin;
90+
}
91+
92+
public int getId()
93+
{
94+
return id;
95+
}
96+
public void setId(int id)
97+
{
98+
this.id = id;
99+
}
100+
public String getName()
101+
{
102+
return name;
103+
}
104+
public void setName(String name)
105+
{
106+
this.name = name;
107+
}
108+
public int getContactNo()
109+
{
110+
return contactNo;
111+
}
112+
public void setContactNo(int contactNo)
113+
{
114+
this.contactNo = contactNo;
115+
}
116+
public String getAddress()
117+
{
118+
return address;
119+
}
120+
public void setAddress(String address)
121+
{
122+
this.address = address;
123+
}
124+
public int getPin()
125+
{
126+
return pin;
127+
}
128+
public void setPin(int pin)
129+
{
130+
this.pin= pin;
131+
}
132+
}

0 commit comments

Comments
 (0)