Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TripPlanner {
- public static void main(String[] args) {
- intro();
- System.out.println("\n***********\n");
- durationAndBudget();
- System.out.println("\n***********\n");
- timeDifference();
- System.out.println("\n***********\n");
- destinationArea();
- System.out.println("\n***********\n");
- destinationDistance();
- }
- public static void intro() {
- Scanner input = new Scanner(System.in);
- System.out.println("Welcome to Vacation planner!");
- System.out.print("What is your name? ");
- String name = input.nextLine();
- System.out.print("Nice to meet you " + name + ", where are you travelling to? ");
- String destination = input.nextLine();
- System.out.println("Great! " + destination + " sounds like a great trip");
- }
- public static void durationAndBudget() {
- Scanner input = new Scanner(System.in);
- System.out.print("How many days are you going to spend travelling? ");
- int durationDays = input.nextInt();
- int durationHours = durationDays * 24;
- int durationMinutes = durationHours * 60;
- System.out.print("How much money, in USD, are you planning to spend on your trip? ");
- double budgetTotal = input.nextDouble();
- double budgetDaily = Math.round(budgetTotal / durationDays * 100d) / 100d;
- System.out.print("What is the three letter currency symbol for your travel destination? ");
- String currencySymbol = input.next();
- System.out.print("How many " + currencySymbol + " are there in 1 USD? ");
- double currencyConversion = input.nextDouble();
- double budgetTotalConverted = Math.round(budgetTotal * currencyConversion * 100d) / 100d;
- double budgetDailyConverted = Math.round(budgetDaily * currencyConversion * 100d) / 100d;
- System.out.println("\nIf you are travelling for " + durationDays + " days that is the same as " + durationHours + " hours or " + durationMinutes + " minutes");
- System.out.println("If you are going to spend $" + budgetTotal + " USD that means per day you can spend up to $" + budgetDaily + " USD ");
- System.out.println("Your total budget in " + currencySymbol + " is " + budgetTotalConverted + " " + currencySymbol + ", which per day is " + budgetDailyConverted + " " + currencySymbol);
- }
- public static void timeDifference() {
- Scanner input = new Scanner(System.in);
- System.out.print("What is the time difference, in hours, between your home and you destination? ");
- int timeDifference = input.nextInt();
- int timeMidnight = (timeDifference + 24) % 24;
- int timeNoon = (timeDifference + 12) % 24;
- System.out.println("That means that when it is midnight at home it will be " + timeMidnight + ":00 in your travel destination");
- System.out.println("and when it is noon at home it will be " + timeNoon + ":00");
- }
- public static void destinationArea() {
- Scanner input = new Scanner(System.in);
- System.out.print("What is the square area of your destination country in km2? ");
- double destinationAreaKm = input.nextDouble();
- double destinationAreaMiles = Math.round(destinationAreaKm * 0.3861);
- System.out.println("In miles2 that is " + (int) destinationAreaMiles);
- }
- public static void destinationDistance() {
- Scanner input = new Scanner(System.in);
- System.out.print("What is the longitude of your home? ");
- double homeLong = Math.toRadians(input.nextDouble());
- System.out.print("What is the latitude of your home? ");
- double homeLat = Math.toRadians(input.nextDouble());
- System.out.print("What is the longitude of your destination? ");
- double destinationLong = Math.toRadians(input.nextDouble());
- System.out.print("What is the latitude of your destination? ");
- double destinationLat = Math.toRadians(input.nextDouble());
- int earthRadius = 6378;
- 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)));
- System.out.println("The distance between your home and the destination is " + Math.round(destinationDistance) + " km");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement