Skip to content

Commit d77ecfe

Browse files
committed
Motel (IPA-35)
1 parent 8b98606 commit d77ecfe

File tree

2 files changed

+178
-177
lines changed

2 files changed

+178
-177
lines changed
Lines changed: 116 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,117 @@
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
}
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
Create a class Motel with the below attributes:
2-
3-
motelId - int
4-
motelName - String
5-
dateOfBooking – String (in the format dd-mon-yyyy)
6-
noOfRoomsBooked – int
7-
cabFacility – String
8-
totalBill- double
9-
10-
Restricted for circulation outside TCS Xplore 6
11-
The above attributes should be private, write getters, setters and parameterized constructor as
12-
required.
13-
Create class Solution with main method.
14-
Implement one static method – totalNoOfRoomsBooked in Solution class.
15-
totalNoOfRoomsBooked method:
16-
This method will take two input parameter - array of Motel objects and a String parameter.
17-
The method will return the total numbers of rooms booked from array of Motel objects if the cab facility
18-
attribute matches with the given String parameter(cab facility) and the number of rooms booked is
19-
greater than 5.
20-
If no rooms are booked with the above criteria in the array of Motel objects, then the method should
21-
return 0.
22-
Note :
23-
No two Motel object would have the same motelId.
24-
dateOfBooking is stored in the format dd-mon-yyyy(eg. 01-Jan-2022)
25-
The above mentioned static method should be called from the main method.
26-
For totalNoOfRoomsBooked method - The main method should print the total number of booked rooms
27-
as it is, if the returned value is greater than 0, else it
28-
should print "No such rooms booked"
29-
Before calling these static methods in main, use Scanner object to read the values of four Motel objects
30-
referring attributes in the above mentioned attribute sequence.
31-
Next, read the value of one String parameter for capturing the cab facility
32-
33-
Input
34-
___________
35-
1001
36-
M&M
37-
01-Dec-2022
38-
5
39-
Yes
40-
30000
41-
1002
42-
BestStay
43-
10-Jan-2022
44-
3
45-
Yes
46-
27000
47-
1003
48-
Novatel
49-
11-Jun-2022
50-
5
51-
Yes
52-
25000
53-
1004
54-
Chola
55-
01-Sep-2022
56-
7
57-
Yes
58-
72000
59-
Yes
60-
___________
61-
OutPut
62-
___________
1+
Create a class Motel with the below attributes:
2+
3+
motelId - int
4+
motelName - String
5+
dateOfBooking – String (in the format dd-mon-yyyy)
6+
noOfRoomsBooked – int
7+
cabFacility – String
8+
totalBill- double
9+
10+
Restricted for circulation outside TCS Xplore 6
11+
The above attributes should be private, write getters, setters and parameterized constructor as
12+
required.
13+
Create class Solution with main method.
14+
Implement one static method – totalNoOfRoomsBooked in Solution class.
15+
totalNoOfRoomsBooked method:
16+
This method will take two input parameter - array of Motel objects and a String parameter.
17+
The method will return the total numbers of rooms booked from array of Motel objects if the cab facility
18+
attribute matches with the given String parameter(cab facility) and the number of rooms booked is
19+
greater than 5.
20+
If no rooms are booked with the above criteria in the array of Motel objects, then the method should
21+
return 0.
22+
Note :
23+
No two Motel object would have the same motelId.
24+
dateOfBooking is stored in the format dd-mon-yyyy(eg. 01-Jan-2022)
25+
The above mentioned static method should be called from the main method.
26+
For totalNoOfRoomsBooked method - The main method should print the total number of booked rooms
27+
as it is, if the returned value is greater than 0, else it
28+
should print "No such rooms booked"
29+
Before calling these static methods in main, use Scanner object to read the values of four Motel objects
30+
referring attributes in the above mentioned attribute sequence.
31+
Next, read the value of one String parameter for capturing the cab facility
32+
33+
Input
34+
___________
35+
1001
36+
M&M
37+
01-Dec-2022
38+
5
39+
Yes
40+
30000
41+
1002
42+
BestStay
43+
10-Jan-2022
44+
3
45+
Yes
46+
27000
47+
1003
48+
Novatel
49+
11-Jun-2022
50+
5
51+
Yes
52+
25000
53+
1004
54+
Chola
55+
01-Sep-2022
56+
7
57+
Yes
58+
72000
59+
Yes
60+
___________
61+
OutPut
62+
___________
6363
7

0 commit comments

Comments
 (0)