diff --git a/.classpath b/.classpath
index 2846539..4c0579d 100644
--- a/.classpath
+++ b/.classpath
@@ -8,10 +8,11 @@
-
+
-
+
+
diff --git a/build/classes/.gitignore b/build/classes/.gitignore
index 0b6c10d..600bb33 100644
--- a/build/classes/.gitignore
+++ b/build/classes/.gitignore
@@ -1,3 +1,4 @@
-/controller/
/model/
/services/
+/controller/
+/testing/
diff --git a/build/classes/controller/BusController.class b/build/classes/controller/BusController.class
index 59d8dfc..82c8302 100644
Binary files a/build/classes/controller/BusController.class and b/build/classes/controller/BusController.class differ
diff --git a/build/classes/controller/FlightController.class b/build/classes/controller/FlightController.class
index 4023961..ea3fef4 100644
Binary files a/build/classes/controller/FlightController.class and b/build/classes/controller/FlightController.class differ
diff --git a/build/classes/controller/HotelController.class b/build/classes/controller/HotelController.class
index 9738d37..be4ceee 100644
Binary files a/build/classes/controller/HotelController.class and b/build/classes/controller/HotelController.class differ
diff --git a/build/classes/controller/TrainController.class b/build/classes/controller/TrainController.class
index 167c495..72c2986 100644
Binary files a/build/classes/controller/TrainController.class and b/build/classes/controller/TrainController.class differ
diff --git a/src/controller/BusController.java b/src/controller/BusController.java
index f1f8372..2e78db4 100644
--- a/src/controller/BusController.java
+++ b/src/controller/BusController.java
@@ -10,6 +10,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import model.Bus;
+import services.FareCalculator;
+
@WebServlet(urlPatterns= {"/bus"})
public class BusController extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -28,7 +31,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-/*
+
int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
String bustype=request.getParameter("bustype");
@@ -72,6 +75,6 @@ else if(bustype.equals("nonacsemisleeper")) {
request.setAttribute("busfare", rate);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/busView.jsp");
dispatcher.forward(request, response);
-*/ }
+ }
}
diff --git a/src/controller/FlightController.java b/src/controller/FlightController.java
index 7760e3c..645d836 100644
--- a/src/controller/FlightController.java
+++ b/src/controller/FlightController.java
@@ -10,6 +10,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import model.Flight;
+import services.FareCalculator;
+
@WebServlet("/flight")
@@ -29,7 +32,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-/* int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
+ int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
String classtype=request.getParameter("class");
String from=request.getParameter("from");
String to=request.getParameter("to");
@@ -59,6 +62,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
request.setAttribute("flightfare", rate);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/flightView.jsp");
dispatcher.forward(request, response);
- */}
+ }
}
diff --git a/src/controller/HotelController.java b/src/controller/HotelController.java
index 0c39e3b..14e58ec 100644
--- a/src/controller/HotelController.java
+++ b/src/controller/HotelController.java
@@ -12,8 +12,8 @@
-/*import model.Hotel;
-import services.FareCalculator;*/
+import model.Hotel;
+import services.FareCalculator;
@@ -33,7 +33,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-/* int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
+ int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
String roomtype=request.getParameter("roomtype");
String occupancy=request.getParameter("occupancy");
String from=request.getParameter("from");
@@ -67,6 +67,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/hotelOutputView.jsp");
dispatcher.forward(request, response);
-*/ }
+ }
}
diff --git a/src/controller/TrainController.java b/src/controller/TrainController.java
index dcc07df..3764d7e 100644
--- a/src/controller/TrainController.java
+++ b/src/controller/TrainController.java
@@ -10,6 +10,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import model.Train;
+import services.FareCalculator;
+
/**
* Servlet implementation class TrainController
@@ -31,7 +34,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-/* int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
+ int numberOfPersons=Integer.parseInt(request.getParameter("persons"));
String berth=request.getParameter("berth");
String date=request.getParameter("to");
System.out.println(numberOfPersons);
@@ -68,6 +71,6 @@ else if(berth.equals("nonac")) {
request.setAttribute("trainfare", trainfare);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/trainView.jsp");
dispatcher.forward(request, response);
- */}
+ }
}
diff --git a/src/model/Bus.java b/src/model/Bus.java
index 430ca5d..a30df09 100644
--- a/src/model/Bus.java
+++ b/src/model/Bus.java
@@ -1,3 +1,42 @@
package model;
-// Type your code
+import java.time.LocalDate;
+
+public class Bus{
+ private int noOfPersons;
+ private String busType;
+ private int rates;
+ private LocalDate date;
+ public Bus(int noOfPersons, int rates, String busType, LocalDate date) {
+ super();
+ this.noOfPersons = noOfPersons;
+ this.busType = busType;
+ this.rates = rates;
+ this.date = date;
+ }
+ public int getNoOfPersons() {
+ return noOfPersons;
+ }
+ public void setNoOfPersons(int noOfPersons) {
+ this.noOfPersons = noOfPersons;
+ }
+ public String getBusType() {
+ return busType;
+ }
+ public void setBusType(String busType) {
+ this.busType = busType;
+ }
+ public int getRates() {
+ return rates;
+ }
+ public void setRates(int rates) {
+ this.rates = rates;
+ }
+ public LocalDate getDate() {
+ return date;
+ }
+ public void setDate(LocalDate date) {
+ this.date = date;
+ }
+
+}
diff --git a/src/model/Flight.java b/src/model/Flight.java
index 9ac54b5..4992d3f 100644
--- a/src/model/Flight.java
+++ b/src/model/Flight.java
@@ -1,3 +1,59 @@
package model;
-//Type your code
\ No newline at end of file
+import java.time.LocalDate;
+
+public class Flight {
+ private int noOfPersons;
+ private String classType;
+ private int rates;
+ private LocalDate from;
+ private LocalDate to;
+ private String triptype;
+ public int getRates() {
+ return rates;
+ }
+ public void setRates(int rates) {
+ this.rates = rates;
+ }
+ public Flight(int noOfPersons, int rates,String classType, LocalDate from, LocalDate to, String triptype) {
+ this.noOfPersons = noOfPersons;
+ this.classType = classType;
+ this.rates = rates;
+ this.from = from;
+ this.to = to;
+ this.triptype = triptype;
+ }
+ public int getNoOfPersons() {
+ return noOfPersons;
+ }
+ public void setNoOfPersons(int noOfPersons) {
+ this.noOfPersons = noOfPersons;
+ }
+ public String getClassType() {
+ return classType;
+ }
+ public void setClassType(String classType) {
+ this.classType = classType;
+ }
+ public LocalDate getFrom() {
+ return from;
+ }
+ public void setFrom(LocalDate from) {
+ this.from = from;
+ }
+ public LocalDate getTo() {
+ return to;
+ }
+ public void setTo(LocalDate to) {
+ this.to = to;
+ }
+ public String getTriptype() {
+ return triptype;
+ }
+ public void setTriptype(String triptype) {
+ this.triptype = triptype;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/src/model/Hotel.java b/src/model/Hotel.java
index b21180d..02f2cfe 100644
--- a/src/model/Hotel.java
+++ b/src/model/Hotel.java
@@ -1,2 +1,58 @@
package model;
-// Type your code
\ No newline at end of file
+
+import java.time.LocalDate;
+
+public class Hotel{
+ private int noOfPersons;
+ private String roomType;
+ private int rates;
+ private String occupancy;
+ private LocalDate fromdate;
+ private LocalDate todate;
+ public Hotel(int noOfPersons, String roomType, int rates, String occupancy, LocalDate fromdate, LocalDate todate) {
+ this.noOfPersons = noOfPersons;
+ this.roomType = roomType;
+ this.rates = rates;
+ this.occupancy = occupancy;
+ this.fromdate = fromdate;
+ this.todate = todate;
+ }
+ public int getNoOfPersons() {
+ return noOfPersons;
+ }
+ public void setNoOfPersons(int noOfPersons) {
+ this.noOfPersons = noOfPersons;
+ }
+ public String getRoomType() {
+ return roomType;
+ }
+ public void setRoomType(String roomType) {
+ this.roomType = roomType;
+ }
+ public int getRates() {
+ return rates;
+ }
+ public void setRates(int rates) {
+ this.rates = rates;
+ }
+ public String getOccupancy() {
+ return occupancy;
+ }
+ public void setOccupancy(String occupancy) {
+ this.occupancy = occupancy;
+ }
+ public LocalDate getFromdate() {
+ return fromdate;
+ }
+ public void setFromdate(LocalDate fromdate) {
+ this.fromdate = fromdate;
+ }
+ public LocalDate getTodate() {
+ return todate;
+ }
+ public void setTodate(LocalDate todate) {
+ this.todate = todate;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/model/Train.java b/src/model/Train.java
index b21180d..2805e98 100644
--- a/src/model/Train.java
+++ b/src/model/Train.java
@@ -1,2 +1,42 @@
package model;
-// Type your code
\ No newline at end of file
+
+import java.time.LocalDate;
+
+public class Train{
+ private int noOfPersons;
+ private String berth;
+ private int rates;
+ private LocalDate date;
+ public Train(int noOfPersons, int rates, String berth, LocalDate date) {
+ this.noOfPersons = noOfPersons;
+ this.berth = berth;
+ this.rates = rates;
+ this.date = date;
+ }
+ public int getNoOfPersons() {
+ return noOfPersons;
+ }
+ public void setNoOfPersons(int noOfPersons) {
+ this.noOfPersons = noOfPersons;
+ }
+ public String getBerth() {
+ return berth;
+ }
+ public void setBerth(String berth) {
+ this.berth = berth;
+ }
+ public int getRates() {
+ return rates;
+ }
+ public void setRates(int rates) {
+ this.rates = rates;
+ }
+ public LocalDate getDate() {
+ return date;
+ }
+ public void setDate(LocalDate date) {
+ this.date = date;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/services/Booking.java b/src/services/Booking.java
index fe2c822..287e1aa 100644
--- a/src/services/Booking.java
+++ b/src/services/Booking.java
@@ -1,4 +1,8 @@
package services;
-// Type your code
+public class Booking {
+ public double booking(int noOfPersons,int rates) {
+ return noOfPersons * rates;
+ }
+}
diff --git a/src/services/FareCalculator.java b/src/services/FareCalculator.java
index 6d38ab5..2da29f4 100644
--- a/src/services/FareCalculator.java
+++ b/src/services/FareCalculator.java
@@ -1,3 +1,44 @@
package services;
-// Type your code
\ No newline at end of file
+import model.Bus;
+import model.Flight;
+import model.Hotel;
+import model.Train;
+
+public class FareCalculator extends Booking{
+ public double book(Hotel hotel) {
+ if (hotel.getNoOfPersons() == 1)
+ hotel.setOccupancy("single");
+ else if (hotel.getNoOfPersons() >= 3) {
+ String msg=String.format("%d Double Occupancy and %d Single Occupancy", (int)hotel.getNoOfPersons()/2,hotel.getNoOfPersons()%2);
+ hotel.setOccupancy(msg);
+ }
+ if(hotel.getFromdate() != null && hotel.getTodate() != null && hotel.getFromdate().isBefore(hotel.getTodate())) {
+ return super.booking(hotel.getNoOfPersons(), hotel.getRates());
+ }
+ else {
+ System.out.println("Invalid Date");
+ return 0.0;
+ }
+ }
+ public double book(Flight flight) {
+ if(flight.getFrom() != null && flight.getTo() != null && flight.getFrom().isBefore(flight.getTo())) {
+ if (flight.getTriptype().equals("one-way"))
+ return super.booking(flight.getNoOfPersons(),flight.getRates());
+ else
+ return 2*super.booking(flight.getNoOfPersons(),flight.getRates());
+ }
+ else {
+ System.out.println("Invalid Date");
+ return 0.0;
+ }
+
+ }
+ public double book(Train train) {
+ return super.booking(train.getNoOfPersons(), train.getRates());
+ }
+ public double book(Bus bus) {
+ return super.booking(bus.getNoOfPersons(), bus.getRates());
+ }
+
+}
\ No newline at end of file
diff --git a/src/testing/TestBooking.java b/src/testing/TestBooking.java
index a729b9b..f69da37 100644
--- a/src/testing/TestBooking.java
+++ b/src/testing/TestBooking.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import static org.junit.Assert.*;
import org.junit.Test;
@@ -23,4 +23,4 @@ public void testBookingMethod() {
}
}
}
-*/
+
diff --git a/src/testing/TestBus.java b/src/testing/TestBus.java
index 90df968..1b0b5af 100644
--- a/src/testing/TestBus.java
+++ b/src/testing/TestBus.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import model.Bus;
import java.time.LocalDate;
@@ -60,4 +60,4 @@ public void testSetDate() {
}
}
-*/
+
diff --git a/src/testing/TestFareCalculator.java b/src/testing/TestFareCalculator.java
index 91dddec..d518521 100644
--- a/src/testing/TestFareCalculator.java
+++ b/src/testing/TestFareCalculator.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+//Uncomment the below code to test your application
import static org.junit.Assert.*;
@@ -89,4 +89,4 @@ public void testTrainMethod() {
}
}
}
-*/
+
diff --git a/src/testing/TestFlight.java b/src/testing/TestFlight.java
index 90127f6..6d7d675 100644
--- a/src/testing/TestFlight.java
+++ b/src/testing/TestFlight.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import model.Flight;
import java.time.LocalDate;
@@ -62,4 +62,4 @@ public void testSetDate() {
}
}
-*/
+
diff --git a/src/testing/TestHotel.java b/src/testing/TestHotel.java
index 2d3565b..c9da77b 100644
--- a/src/testing/TestHotel.java
+++ b/src/testing/TestHotel.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import model.Hotel;
import java.time.LocalDate;
@@ -62,4 +62,4 @@ public void testSetDate() {
}
}
-*/
+
diff --git a/src/testing/TestRunner.java b/src/testing/TestRunner.java
index f26d18d..0180da2 100644
--- a/src/testing/TestRunner.java
+++ b/src/testing/TestRunner.java
@@ -1,11 +1,13 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
+import junit.framework.TestSuite;
+
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(TestSuite.class);
@@ -17,4 +19,4 @@ public static void main(String[] args) {
System.out.println(result.wasSuccessful());
}
}
-*/
+
diff --git a/src/testing/TestSuite.java b/src/testing/TestSuite.java
index a48a79e..42f3770 100644
--- a/src/testing/TestSuite.java
+++ b/src/testing/TestSuite.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -12,4 +12,4 @@
public class TestSuite {
}
-*/
+
diff --git a/src/testing/TestTrain.java b/src/testing/TestTrain.java
index 688df5c..d77ab2f 100644
--- a/src/testing/TestTrain.java
+++ b/src/testing/TestTrain.java
@@ -1,6 +1,6 @@
package testing;
-/* Uncomment the below code to test your application
+// Uncomment the below code to test your application
import model.Train;
import java.time.LocalDate;
@@ -64,4 +64,4 @@ public void testSetDate() {
}
}
-*/
+