Advertisement
Valantina

BestPlaneTickets/Ex/27.07.2019/Java

Jul 29th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_BestPlaneTickets {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int lowestMinsStay = Integer.MAX_VALUE;
  8.         String bestTicketNumber = "";
  9.         double bestTicketNoTransferPrice = Double.MAX_VALUE;
  10.  
  11.         String ticketNumber = scanner.nextLine();
  12.         while (!ticketNumber.equals("End")) {
  13.             double ticketPrice = Double.parseDouble(scanner.nextLine());
  14.             int minutesStay = Integer.parseInt(scanner.nextLine());
  15.  
  16.             ticketPrice = ticketPrice * 1.96;
  17.             if (minutesStay < lowestMinsStay) {
  18.                 bestTicketNoTransferPrice = ticketPrice;
  19.                 bestTicketNumber = ticketNumber;
  20.                 lowestMinsStay = minutesStay;
  21.             }
  22.  
  23.             ticketNumber = scanner.nextLine();
  24.         }
  25.  
  26.         System.out.printf("Ticket found for flight %s costs %.2f leva with %dh %dm stay",
  27.                 bestTicketNumber,
  28.                 bestTicketNoTransferPrice,
  29.                 lowestMinsStay / 60,
  30.                 lowestMinsStay % 60);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement