diff --git a/.classpath b/.classpath index 2846539..20c137d 100644 --- a/.classpath +++ b/.classpath @@ -8,10 +8,6 @@ - - - - - + diff --git a/build/classes/.gitignore b/build/classes/.gitignore index 0b6c10d..365864b 100644 --- a/build/classes/.gitignore +++ b/build/classes/.gitignore @@ -1,3 +1,2 @@ /controller/ -/model/ /services/ diff --git a/build/classes/controller/BusController.class b/build/classes/controller/BusController.class index 59d8dfc..90c0731 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..6768faf 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/build/classes/model/Bus.class b/build/classes/model/Bus.class new file mode 100644 index 0000000..e13ef31 Binary files /dev/null and b/build/classes/model/Bus.class differ diff --git a/build/classes/model/Flight.class b/build/classes/model/Flight.class new file mode 100644 index 0000000..abfd9ac Binary files /dev/null and b/build/classes/model/Flight.class differ diff --git a/build/classes/model/Hotel.class b/build/classes/model/Hotel.class new file mode 100644 index 0000000..f6066bb Binary files /dev/null and b/build/classes/model/Hotel.class differ diff --git a/build/classes/model/Train.class b/build/classes/model/Train.class new file mode 100644 index 0000000..52fa7af Binary files /dev/null and b/build/classes/model/Train.class differ diff --git a/build/classes/testing/TestBus.class b/build/classes/testing/TestBus.class new file mode 100644 index 0000000..6325d93 Binary files /dev/null and b/build/classes/testing/TestBus.class differ diff --git a/src/controller/BusController.java b/src/controller/BusController.java index f1f8372..45381de 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"); @@ -58,7 +61,7 @@ else if(bustype.equals("nonacsemisleeper")) { LocalDate start=LocalDate.parse(date); - Bus bus=new Bus(numberOfPersons,rates,bustype,start); + Bus bus=new Bus(numberOfPersons,bustype,rates,start); bus.setNoOfPersons(numberOfPersons); bus.setRates(rates); bus.setBusType(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..e182ca8 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"); @@ -45,7 +48,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) LocalDate start=LocalDate.parse(from); LocalDate end=LocalDate.parse(to); - Flight flight=new Flight(numberOfPersons,rates,classtype,start,end,triptype); + Flight flight=new Flight(numberOfPersons,classtype,rates,start,end,triptype); flight.setNoOfPersons(numberOfPersons); flight.setRates(rates); flight.setClassType(classtype); @@ -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..d6f2abc 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..fe99083 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, String busType, int rates, LocalDate date) + { + 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..2749538 100644 --- a/src/model/Flight.java +++ b/src/model/Flight.java @@ -1,3 +1,58 @@ 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 Flight(int noOfPersons,String classType, int rates, 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 int getRates() { + return rates; + } + public void setRates(int rates) { + this.rates = rates; + } + 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..159ebd0 100644 --- a/src/model/Hotel.java +++ b/src/model/Hotel.java @@ -1,2 +1,59 @@ 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 String occupancy; + private int rates; + 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 String getOccupancy() { + return occupancy; + } + public void setOccupancy(String occupancy) { + this.occupancy = occupancy; + } + public int getRates() { + return rates; + } + public void setRates(int rates) { + this.rates = rates; + } + 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..538cc9e 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.rates=rates; + this.berth=berth; + 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..ba3cb9b 100644 --- a/src/services/Booking.java +++ b/src/services/Booking.java @@ -1,4 +1,10 @@ package services; -// Type your code +public class Booking{ + public double booking(int noOfPersons,int rates) + { + double totalRate=noOfPersons*rates; + return totalRate; + } +} diff --git a/src/services/FareCalculator.java b/src/services/FareCalculator.java index 6d38ab5..de124af 100644 --- a/src/services/FareCalculator.java +++ b/src/services/FareCalculator.java @@ -1,3 +1,61 @@ package services; -// Type your code \ No newline at end of file +import java.time.LocalDate; + +import model.Bus; +import model.Flight; +import model.Hotel; +import model.Train; + +public class FareCalculator extends Booking{ + public double book(Hotel hotel) + { + LocalDate fromdate=hotel.getFromdate(); + LocalDate todate=hotel.getTodate(); + int noOfPersons=hotel.getNoOfPersons(); + int rates=hotel.getRates(); + //String occupancy=hotel.getOccupancy(); + double total=0; + if(todate.isAfter(fromdate)) + { + total= super.booking(noOfPersons, rates); + } + return total; + + } + public double book(Flight flight) + { + double total=0; + String triptype=flight.getTriptype(); + int noOfPersons=flight.getNoOfPersons(); + int rates=flight.getRates(); + LocalDate from=flight.getFrom(); + LocalDate to=flight.getTo(); + + if(triptype.equals("one-way")) + { + total=super.booking(noOfPersons, rates); + } + else + { + if(to.isAfter(from)) + total=super.booking(noOfPersons, rates); + total*=2; + } + return total; + } + public double book(Train train) + { + int noOfPersons=train.getNoOfPersons(); + int rates=train.getRates(); + double total= super.booking(noOfPersons, rates); + return total; + } + public double book(Bus bus) + { + int noOfPersons=bus.getNoOfPersons(); + int rates=bus.getRates(); + double total= super.booking(noOfPersons, rates); + return total; + } +} \ No newline at end of file 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() { } } -*/ +