diff --git a/Main.java b/Main.java deleted file mode 100755 index 2255c0a..0000000 --- a/Main.java +++ /dev/null @@ -1,588 +0,0 @@ -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Scanner; - -class Food implements Serializable -{ - int itemno; - int quantity; - float price; - - Food(int itemno,int quantity) - { - this.itemno=itemno; - this.quantity=quantity; - switch(itemno) - { - case 1:price=quantity*50; - break; - case 2:price=quantity*60; - break; - case 3:price=quantity*70; - break; - case 4:price=quantity*30; - break; - } - } -} -class Singleroom implements Serializable -{ - String name; - String contact; - String gender; - ArrayList food =new ArrayList<>(); - - - Singleroom() - { - this.name=""; - } - Singleroom(String name,String contact,String gender) - { - this.name=name; - this.contact=contact; - this.gender=gender; - } -} -class Doubleroom extends Singleroom implements Serializable -{ - String name2; - String contact2; - String gender2; - - Doubleroom() - { - this.name=""; - this.name2=""; - } - Doubleroom(String name,String contact,String gender,String name2,String contact2,String gender2) - { - this.name=name; - this.contact=contact; - this.gender=gender; - this.name2=name2; - this.contact2=contact2; - this.gender2=gender2; - } -} -class NotAvailable extends Exception -{ - @Override - public String toString() - { - return "Not Available !"; - } -} - -class holder implements Serializable -{ - Doubleroom luxury_doublerrom[]=new Doubleroom[10]; //Luxury - Doubleroom deluxe_doublerrom[]=new Doubleroom[20]; //Deluxe - Singleroom luxury_singleerrom[]=new Singleroom[10]; //Luxury - Singleroom deluxe_singleerrom[]=new Singleroom[20]; //Deluxe -} - -class Hotel -{ - static holder hotel_ob=new holder(); - static Scanner sc = new Scanner(System.in); - static void CustDetails(int i,int rn) - { - String name, contact, gender; - String name2 = null, contact2 = null; - String gender2=""; - System.out.print("\nEnter customer name: "); - name = sc.next(); - System.out.print("Enter contact number: "); - contact=sc.next(); - System.out.print("Enter gender: "); - gender = sc.next(); - if(i<3) - { - System.out.print("Enter second customer name: "); - name2 = sc.next(); - System.out.print("Enter contact number: "); - contact2=sc.next(); - System.out.print("Enter gender: "); - gender2 = sc.next(); - } - - switch (i) { - case 1:hotel_ob.luxury_doublerrom[rn]=new Doubleroom(name,contact,gender,name2,contact2,gender2); - break; - case 2:hotel_ob.deluxe_doublerrom[rn]=new Doubleroom(name,contact,gender,name2,contact2,gender2); - break; - case 3:hotel_ob.luxury_singleerrom[rn]=new Singleroom(name,contact,gender); - break; - case 4:hotel_ob.deluxe_singleerrom[rn]=new Singleroom(name,contact,gender); - break; - default:System.out.println("Wrong option"); - break; - } - } - - static void bookroom(int i) - { - int j; - int rn; - System.out.println("\nChoose room number from : "); - switch (i) { - case 1: - for(j=0;j60) - System.out.println("Room doesn't exist"); - else if(ch2>40) - Hotel.order(ch2-41,4); - else if(ch2>30) - Hotel.order(ch2-31,3); - else if(ch2>10) - Hotel.order(ch2-11,2); - else if(ch2>0) - Hotel.order(ch2-1,1); - else - System.out.println("Room doesn't exist"); - break; - case 5: - System.out.print("Room Number -"); - ch2 = sc.nextInt(); - if(ch2>60) - System.out.println("Room doesn't exist"); - else if(ch2>40) - Hotel.deallocate(ch2-41,4); - else if(ch2>30) - Hotel.deallocate(ch2-31,3); - else if(ch2>10) - Hotel.deallocate(ch2-11,2); - else if(ch2>0) - Hotel.deallocate(ch2-1,1); - else - System.out.println("Room doesn't exist"); - break; - case 6:break x; - - } - - System.out.println("\nContinue : (y/n)"); - wish=sc.next().charAt(0); - if(!(wish=='y'||wish=='Y'||wish=='n'||wish=='N')) - { - System.out.println("Invalid Option"); - System.out.println("\nContinue : (y/n)"); - wish=sc.next().charAt(0); - } - - }while(wish=='y'||wish=='Y'); - - Thread t=new Thread(new write(Hotel.hotel_ob)); - t.start(); - } - catch(Exception e) - { - System.out.println("Not a valid input"); - } - } -} diff --git a/Pipeline b/Pipeline new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/Pipeline @@ -0,0 +1 @@ + diff --git a/src/test/java/glue/HotelManagement.java b/src/test/java/glue/HotelManagement.java new file mode 100644 index 0000000..f24263b --- /dev/null +++ b/src/test/java/glue/HotelManagement.java @@ -0,0 +1,185 @@ +import io.cucumber.java.en.*; +import static org.junit.Assert.*; + +public class HotelManagementSteps { + + private int lastBookedRoomNumber = -1; + private int lastRoomType = -1; + private boolean bookingSuccess = false; + private boolean foodOrdered = false; + private boolean checkoutSuccess = false; + + @Given("the hotel management system is running") + public void the_hotel_management_system_is_running() { + // Reset the hotel state for testing + Hotel.hotel_ob = new holder(); + bookingSuccess = false; + foodOrdered = false; + checkoutSuccess = false; + lastBookedRoomNumber = -1; + lastRoomType = -1; + } + + @When("the user requests room features for {string}") + public void the_user_requests_room_features_for(String roomType) { + Hotel.features(getRoomType(roomType)); + } + + @Then("the system should display details for {string}") + public void the_system_should_display_details_for(String roomType) { + // Would capture output for assertion in a robust test + } + + @When("the user requests room availability for {string}") + public void the_user_requests_room_availability_for(String roomType) { + Hotel.availability(getRoomType(roomType)); + } + + @Then("the system should display number of available {string}") + public void the_system_should_display_number_of_available(String roomType) { + // Would capture output for assertion in a robust test + } + + @When("the user books a {string} with name {string}, contact {string}, gender {string}") + public void the_user_books_a_with_details(String roomType, String name, String contact, String gender) { + int type = getRoomType(roomType); + int roomIndex = getFirstAvailableRoomIndex(type); + if (roomIndex != -1) { + Hotel.CustDetails(type, roomIndex, name, contact, gender, null, null, null); // Custom overloaded method for test + lastBookedRoomNumber = roomIndex; + lastRoomType = type; + bookingSuccess = true; + } else { + bookingSuccess = false; + } + } + + @Then("the booking should be successful") + public void the_booking_should_be_successful() { + assertTrue("Booking should succeed", bookingSuccess); + } + + @Given("a {string} is booked with room number {int}") + public void a_room_is_booked_with_room_number(String roomType, int roomNumber) { + int type = getRoomType(roomType); + Hotel.CustDetails(type, roomNumber, "TestUser", "123456", "M", null, null, null); // Custom overloaded method for test + lastBookedRoomNumber = roomNumber; + lastRoomType = type; + bookingSuccess = true; + } + + @When("the user orders {string} quantity {string} for room number {int}") + public void the_user_orders_food(String foodItem, String quantity, int roomNo) { + int itemNo = getFoodItemNo(foodItem); + int qty = Integer.parseInt(quantity); + // Use type from booking context or default to 3 (Luxury Single Room) + int type = (lastRoomType != -1) ? lastRoomType : 3; + switch (type) { + case 1: + if (Hotel.hotel_ob.luxury_doublerrom[roomNo] != null) + Hotel.hotel_ob.luxury_doublerrom[roomNo].food.add(new Food(itemNo, qty)); + break; + case 2: + if (Hotel.hotel_ob.deluxe_doublerrom[roomNo] != null) + Hotel.hotel_ob.deluxe_doublerrom[roomNo].food.add(new Food(itemNo, qty)); + break; + case 3: + if (Hotel.hotel_ob.luxury_singleerrom[roomNo] != null) + Hotel.hotel_ob.luxury_singleerrom[roomNo].food.add(new Food(itemNo, qty)); + break; + case 4: + if (Hotel.hotel_ob.deluxe_singleerrom[roomNo] != null) + Hotel.hotel_ob.deluxe_singleerrom[roomNo].food.add(new Food(itemNo, qty)); + break; + } + foodOrdered = true; + } + + @Then("the food order should be added to the room bill") + public void the_food_order_should_be_added_to_the_room_bill() { + assertTrue("Food should be ordered", foodOrdered); + } + + @Given("a {string} is booked and food has been ordered") + public void a_room_is_booked_and_food_has_been_ordered(String roomType) { + int type = getRoomType(roomType); + int roomIndex = getFirstAvailableRoomIndex(type); + Hotel.CustDetails(type, roomIndex, "TestUser", "123456", "M", null, null, null); // Custom overloaded method for test + lastBookedRoomNumber = roomIndex; + lastRoomType = type; + // Add food + switch (type) { + case 1: + Hotel.hotel_ob.luxury_doublerrom[roomIndex].food.add(new Food(1, 2)); + break; + case 2: + Hotel.hotel_ob.deluxe_doublerrom[roomIndex].food.add(new Food(1, 2)); + break; + case 3: + Hotel.hotel_ob.luxury_singleerrom[roomIndex].food.add(new Food(1, 2)); + break; + case 4: + Hotel.hotel_ob.deluxe_singleerrom[roomIndex].food.add(new Food(1, 2)); + break; + } + foodOrdered = true; + } + + @When("the user checks out from room number {int}") + public void the_user_checks_out_from_room_number(Integer roomNumber) { + if (lastRoomType != -1 && roomNumber != -1) { + Hotel.deallocate(roomNumber, lastRoomType); + checkoutSuccess = true; + } else { + checkoutSuccess = false; + } + } + + @Then("the system should deallocate the room and display the total bill") + public void the_system_should_deallocate_the_room_and_display_the_total_bill() { + assertTrue(checkoutSuccess); + } + + // Utility methods + private int getRoomType(String roomType) { + switch (roomType) { + case "Luxury Double Room": return 1; + case "Deluxe Double Room": return 2; + case "Luxury Single Room": return 3; + case "Deluxe Single Room": return 4; + default: return 1; + } + } + + private int getFirstAvailableRoomIndex(int type) { + switch (type) { + case 1: + for (int i = 0; i < Hotel.hotel_ob.luxury_doublerrom.length; i++) + if (Hotel.hotel_ob.luxury_doublerrom[i] == null) return i; + break; + case 2: + for (int i = 0; i < Hotel.hotel_ob.deluxe_doublerrom.length; i++) + if (Hotel.hotel_ob.deluxe_doublerrom[i] == null) return i; + break; + case 3: + for (int i = 0; i < Hotel.hotel_ob.luxury_singleerrom.length; i++) + if (Hotel.hotel_ob.luxury_singleerrom[i] == null) return i; + break; + case 4: + for (int i = 0; i < Hotel.hotel_ob.deluxe_singleerrom.length; i++) + if (Hotel.hotel_ob.deluxe_singleerrom[i] == null) return i; + break; + } + return -1; + } + + private int getFoodItemNo(String foodName) { + switch (foodName.toLowerCase()) { + case "sandwich": return 1; + case "pasta": return 2; + case "noodles": return 3; + case "coke": return 4; + default: return 1; + } + } +} diff --git a/src/test/java/runner/TestRunner.java b/src/test/java/runner/TestRunner.java new file mode 100644 index 0000000..e415fd0 --- /dev/null +++ b/src/test/java/runner/TestRunner.java @@ -0,0 +1,14 @@ +import org.junit.runner.RunWith; +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = "src/test/resources", // Path to your .feature files + glue = "stepdefinitions", // Package containing your step defs (adjust as needed) + plugin = { "pretty", "html:target/cucumber-reports" }, // Reports + monochrome = true +) +public class TestRunner { + // This class remains empty. It is used only as a holder for the above annotations. +} diff --git a/src/test/java/screenshots b/src/test/java/screenshots new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/test/java/screenshots @@ -0,0 +1 @@ + diff --git a/src/test/resources/hotel-Management.feature b/src/test/resources/hotel-Management.feature new file mode 100644 index 0000000..906d1be --- /dev/null +++ b/src/test/resources/hotel-Management.feature @@ -0,0 +1,26 @@ +Feature: Hotel Management System + + Scenario: Display available features for each room type + Given the hotel management system is running + When the user requests room features for "Luxury Double Room" + Then the system should display details for "Luxury Double Room" + + Scenario: Display room availability + Given the hotel management system is running + When the user requests room availability for "Deluxe Single Room" + Then the system should display number of available "Deluxe Single Room" + + Scenario: Book a room + Given the hotel management system is running + When the user books a "Luxury Single Room" with name "Alice", contact "1111111", gender "F" + Then the booking should be successful + + Scenario: Order food for a room + Given a "Luxury Single Room" is booked with room number 31 + When the user orders "Sandwich" quantity "2" for room number 31 + Then the food order should be added to the room bill + + Scenario: Checkout from room + Given a "Luxury Single Room" is booked and food has been ordered + When the user checks out from room number 31 + Then the system should deallocate the room and display the total bill