Write program in java

Objective: To build a time-traveling program that allows users to travel forward or backward in time in fixed intervals.
Problem statement: You are to create a "Time Machine" simulator. Users can select if they want to travel into the future or the past, and then specify the number of years they want to travel.
Requirements:
Use a for loop to count the years as they pass by
Provide an engaging narrative for the time-travel experience(describe what the world looks like in different eras).
Sample output:
Welcome to the Time Machine!
Would you like to travel to the future or the past? (Enter 'future' or 'past'): future
How many years would you like to travel into the future? 3
Traveling to the future...
Year 1: Electric cars are now the standard.
Year 2: AI-powered robots are common in households.
Year 3: Space tourism has become affordable.
Welcome to the year 2026! Enjoy your stay!

```java

import java.util.Scanner;

public class TimeMachine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("Welcome to the Time Machine!");
System.out.print("Would you like to travel to the future or the past? (Enter 'future' or 'past'): ");
String direction = input.nextLine();

System.out.print("How many years would you like to travel " + direction + "? ");
int years = input.nextInt();

System.out.println("Traveling to the " + direction + "...");
for (int i = 1; i <= years; i++) {
System.out.print("Year " + i + ": ");
if (direction.equalsIgnoreCase("future")) {
travelToFuture(i);
} else if (direction.equalsIgnoreCase("past")) {
travelToPast(i);
}
}

System.out.println("Welcome to the year " + getCurrentYear(years, direction) + "! Enjoy your stay!");
input.close();
}

public static void travelToFuture(int year) {
switch (year) {
case 1:
System.out.println("Electric cars are now the standard.");
break;
case 2:
System.out.println("AI-powered robots are common in households.");
break;
case 3:
System.out.println("Space tourism has become affordable.");
break;
default:
System.out.println("Unknown advancements.");
break;
}
}

public static void travelToPast(int year) {
switch (year) {
case 1:
System.out.println("Horse-drawn carriages are the primary mode of transportation.");
break;
case 2:
System.out.println("Telegraph is the fastest means of communication.");
break;
case 3:
System.out.println("Inventions like the steam engine are revolutionizing industries.");
break;
default:
System.out.println("Unknown eras.");
break;
}
}

public static int getCurrentYear(int years, String direction) {
int currentYear = 2021;
if (direction.equalsIgnoreCase("future")) {
currentYear += years;
} else if (direction.equalsIgnoreCase("past")) {
currentYear -= years;
}
return currentYear;
}
}
```

This program prompts the user to choose whether they want to travel to the future or the past. Then, it asks for the number of years the user wants to travel, and based on the user's input, it uses a for loop to simulate the time-travel experience.

The `travelToFuture()` method is called when traveling to the future, and it provides a narrative for each year using a switch statement. Similarly, the `travelToPast()` method is called when traveling to the past.

Finally, the `getCurrentYear()` method calculates the current year based on the direction and number of years traveled, and it is displayed as part of the final output.