diff --git a/build/classes/.gitignore b/build/classes/.gitignore index 0b6c10d..aa6d612 100644 --- a/build/classes/.gitignore +++ b/build/classes/.gitignore @@ -1,3 +1,4 @@ /controller/ /model/ /services/ +/testing/ diff --git a/build/classes/controller/BusController.class b/build/classes/controller/BusController.class index 59d8dfc..5a749df 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..99bcd3a 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..ed2e121 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..ede66d7 100644 --- a/src/controller/BusController.java +++ b/src/controller/BusController.java @@ -1,6 +1,7 @@ package controller; import java.io.IOException; + import java.time.LocalDate; import javax.servlet.RequestDispatcher; @@ -10,6 +11,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import model.Bus; +import services.*; + @WebServlet(urlPatterns= {"/bus"}) public class BusController extends HttpServlet { private static final long serialVersionUID = 1L; @@ -28,9 +32,8 @@ 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 bustype=request.getParameter("bustype"); String date=request.getParameter("start"); System.out.println(numberOfPersons); @@ -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..67e2e97 100644 --- a/src/controller/HotelController.java +++ b/src/controller/HotelController.java @@ -10,6 +10,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import model.Hotel; +import services.FareCalculator; + /*import model.Hotel; @@ -33,7 +36,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 +70,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..265a67a 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); @@ -55,7 +58,7 @@ else if(berth.equals("nonac")) { } LocalDate start=LocalDate.parse(date); - Train train=new Train(numberOfPersons,rates,berth,start); + Train train=new Train(numberOfPersons,berth,rates,start); train.setNoOfPersons(numberOfPersons); train.setRates(rates); train.setBerth(berth);; @@ -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..b23cb27 100644 --- a/src/model/Bus.java +++ b/src/model/Bus.java @@ -1,3 +1,48 @@ package model; +import java.time.LocalDate; + // Type your code + +public class Bus{ + private int noOfPersons; + private String busType; + private int rates; + private LocalDate date; + + + //Getter-Setter + 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; + } + + //CONSTRUCTOR + public Bus(int noOfPersons, String busType, int rates, LocalDate date) { + this.noOfPersons = noOfPersons; + this.busType = busType; + this.rates = rates; + this.date = date; + } + +} \ No newline at end of file diff --git a/src/model/Flight.java b/src/model/Flight.java index 9ac54b5..6210b05 100644 --- a/src/model/Flight.java +++ b/src/model/Flight.java @@ -1,3 +1,98 @@ package model; -//Type your code \ No newline at end of file +import java.time.LocalDate; + +//Type your code + +public class Flight{ + private int noOfPersons; + private String classType; + private int rates; + private LocalDate from; + private LocalDate to; + private String 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; + } + + + + 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; + } + +} \ No newline at end of file diff --git a/src/model/Hotel.java b/src/model/Hotel.java index b21180d..4711a73 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 +// Type your code + +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 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; + } + + 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; + } + +} \ No newline at end of file diff --git a/src/model/Train.java b/src/model/Train.java index b21180d..d9b5e41 100644 --- a/src/model/Train.java +++ b/src/model/Train.java @@ -1,2 +1,45 @@ package model; -// Type your code \ No newline at end of file + +import java.time.LocalDate; + +// Type your code + +public class Train{ + private int noOfPersons; + private String berth; + private int rates; + private LocalDate 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; + } + + public Train(int noOfPersons, String berth, int rates, LocalDate date) { + this.noOfPersons = noOfPersons; + this.berth = berth; + this.rates = rates; + this.date = date; + } + +} \ No newline at end of file diff --git a/src/services/Booking.java b/src/services/Booking.java index fe2c822..4f8a98e 100644 --- a/src/services/Booking.java +++ b/src/services/Booking.java @@ -1,4 +1,14 @@ package services; // Type your code +/*Create a class called as Booking inside the service package. + Create a method public double booking(int noOfPersons,int rates). + The booking method should return the total rate.*/ +public class Booking{ + + public double booking(int noOfPersons,int rates) { + return noOfPersons*rates; + } + +} \ No newline at end of file diff --git a/src/services/FareCalculator.java b/src/services/FareCalculator.java index 6d38ab5..d4cbd2f 100644 --- a/src/services/FareCalculator.java +++ b/src/services/FareCalculator.java @@ -1,3 +1,64 @@ package services; -// Type your code \ No newline at end of file +import model.*; + +// Type your code + +/*Create a class called as FareCalculator. +FareCalculator should extend the Booking Class and should use the booking method defined in Booking Class. +FareCalculator has 4 methods as mentioned below. +public double book(Hotel hotel) +public double book(Flight flight) +public double book(Train train) +public double book(Bus bus) +Each method should return the user details and total fare + + +In the public double book(Hotel hotel)method inside the FareCalculator. +Check-In date should be less than Check-Out date. +Single occupancy can be given only for 1 guest. +If there are 3 guests then the rooms alloted should be 1 Double Occupancy room and 1 Single Occupancy. +Calculate the total fare after these conditions are met. +*/ + public class FareCalculator extends Booking{ + + double fare=0; + + public double book(Hotel hotel) { + if(hotel.getFromdate().isBefore(hotel.getTodate())) + { + if(hotel.getNoOfPersons()==1) + hotel.setOccupancy("Single"); + else if(hotel.getNoOfPersons()==3) + hotel.setOccupancy("Double "+"Single"); + fare= hotel.getNoOfPersons()*hotel.getRates(); + } + return fare; + } + + + public double book(Flight flight) { + if(flight.getTriptype()=="one-way") { + fare=flight.getNoOfPersons()*flight.getRates(); + return fare; + } + else if(flight.getTriptype()=="round") { + if(flight.getFrom().isBefore(flight.getTo())) { + fare=flight.getNoOfPersons()*flight.getRates(); + return fare; + } + System.out.println("Enter valid date"); + } + return fare; + } + + + public double book(Train train) { + return booking(train.getNoOfPersons(),train.getRates()); + } + + + public double book(Bus bus) { + return booking(bus.getNoOfPersons(),bus.getRates()); + } + } \ No newline at end of file