Advertisement
Guest User

TripPlanner

a guest
Jan 22nd, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TripPlanner {
  4.     public static void main(String[] args) {
  5.         intro();
  6.         System.out.println("\n***********\n");
  7.  
  8.         durationAndBudget();
  9.         System.out.println("\n***********\n");
  10.  
  11.         timeDifference();
  12.         System.out.println("\n***********\n");
  13.  
  14.         destinationArea();
  15.         System.out.println("\n***********\n");
  16.  
  17.         destinationDistance();
  18.     }
  19.  
  20.     public static void intro() {
  21.         Scanner input = new Scanner(System.in);
  22.  
  23.         System.out.println("Welcome to Vacation planner!");
  24.         System.out.print("What is your name? ");
  25.         String name = input.nextLine();
  26.  
  27.         System.out.print("Nice to meet you " + name + ", where are you travelling to? ");
  28.         String destination = input.nextLine();
  29.  
  30.         System.out.println("Great! " + destination + " sounds like a great trip");
  31.     }
  32.  
  33.     public static void durationAndBudget() {
  34.         Scanner input = new Scanner(System.in);
  35.  
  36.         System.out.print("How many days are you going to spend travelling? ");
  37.         int durationDays = input.nextInt();
  38.  
  39.         int durationHours = durationDays * 24;
  40.         int durationMinutes = durationHours * 60;
  41.  
  42.         System.out.print("How much money, in USD, are you planning to spend on your trip? ");
  43.         double budgetTotal = input.nextDouble();
  44.  
  45.         double budgetDaily = Math.round(budgetTotal / durationDays * 100d) / 100d;
  46.  
  47.         System.out.print("What is the three letter currency symbol for your travel destination? ");
  48.         String currencySymbol = input.next();
  49.  
  50.         System.out.print("How many " + currencySymbol + " are there in 1 USD? ");
  51.         double currencyConversion = input.nextDouble();
  52.  
  53.         double budgetTotalConverted = Math.round(budgetTotal * currencyConversion * 100d) / 100d;
  54.         double budgetDailyConverted = Math.round(budgetDaily * currencyConversion * 100d) / 100d;
  55.  
  56.         System.out.println("\nIf you are travelling for " + durationDays + " days that is the same as " + durationHours + " hours or " + durationMinutes + " minutes");
  57.         System.out.println("If you are going to spend $" + budgetTotal + " USD that means per day you can spend up to $" + budgetDaily + " USD ");
  58.         System.out.println("Your total budget in " + currencySymbol + " is " + budgetTotalConverted + " " + currencySymbol + ", which per day is " + budgetDailyConverted + " " + currencySymbol);
  59.     }
  60.  
  61.     public static void timeDifference() {
  62.         Scanner input = new Scanner(System.in);
  63.  
  64.         System.out.print("What is the time difference, in hours, between your home and you destination? ");
  65.         int timeDifference = input.nextInt();
  66.  
  67.         int timeMidnight = (timeDifference + 24) % 24;
  68.         int timeNoon = (timeDifference + 12) % 24;
  69.  
  70.         System.out.println("That means that when it is midnight at home it will be " + timeMidnight + ":00 in your travel destination");
  71.         System.out.println("and when it is noon at home it will be " + timeNoon + ":00");
  72.     }
  73.  
  74.     public static void destinationArea() {
  75.         Scanner input = new Scanner(System.in);
  76.  
  77.         System.out.print("What is the square area of your destination country in km2? ");
  78.         double destinationAreaKm = input.nextDouble();
  79.  
  80.         double destinationAreaMiles = Math.round(destinationAreaKm * 0.3861);
  81.  
  82.         System.out.println("In miles2 that is " + (int) destinationAreaMiles);
  83.     }
  84.  
  85.     public static void destinationDistance() {
  86.         Scanner input = new Scanner(System.in);
  87.  
  88.         System.out.print("What is the longitude of your home? ");
  89.         double homeLong = Math.toRadians(input.nextDouble());
  90.  
  91.         System.out.print("What is the latitude of your home? ");
  92.         double homeLat = Math.toRadians(input.nextDouble());
  93.  
  94.         System.out.print("What is the longitude of your destination? ");
  95.         double destinationLong = Math.toRadians(input.nextDouble());
  96.  
  97.         System.out.print("What is the latitude of your destination? ");
  98.         double destinationLat = Math.toRadians(input.nextDouble());
  99.  
  100.         int earthRadius = 6378;
  101.         double destinationDistance = 2 * earthRadius * Math.asin(Math.sqrt(Math.sin((destinationLat - homeLat) / 2) * Math.sin((destinationLat - homeLat) / 2) + Math.cos(homeLat) * Math.cos(destinationLat) * Math.sin((destinationLong - homeLong) / 2) * Math.sin((destinationLong - homeLong) / 2)));
  102.  
  103.         System.out.println("The distance between your home and the destination is " + Math.round(destinationDistance) + " km");
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement