Skip to content

Commit 01d7ea7

Browse files
committed
Hotel (IPA-35)
1 parent 71f0440 commit 01d7ea7

File tree

2 files changed

+298
-297
lines changed

2 files changed

+298
-297
lines changed
Lines changed: 138 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,139 @@
1-
import java.util.*;
2-
public class IPA8
3-
{
4-
public static void main(String[] args) {
5-
Scanner sc= new Scanner(System.in);
6-
Hotel[] h = new Hotel[4];
7-
for (int i = 0; i < h.length; i++)
8-
{
9-
int a = sc.nextInt();sc.nextLine();
10-
String b = sc.nextLine();
11-
String c = sc.nextLine();
12-
int d = sc.nextInt();sc.nextLine();
13-
String e = sc.nextLine();
14-
double f = sc.nextDouble();sc.nextLine();
15-
16-
h[i]=new Hotel(a,b,c,d,e,f);
17-
}
18-
String month = sc.nextLine();
19-
String wf = sc.nextLine();
20-
int ans1 = noOfRoomsBookedInGivenMonth(h, month);
21-
if(ans1!=0)
22-
{
23-
System.out.println(ans1);
24-
}
25-
else{
26-
System.out.println("No rooms booked in the given month");
27-
}
28-
int ans2 = searchHotelByWifiOption(h, wf);
29-
if(ans2!=0)
30-
{
31-
System.out.println(ans2);
32-
}
33-
else{
34-
System.out.println("No such option available");
35-
}
36-
}
37-
public static int noOfRoomsBookedInGivenMonth(Hotel[] h, String m)
38-
{
39-
int count = 0;
40-
for (int i = 0; i < h.length; i++)
41-
{
42-
if(h[i].getDate().contains(m))
43-
{
44-
count = count + h[i].getRoom();
45-
return count;
46-
}
47-
}
48-
return 0;
49-
}
50-
51-
public static int searchHotelByWifiOption(Hotel[] h, String w)
52-
{
53-
int[] id = new int[0];
54-
for (int i = 0; i < h.length; i++) {
55-
if(h[i].getWifi().equalsIgnoreCase(w))
56-
{
57-
id = Arrays.copyOf(id, id.length+1);
58-
id[id.length-1]=h[i].getId();
59-
Arrays.sort(id);
60-
}
61-
}
62-
if(id.length>0)
63-
{
64-
return id[id.length-2];
65-
}
66-
else
67-
{
68-
return 0;
69-
}
70-
}
71-
}
72-
class Hotel{
73-
private int id;
74-
private String name;
75-
private String date;
76-
private int room;
77-
private String wifi;
78-
private double bill;
79-
80-
public Hotel(int id, String name, String date, int room, String wifi, double bill)
81-
{
82-
this.id = id;
83-
this.name = name;
84-
this.date = date;
85-
this.room = room;
86-
this.wifi = wifi;
87-
this.bill = bill;
88-
}
89-
90-
public int getId()
91-
{
92-
return id;
93-
}
94-
public void setId(int id)
95-
{
96-
this.id = id;
97-
}
98-
public String getName()
99-
{
100-
return name;
101-
}
102-
public void setName(String name)
103-
{
104-
this.name = name;
105-
}
106-
public String getDate()
107-
{
108-
return date;
109-
}
110-
public void setDate(String date)
111-
{
112-
this.date = date;
113-
}
114-
public int getRoom()
115-
{
116-
return room;
117-
}
118-
public void setRoom(int room)
119-
{
120-
this.room = room;
121-
}
122-
public String getWifi()
123-
{
124-
return wifi;
125-
}
126-
public void setWifi(String wifi)
127-
{
128-
this.wifi = wifi;
129-
}
130-
public double getBill()
131-
{
132-
return bill;
133-
}
134-
public void setBill(double bill)
135-
{
136-
this.bill = bill;
137-
}
1+
package IPA8;
2+
import java.util.*;
3+
public class IPA8
4+
{
5+
public static void main(String[] args) {
6+
Scanner sc= new Scanner(System.in);
7+
Hotel[] h = new Hotel[4];
8+
for (int i = 0; i < h.length; i++)
9+
{
10+
int a = sc.nextInt();sc.nextLine();
11+
String b = sc.nextLine();
12+
String c = sc.nextLine();
13+
int d = sc.nextInt();sc.nextLine();
14+
String e = sc.nextLine();
15+
double f = sc.nextDouble();sc.nextLine();
16+
17+
h[i]=new Hotel(a,b,c,d,e,f);
18+
}
19+
String month = sc.nextLine();
20+
String wf = sc.nextLine();
21+
int ans1 = noOfRoomsBookedInGivenMonth(h, month);
22+
if(ans1!=0)
23+
{
24+
System.out.println(ans1);
25+
}
26+
else{
27+
System.out.println("No rooms booked in the given month");
28+
}
29+
int ans2 = searchHotelByWifiOption(h, wf);
30+
if(ans2!=0)
31+
{
32+
System.out.println(ans2);
33+
}
34+
else{
35+
System.out.println("No such option available");
36+
}
37+
}
38+
public static int noOfRoomsBookedInGivenMonth(Hotel[] h, String m)
39+
{
40+
int count = 0;
41+
for (int i = 0; i < h.length; i++)
42+
{
43+
if(h[i].getDate().contains(m))
44+
{
45+
count = count + h[i].getRoom();
46+
return count;
47+
}
48+
}
49+
return 0;
50+
}
51+
52+
public static int searchHotelByWifiOption(Hotel[] h, String w)
53+
{
54+
int[] id = new int[0];
55+
for (int i = 0; i < h.length; i++) {
56+
if(h[i].getWifi().equalsIgnoreCase(w))
57+
{
58+
id = Arrays.copyOf(id, id.length+1);
59+
id[id.length-1]=h[i].getId();
60+
Arrays.sort(id);
61+
}
62+
}
63+
if(id.length>0)
64+
{
65+
return id[id.length-2];
66+
}
67+
else
68+
{
69+
return 0;
70+
}
71+
}
72+
}
73+
class Hotel{
74+
private int id;
75+
private String name;
76+
private String date;
77+
private int room;
78+
private String wifi;
79+
private double bill;
80+
81+
public Hotel(int id, String name, String date, int room, String wifi, double bill)
82+
{
83+
this.id = id;
84+
this.name = name;
85+
this.date = date;
86+
this.room = room;
87+
this.wifi = wifi;
88+
this.bill = bill;
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 String getDate()
108+
{
109+
return date;
110+
}
111+
public void setDate(String date)
112+
{
113+
this.date = date;
114+
}
115+
public int getRoom()
116+
{
117+
return room;
118+
}
119+
public void setRoom(int room)
120+
{
121+
this.room = room;
122+
}
123+
public String getWifi()
124+
{
125+
return wifi;
126+
}
127+
public void setWifi(String wifi)
128+
{
129+
this.wifi = wifi;
130+
}
131+
public double getBill()
132+
{
133+
return bill;
134+
}
135+
public void setBill(double bill)
136+
{
137+
this.bill = bill;
138+
}
138139
}

0 commit comments

Comments
 (0)