1-
2- import java .util .*;
3- public class IPA5 {
4- public static void main (String []args )
5- {
6- Scanner sc = new Scanner (System .in );
7- Motel [] m = new Motel [4 ];
8- for (int i =0 ; i <4 ; 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- m [i ] = new Motel (a ,b ,c ,d ,e ,f );
18- }
19- String cf = sc .nextLine ();
20- int total = totalNoOfRoomsBooked (m , cf );
21- if (total !=0 )
22- {
23- System .out .println (total );
24- }
25- else {
26- System .out .println ("No such rooms booked" );
27- }
28-
29- }
30- public static int totalNoOfRoomsBooked (Motel [] m ,String check )
31- {
32- int total = 0 ;
33- for (int i = 0 ; i <m .length ; i ++)
34- {
35- if (m [i ].getCabFacility ().equalsIgnoreCase (check ) && m [i ].getNoOfRoomsBooked ()>5 )
36- {
37- total = total + m [i ].getNoOfRoomsBooked ();
38- }
39- }
40- if (total >0 )
41- {
42- return total ;
43- }
44- else {
45- return 0 ;
46- }
47- }
48- }
49- class Motel
50- {
51- private int motelId ;
52- private String motelName ;
53- private String dateOfBooking ;
54- private int noOfRoomsBooked ;
55- private String cabFacility ;
56- private double totalBill ;
57-
58- public Motel (int motelId , String motelName , String dateOfBooking , int noOfRoomsBooked , String cabFacility , double totalBill )
59- {
60- this .motelId = motelId ;
61- this .motelName = motelName ;
62- this .dateOfBooking = dateOfBooking ;
63- this .noOfRoomsBooked = noOfRoomsBooked ;
64- this .cabFacility = cabFacility ;
65- this .totalBill = totalBill ;
66- }
67-
68- public int getMotelId ()
69- {
70- return motelId ;
71- }
72- public void setMotelId (int motelId )
73- {
74- this .motelId = motelId ;
75- }
76- public String getMotelName ()
77- {
78- return motelName ;
79- }
80- public void setMotelName (String motelName )
81- {
82- this .motelName = motelName ;
83- }
84- public String getDateOfBooking ()
85- {
86- return dateOfBooking ;
87- }
88- public void setDateOfBooking (String dateOfBooking )
89- {
90- this .dateOfBooking = dateOfBooking ;
91- }
92- public int getNoOfRoomsBooked ()
93- {
94- return noOfRoomsBooked ;
95- }
96- public void setNoOfRoomBooked (int noOfRoomsBooked )
97- {
98- this .noOfRoomsBooked = noOfRoomsBooked ;
99- }
100- public String getCabFacility ()
101- {
102- return cabFacility ;
103- }
104- public void setCabFacility (String cabFacility )
105- {
106- this .cabFacility = cabFacility ;
107- }
108- public double getTotalBill ()
109- {
110- return totalBill ;
111- }
112- public void setTotalBill (double totalBill )
113- {
114- this .totalBill = totalBill ;
115- }
1+ package IPA5 ;
2+
3+ import java .util .*;
4+ public class IPA5 {
5+ public static void main (String []args )
6+ {
7+ Scanner sc = new Scanner (System .in );
8+ Motel [] m = new Motel [4 ];
9+ for (int i =0 ; i <4 ; i ++)
10+ {
11+ int a = sc .nextInt ();sc .nextLine ();
12+ String b = sc .nextLine ();
13+ String c = sc .nextLine ();
14+ int d = sc .nextInt ();sc .nextLine ();
15+ String e = sc .nextLine ();
16+ double f = sc .nextDouble ();sc .nextLine ();
17+
18+ m [i ] = new Motel (a ,b ,c ,d ,e ,f );
19+ }
20+ String cf = sc .nextLine ();
21+ int total = totalNoOfRoomsBooked (m , cf );
22+ if (total !=0 )
23+ {
24+ System .out .println (total );
25+ }
26+ else {
27+ System .out .println ("No such rooms booked" );
28+ }
29+
30+ }
31+ public static int totalNoOfRoomsBooked (Motel [] m ,String check )
32+ {
33+ int total = 0 ;
34+ for (int i = 0 ; i <m .length ; i ++)
35+ {
36+ if (m [i ].getCabFacility ().equalsIgnoreCase (check ) && m [i ].getNoOfRoomsBooked ()>5 )
37+ {
38+ total = total + m [i ].getNoOfRoomsBooked ();
39+ }
40+ }
41+ if (total >0 )
42+ {
43+ return total ;
44+ }
45+ else {
46+ return 0 ;
47+ }
48+ }
49+ }
50+ class Motel
51+ {
52+ private int motelId ;
53+ private String motelName ;
54+ private String dateOfBooking ;
55+ private int noOfRoomsBooked ;
56+ private String cabFacility ;
57+ private double totalBill ;
58+
59+ public Motel (int motelId , String motelName , String dateOfBooking , int noOfRoomsBooked , String cabFacility , double totalBill )
60+ {
61+ this .motelId = motelId ;
62+ this .motelName = motelName ;
63+ this .dateOfBooking = dateOfBooking ;
64+ this .noOfRoomsBooked = noOfRoomsBooked ;
65+ this .cabFacility = cabFacility ;
66+ this .totalBill = totalBill ;
67+ }
68+
69+ public int getMotelId ()
70+ {
71+ return motelId ;
72+ }
73+ public void setMotelId (int motelId )
74+ {
75+ this .motelId = motelId ;
76+ }
77+ public String getMotelName ()
78+ {
79+ return motelName ;
80+ }
81+ public void setMotelName (String motelName )
82+ {
83+ this .motelName = motelName ;
84+ }
85+ public String getDateOfBooking ()
86+ {
87+ return dateOfBooking ;
88+ }
89+ public void setDateOfBooking (String dateOfBooking )
90+ {
91+ this .dateOfBooking = dateOfBooking ;
92+ }
93+ public int getNoOfRoomsBooked ()
94+ {
95+ return noOfRoomsBooked ;
96+ }
97+ public void setNoOfRoomBooked (int noOfRoomsBooked )
98+ {
99+ this .noOfRoomsBooked = noOfRoomsBooked ;
100+ }
101+ public String getCabFacility ()
102+ {
103+ return cabFacility ;
104+ }
105+ public void setCabFacility (String cabFacility )
106+ {
107+ this .cabFacility = cabFacility ;
108+ }
109+ public double getTotalBill ()
110+ {
111+ return totalBill ;
112+ }
113+ public void setTotalBill (double totalBill )
114+ {
115+ this .totalBill = totalBill ;
116+ }
116117}
0 commit comments