Skip to content

Commit

Permalink
Hotel (IPA-35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit-SE committed Feb 25, 2023
1 parent 71f0440 commit 01d7ea7
Show file tree
Hide file tree
Showing 2 changed files with 298 additions and 297 deletions.
275 changes: 138 additions & 137 deletions IPA8.java → IPA8/IPA8.java
Original file line number Diff line number Diff line change
@@ -1,138 +1,139 @@
import java.util.*;
public class IPA8
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Hotel[] h = new Hotel[4];
for (int i = 0; i < h.length; i++)
{
int a = sc.nextInt();sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();sc.nextLine();
String e = sc.nextLine();
double f = sc.nextDouble();sc.nextLine();

h[i]=new Hotel(a,b,c,d,e,f);
}
String month = sc.nextLine();
String wf = sc.nextLine();
int ans1 = noOfRoomsBookedInGivenMonth(h, month);
if(ans1!=0)
{
System.out.println(ans1);
}
else{
System.out.println("No rooms booked in the given month");
}
int ans2 = searchHotelByWifiOption(h, wf);
if(ans2!=0)
{
System.out.println(ans2);
}
else{
System.out.println("No such option available");
}
}
public static int noOfRoomsBookedInGivenMonth(Hotel[] h, String m)
{
int count = 0;
for (int i = 0; i < h.length; i++)
{
if(h[i].getDate().contains(m))
{
count = count + h[i].getRoom();
return count;
}
}
return 0;
}

public static int searchHotelByWifiOption(Hotel[] h, String w)
{
int[] id = new int[0];
for (int i = 0; i < h.length; i++) {
if(h[i].getWifi().equalsIgnoreCase(w))
{
id = Arrays.copyOf(id, id.length+1);
id[id.length-1]=h[i].getId();
Arrays.sort(id);
}
}
if(id.length>0)
{
return id[id.length-2];
}
else
{
return 0;
}
}
}
class Hotel{
private int id;
private String name;
private String date;
private int room;
private String wifi;
private double bill;

public Hotel(int id, String name, String date, int room, String wifi, double bill)
{
this.id = id;
this.name = name;
this.date = date;
this.room = room;
this.wifi = wifi;
this.bill = bill;
}

public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getDate()
{
return date;
}
public void setDate(String date)
{
this.date = date;
}
public int getRoom()
{
return room;
}
public void setRoom(int room)
{
this.room = room;
}
public String getWifi()
{
return wifi;
}
public void setWifi(String wifi)
{
this.wifi = wifi;
}
public double getBill()
{
return bill;
}
public void setBill(double bill)
{
this.bill = bill;
}
package IPA8;
import java.util.*;
public class IPA8
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Hotel[] h = new Hotel[4];
for (int i = 0; i < h.length; i++)
{
int a = sc.nextInt();sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();sc.nextLine();
String e = sc.nextLine();
double f = sc.nextDouble();sc.nextLine();

h[i]=new Hotel(a,b,c,d,e,f);
}
String month = sc.nextLine();
String wf = sc.nextLine();
int ans1 = noOfRoomsBookedInGivenMonth(h, month);
if(ans1!=0)
{
System.out.println(ans1);
}
else{
System.out.println("No rooms booked in the given month");
}
int ans2 = searchHotelByWifiOption(h, wf);
if(ans2!=0)
{
System.out.println(ans2);
}
else{
System.out.println("No such option available");
}
}
public static int noOfRoomsBookedInGivenMonth(Hotel[] h, String m)
{
int count = 0;
for (int i = 0; i < h.length; i++)
{
if(h[i].getDate().contains(m))
{
count = count + h[i].getRoom();
return count;
}
}
return 0;
}

public static int searchHotelByWifiOption(Hotel[] h, String w)
{
int[] id = new int[0];
for (int i = 0; i < h.length; i++) {
if(h[i].getWifi().equalsIgnoreCase(w))
{
id = Arrays.copyOf(id, id.length+1);
id[id.length-1]=h[i].getId();
Arrays.sort(id);
}
}
if(id.length>0)
{
return id[id.length-2];
}
else
{
return 0;
}
}
}
class Hotel{
private int id;
private String name;
private String date;
private int room;
private String wifi;
private double bill;

public Hotel(int id, String name, String date, int room, String wifi, double bill)
{
this.id = id;
this.name = name;
this.date = date;
this.room = room;
this.wifi = wifi;
this.bill = bill;
}

public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getDate()
{
return date;
}
public void setDate(String date)
{
this.date = date;
}
public int getRoom()
{
return room;
}
public void setRoom(int room)
{
this.room = room;
}
public String getWifi()
{
return wifi;
}
public void setWifi(String wifi)
{
this.wifi = wifi;
}
public double getBill()
{
return bill;
}
public void setBill(double bill)
{
this.bill = bill;
}
}
Loading

0 comments on commit 01d7ea7

Please sign in to comment.