|
| 1 | +import java.util.Scanner; |
| 2 | + |
| 3 | +public class Flight { |
| 4 | + private String flightNumber; |
| 5 | + private String sourceLocation; |
| 6 | + private String destination; |
| 7 | + private int numberOfTickets; |
| 8 | + private double ticketFare; |
| 9 | + |
| 10 | + public void inputFlightData() { |
| 11 | + Scanner scanner = new Scanner(System.in); |
| 12 | + System.out.print("Enter Flight Number: "); |
| 13 | + flightNumber = scanner.nextLine(); |
| 14 | + System.out.print("Enter Source Location: "); |
| 15 | + sourceLocation = scanner.nextLine(); |
| 16 | + System.out.print("Enter Destination: "); |
| 17 | + destination = scanner.nextLine(); |
| 18 | + System.out.print("Enter Number of Tickets: "); |
| 19 | + numberOfTickets = scanner.nextInt(); |
| 20 | + System.out.print("Enter Ticket Fare: "); |
| 21 | + ticketFare = scanner.nextDouble(); |
| 22 | + } |
| 23 | + |
| 24 | + public double calculateTicketAmount() { |
| 25 | + double ticketAmount = numberOfTickets * ticketFare; |
| 26 | + double tax = 0.18 * ticketAmount; |
| 27 | + double discount = 0.05 * ticketAmount; |
| 28 | + return ticketAmount + tax - discount; |
| 29 | + } |
| 30 | + |
| 31 | + public void printTicketDetails() { |
| 32 | + System.out.println("Flight Number: " + flightNumber); |
| 33 | + System.out.println("Source Location: " + sourceLocation); |
| 34 | + System.out.println("Destination: " + destination); |
| 35 | + System.out.println("Number of Tickets: " + numberOfTickets); |
| 36 | + System.out.println("Ticket Fare: " + ticketFare); |
| 37 | + System.out.println("Total Amount Payable: " + calculateTicketAmount()); |
| 38 | + } |
| 39 | + |
| 40 | + public static void main(String[] args) { |
| 41 | + Flight flight = new Flight(); |
| 42 | + flight.inputFlightData(); |
| 43 | + flight.printTicketDetails(); |
| 44 | + } |
| 45 | +} |
0 commit comments