-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTravel Itinerary Planner.java
More file actions
119 lines (104 loc) · 4.07 KB
/
Travel Itinerary Planner.java
File metadata and controls
119 lines (104 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.ArrayList;
import java.util.Scanner;
class Destination {
String name;
String startDate;
String endDate;
double budget;
public Destination(String name, String startDate, String endDate, double budget) {
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.budget = budget;
}
@Override
public String toString() {
return "Destination: " + name + ", Start Date: " + startDate + ", End Date: " + endDate + ", Budget: $" + budget;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Destination> itinerary = new ArrayList<>();
boolean exit = false;
System.out.println("Welcome to the Travel Itinerary Planner!");
while (!exit) {
System.out.println("\nMenu:");
System.out.println("1. Add a Destination");
System.out.println("2. View Itinerary");
System.out.println("3. Calculate Total Budget");
System.out.println("4. Weather Information (Placeholder)");
System.out.println("5. Map Information (Placeholder)");
System.out.println("6. Exit");
System.out.print("Choose an option (1-6): ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
addDestination(scanner, itinerary);
break;
case 2:
viewItinerary(itinerary);
break;
case 3:
calculateTotalBudget(itinerary);
break;
case 4:
weatherInfo();
break;
case 5:
mapInfo();
break;
case 6:
System.out.println("Thank you for using the Travel Itinerary Planner. Safe travels!");
exit = true;
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
scanner.close();
}
// Method to add a destination to the itinerary
private static void addDestination(Scanner scanner, ArrayList<Destination> itinerary) {
System.out.print("Enter destination name: ");
String name = scanner.nextLine();
System.out.print("Enter start date (YYYY-MM-DD): ");
String startDate = scanner.nextLine();
System.out.print("Enter end date (YYYY-MM-DD): ");
String endDate = scanner.nextLine();
System.out.print("Enter budget for this destination: ");
double budget = scanner.nextDouble();
scanner.nextLine(); // Consume newline
Destination destination = new Destination(name, startDate, endDate, budget);
itinerary.add(destination);
System.out.println("Destination added successfully!");
}
// Method to view the itinerary
private static void viewItinerary(ArrayList<Destination> itinerary) {
if (itinerary.isEmpty()) {
System.out.println("Your itinerary is empty.");
} else {
System.out.println("\nYour Itinerary:");
for (Destination destination : itinerary) {
System.out.println(destination);
}
}
}
// Method to calculate the total budget
private static void calculateTotalBudget(ArrayList<Destination> itinerary) {
double totalBudget = 0;
for (Destination destination : itinerary) {
totalBudget += destination.budget;
}
System.out.printf("Total Budget for the trip: $%.2f%n", totalBudget);
}
// Placeholder for weather information
private static void weatherInfo() {
System.out.println("Weather Information: This feature is under development.");
}
// Placeholder for map information
private static void mapInfo() {
System.out.println("Map Information: This feature is under development.");
}
}