Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Retrieve Flights Based on Source and Destination Zaro Flight System wants to automate the process in their organization.As a start up, they need to automate

Retrieve Flights Based on Source and Destination

Zaro Flight System wants to automate the process in their organization.As a start up, they need to automate the flight management system. They have an application to add flight and view flight based on flight id. Help them to develop a software to view the flight based on source and destination.

You are provided with a public class Flight with following private attribute :

int flightId

String source

String destination

int noOfSeats

double flightFare

Appropriate setter and getter are written.

A public 5 argument constructor with arguments - flightId, source, destination, noOfSeats and flightFare is also provided.

Use Database for manipulation. Assume Flight details are already available in the database.

Create a class FlightManagementSystem which has the following method.

public ArrayList viewFlightsBySourceDestination(String source,String destination)-This method should accept a Source and a destination as parameter and retrieve allthe filights with the given source and destination fromthe database. Return these details as ArrayList.

To connect to the database you are provided with database.properties file and DB.java file.

Create a class Main which has main method to perform the above operation.

In main method, when viewFlightsBySourceDestination method is invoked and if it returns a Flight list , display the flight details as

Flight ID : xxx

Source : source name

Destination : destination name

No of seats : xxx

Flight Fare : xxx

........

..........

......

If no flight is available in the list, the output should be "No flights available for the given source and destination".

To execute on your machine, you can make the necessary changes to the values of connection url, username and password in the database.propertiesfile.

Requested files

Flight.java

1

2 public class Flight {

3

4 private int flightId;

5 private String source;

6 private String destination;

7 private int noOfSeats;

8 private double flightFare;

9 public int getFlightId() {

10 return flightId;

11 }

12 public void setFlightId(int flightId) {

13 this.flightId = flightId;

14 }

15 public String getSource() {

16 return source;

17 }

18 public void setSource(String source) {

19 this.source = source;

20 }

21 public String getDestination() {

22 return destination;

23 }

24 public void setDestination(String destination) {

25 this.destination = destination;

26 }

27 public int getNoOfSeats() {

28 return noOfSeats;

29 }

30 public void setNoOfSeats(int noOfSeats) {

31 this.noOfSeats = noOfSeats;

32 }

33 public double getFlightFare() {

34 return flightFare;

35 }

36 public void setFlightFare(double flightFare) {

37 this.flightFare = flightFare;

38 }

39 public Flight(int flightId, String source, String destination,

40 int noOfSeats, double flightFare) {

41 super();

42 this.flightId = flightId;

43 this.source = source;

44 this.destination = destination;

45 this.noOfSeats = noOfSeats;

46 this.flightFare = flightFare;

47 }

48

49

50

51 }

52

FlightManagementSystem.java

Main.java

1 import java.util.*;

2 public class Main{

3public static void main(String[] args){

4Scanner sc=new Scanner(System.in);

5

6}

7 }

DB.java

1

2

3 import java.io.FileInputStream;

4 import java.io.IOException;

5 import java.sql.Connection;

6 import java.sql.DriverManager;

7 import java.sql.SQLException;

8 import java.util.Properties;

9

10 public class DB {

11

12 private static Connection con = null;

13 private static Properties props = new Properties();

14

15

16//ENSURE YOU DON'T CHANGE THE BELOW CODE WHEN YOU SUBMIT

17 public static Connection getConnection() throws ClassNotFoundException, SQLException {

18 try{

19

20 FileInputStream fis = null;

21 fis = new FileInputStream("database.properties");

22 props.load(fis);

23

24 // load the Driver Class

25 Class.forName(props.getProperty("DB_DRIVER_CLASS"));

26

27 // create the connection now

28con = DriverManager.getConnection(props.getProperty("DB_URL"),props.getProperty("DB_USERNAME"),props.getProperty("DB_PASSWORD"));

29 }

30 catch(IOException e){

31 e.printStackTrace();

32 }

33 return con;

34 }

35 }

36

database.properties

1 #IF NEEDED, YOU CAN MODIFY THIS PROPERTY FILE

2 #ENSURE YOU ARE NOT CHANGING THE NAME OF THE PROPERTY

3 #YOU CAN CHANGE THE VALUE OF THE PROPERTY

4 #LOAD THE DETAILS OF DRIVER CLASS, URL, USERNAME AND PASSWORD IN DB.java using this properties file only.

5 #Do not hard code the values in DB.java.

6 7 DB_DRIVER_CLASS=oracle.jdbc.driver.OracleDriver 8 D..:@127.0.0.1:1521:XE 9 DB_USERNAME=${sys:db_username} 10 DB_PASSWORD=${sys:db_password} 11 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What effects does expanded trade have on the environment?

Answered: 1 week ago