Question
Update Flight Fare for a Flight Zaro Flight System wants to automate the process in their organization.As a start up, they need to automate the
Update Flight Fare for a Flight
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 details. Help them to develop a software to update the flight fare based on flight Id.
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 boolean updateFlightFare(int flightId,double flightFare) -This method should take flight Id and the updated flight fare as parameters and update the fare of the flight id provided in the database. If updated, return true.Else return false.
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, invoke the updateFlightFare method.If it returns true, display the message, "Flight Fare updated successfully".Else, display "Flight fare not updated.Check for the ID".
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 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{ 3 public static void main(String[] args){ 4 Scanner 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 28 con = 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started