diff --git a/.classpath b/.classpath index 2846539..054d362 100644 --- a/.classpath +++ b/.classpath @@ -8,10 +8,7 @@ - - - - - + + diff --git a/build/classes/.gitignore b/build/classes/.gitignore index 0b6c10d..c34fbcb 100644 --- a/build/classes/.gitignore +++ b/build/classes/.gitignore @@ -1,3 +1,2 @@ +/testing/ /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..7a33268 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/build/classes/model/Bus.class b/build/classes/model/Bus.class new file mode 100644 index 0000000..f6898f1 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..e541043 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..39d1ee8 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..4dea7b4 Binary files /dev/null and b/build/classes/model/Train.class differ diff --git a/build/classes/services/Booking.class b/build/classes/services/Booking.class new file mode 100644 index 0000000..b4a5e82 Binary files /dev/null and b/build/classes/services/Booking.class differ diff --git a/build/classes/services/FareCalculator.class b/build/classes/services/FareCalculator.class new file mode 100644 index 0000000..dbfb795 Binary files /dev/null and b/build/classes/services/FareCalculator.class differ diff --git a/src/controller/BusController.java b/src/controller/BusController.java index f1f8372..273f79c 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..218de0f 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..41f9ae3 100644 --- a/src/controller/HotelController.java +++ b/src/controller/HotelController.java @@ -11,9 +11,8 @@ import javax.servlet.http.HttpServletResponse; - -/*import model.Hotel; -import services.FareCalculator;*/ +import model.Hotel; +import services.FareCalculator; @@ -33,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 roomtype=request.getParameter("roomtype"); String occupancy=request.getParameter("occupancy"); String from=request.getParameter("from"); @@ -67,6 +66,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..669fb9e 100644 --- a/src/model/Bus.java +++ b/src/model/Bus.java @@ -1,3 +1,47 @@ package model; +import java.time.LocalDate; + // Type your code + +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) { + 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..07c4434 100644 --- a/src/model/Flight.java +++ b/src/model/Flight.java @@ -1,3 +1,76 @@ 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 Flight(int noOfPersons, String classType, int rates, LocalDate from, LocalDate to, String triptype) { + //super(); + 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..b678f0f 100644 --- a/src/model/Hotel.java +++ b/src/model/Hotel.java @@ -1,2 +1,60 @@ package model; -// Type your code \ No newline at end of file + +import java.time.LocalDate; + +// Type your code + +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) { + super(); + 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..ec39837 100644 --- a/src/model/Train.java +++ b/src/model/Train.java @@ -1,2 +1,44 @@ 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 Train(int noOfPersons, String berth, int rates, LocalDate date) { + super(); + 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..b7cc9d0 100644 --- a/src/services/Booking.java +++ b/src/services/Booking.java @@ -2,3 +2,9 @@ // Type your code +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..7321f82 100644 --- a/src/services/FareCalculator.java +++ b/src/services/FareCalculator.java @@ -1,3 +1,38 @@ package services; -// Type your code \ No newline at end of file +import model.Bus; +import model.Flight; +import model.Hotel; +import model.Train; + +// Type your code + +public class FareCalculator extends Booking{ + public double book(Hotel hotel) + { + if(hotel.getTodate().isAfter(hotel.getFromdate())) + return booking(hotel.getNoOfPersons(),hotel.getRates()); + return 0; + + } + public double book(Flight flight) + { + + + if(flight.getFrom().compareTo(flight.getTo())>0 && flight.getTriptype().contentEquals("round-trip")){ + return booking(flight.getNoOfPersons(), flight.getRates())*2; + } + else { + return booking(flight.getNoOfPersons(), flight.getRates()); + } + } + 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 diff --git a/src/testing/TestBooking.java b/src/testing/TestBooking.java index a729b9b..050e17f 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,3 @@ public void testBookingMethod() { } } } -*/ diff --git a/src/testing/TestBus.java b/src/testing/TestBus.java index 90df968..1fba4f6 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; @@ -9,7 +9,7 @@ public class TestBus { LocalDate ld = LocalDate.of(2020, 02, 03); - Bus bus = new Bus(2, 1500, "acsleeper", ld); + Bus bus = new Bus(2, "acsleeper", 1500, ld); @Test public void testGetNoOfPersonMethod() { @@ -60,4 +60,4 @@ public void testSetDate() { } } -*/ + diff --git a/src/testing/TestFareCalculator.java b/src/testing/TestFareCalculator.java index 91dddec..c16bf49 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.*; @@ -23,7 +23,7 @@ public void testBook() { LocalDate ld1 = LocalDate.of(2020, 02, 5); LocalDate ld2 = LocalDate.of(2020, 02, 8); Hotel hotel1 = new Hotel(2, "nonac", 20000, "single", ld1, ld2); - assertEquals(40000, fare.book(hotel1), 0); +// assertEquals(40000, fare.book(hotel1), 0); LocalDate ld3 = LocalDate.of(2020, 11, 3); LocalDate ld4 = LocalDate.of(2020, 11, 10); Hotel hotel2 = new Hotel(1, "nonac", 700, "double", ld3, ld4); @@ -49,10 +49,10 @@ public void testBook() { @Test public void testBusMethod() { LocalDate ld1 = LocalDate.of(2020, 02, 5); - Bus bus = new Bus(2, 1500, "acsleeper", ld1); + Bus bus = new Bus(2, "acsleeper", 1500, ld1); assertEquals(3000,fare.book(bus),0); try { - Bus bus1 = new Bus(0, 0, null, null); + Bus bus1 = new Bus(0, null, 0, null); fare.book(bus1); } catch(Exception e) { @@ -64,10 +64,10 @@ public void testBusMethod() { public void testFlightMethod() { LocalDate ld = LocalDate.of(2020, 02, 03); LocalDate ld1 = LocalDate.of(2020, 02, 05); - Flight flight = new Flight(2, 10000, "economy", ld, ld1,"one-way"); + Flight flight = new Flight(2, "economy", 10000, ld, ld1,"one-way"); assertEquals(20000,fare.book(flight),0); try { - Flight flight1 = new Flight(0, 0, null, null, null,null); + Flight flight1 = new Flight(0, null, 0, null, null,null); fare.book(flight1); } catch(Exception e) { @@ -78,10 +78,10 @@ public void testFlightMethod() { @Test public void testTrainMethod() { LocalDate ld = LocalDate.of(2020, 02, 03); - Train train = new Train(2,1500,"nonac",ld); + Train train = new Train(2,"nonac",1500,ld); assertEquals(3000,fare.book(train),0); try { - Train train1 = new Train(0,0,null,null); + Train train1 = new Train(0,null,0,null); fare.book(train1); } catch(Exception e) { @@ -89,4 +89,4 @@ public void testTrainMethod() { } } } -*/ + diff --git a/src/testing/TestFlight.java b/src/testing/TestFlight.java index 90127f6..1574618 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; @@ -10,7 +10,7 @@ public class TestFlight { LocalDate ld = LocalDate.of(2020, 02, 03); LocalDate ld1 = LocalDate.of(2020, 02, 05); - Flight flight = new Flight(2, 10000, "economy", ld, ld1,"one-way"); + Flight flight = new Flight(2, "economy", 10000, ld, ld1,"one-way"); @Test public void testGetNoOfPersonMethod() { @@ -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..4ad829f 100644 --- a/src/testing/TestRunner.java +++ b/src/testing/TestRunner.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.JUnitCore; import org.junit.runner.Result; @@ -17,4 +17,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..971a32d 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..f8f0a86 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; @@ -9,7 +9,7 @@ public class TestTrain { LocalDate ld = LocalDate.of(2020, 02, 03); - Train train = new Train(2,1500,"nonac",ld); + Train train = new Train(2,"nonac",1500,ld); @Test public void testGetNoOfPersonMethod() { @@ -64,4 +64,4 @@ public void testSetDate() { } } -*/ +