Files
HW-03-oop-and-api/src/main/java/movie/apis/Main.java
T
2026-07-19 05:33:55 +03:30

104 lines
2.8 KiB
Java

package movie.apis;
import java.util.Scanner;
public class Main {
private static final MovieService movieService = new MovieService();
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("\n=== MOVIE API CLIENT ===\n");
boolean running = true;
while (running) {
displayMenu();
int choice = getIntInput("Enter your choice: ");
switch (choice) {
case 1:
movieService.displayGenres();
break;
case 2:
Long genreId =
getLongInput("Enter genre ID: ");
Long page =
getLongInput("Enter page number: ");
movieService.displayMoviesByGenre(
genreId,
page
);
break;
case 3:
Long movieId =
getLongInput("Enter movie ID: ");
movieService.displayMovieDetails(movieId);
break;
case 0:
running = false;
System.out.println("Goodbye!");
break;
default:
System.out.println("Invalid choice! Please enter 0-4");
}
if (running) {
System.out.println("\nPress Enter to continue...");
scanner.nextLine();
scanner.nextLine();
}
}
scanner.close();
}
private static void displayMenu() {
System.out.println("\n================================");
System.out.println(" MENU");
System.out.println("================================");
System.out.println("1. Get all genres");
System.out.println("2. Get movies by genre ID");
System.out.println("3. Get movie details by ID");
System.out.println("0. Exit");
System.out.println("================================");
}
private static int getIntInput(String prompt) {
System.out.print(prompt);
while (!scanner.hasNextInt()) {
System.out.print("Invalid input. " + prompt);
scanner.next();
}
int input = scanner.nextInt();
scanner.nextLine();
return input;
}
private static Long getLongInput(String prompt) {
System.out.print(prompt);
while (!scanner.hasNextLong()) {
System.out.print("Invalid input. " + prompt);
scanner.next();
}
Long input = scanner.nextLong();
scanner.nextLine();
return input;
}
}