|
| 1 | +import java.time.LocalDate; |
| 2 | +import java.time.LocalTime; |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +public class JarvisProgram { |
| 6 | + public static void main(String[] args) { |
| 7 | + Scanner scanner = new Scanner(System.in); |
| 8 | + String command; |
| 9 | + |
| 10 | + System.out.println("Welcome to Jarvis Program!"); |
| 11 | + |
| 12 | + do { |
| 13 | + System.out.print("Enter a command: "); |
| 14 | + command = scanner.nextLine(); |
| 15 | + |
| 16 | + switch (command.toLowerCase()) { |
| 17 | + case "hello": |
| 18 | + System.out.println("Hello! How can I assist you?"); |
| 19 | + break; |
| 20 | + case "time": |
| 21 | + LocalTime time = LocalTime.now(); |
| 22 | + System.out.println("The current time is: " + time); |
| 23 | + break; |
| 24 | + case "date": |
| 25 | + LocalDate date = LocalDate.now(); |
| 26 | + System.out.println("Today's date is: " + date); |
| 27 | + break; |
| 28 | + case "weather": |
| 29 | + String weather = getWeather(); |
| 30 | + System.out.println("The weather today is: " + weather); |
| 31 | + break; |
| 32 | + case "reminder": |
| 33 | + String reminder = setReminder(); |
| 34 | + System.out.println("Reminder set: " + reminder); |
| 35 | + break; |
| 36 | + case "quote": |
| 37 | + String quote = getRandomQuote(); |
| 38 | + System.out.println("Here's a quote for you: " + quote); |
| 39 | + break; |
| 40 | + case "news": |
| 41 | + String news = getLatestNews(); |
| 42 | + System.out.println("Here's the latest news: " + news); |
| 43 | + break; |
| 44 | + case "joke": |
| 45 | + String joke = getJoke(); |
| 46 | + System.out.println("Here's a joke for you: " + joke); |
| 47 | + break; |
| 48 | + case "exit": |
| 49 | + System.out.println("Goodbye!"); |
| 50 | + break; |
| 51 | + default: |
| 52 | + System.out.println("Sorry, I don't understand that command."); |
| 53 | + break; |
| 54 | + } |
| 55 | + } while (!command.equalsIgnoreCase("exit")); |
| 56 | + |
| 57 | + scanner.close(); |
| 58 | + } |
| 59 | + |
| 60 | + private static String getWeather() { |
| 61 | + // Code to fetch the current weather from an API or any other source |
| 62 | + // Implement your own logic or use external libraries |
| 63 | + return "Sunny"; |
| 64 | + } |
| 65 | + |
| 66 | + private static String setReminder() { |
| 67 | + // Code to set a reminder, you can use libraries like java.util.Timer or external libraries |
| 68 | + // Implement your own logic based on the requirements |
| 69 | + return "Meeting at 5 PM"; |
| 70 | + } |
| 71 | + |
| 72 | + private static String getRandomQuote() { |
| 73 | + // Code to fetch a random quote from an API or a predefined list |
| 74 | + // Implement your own logic or use external libraries |
| 75 | + return "Coder's Never Quit.."; |
| 76 | + } |
| 77 | + |
| 78 | + private static String getLatestNews() { |
| 79 | + // Code to fetch the latest news from an API or any other source |
| 80 | + // Implement your own logic or use external libraries |
| 81 | + return "Latest News:- Mercedes drivers can soon turn to ChatGPT for Voice Control..."; |
| 82 | + } |
| 83 | + |
| 84 | + private static String getJoke() { |
| 85 | + // Code to fetch a random joke from an API or a predefined list |
| 86 | + // Implement your own logic or use external libraries |
| 87 | + return "What's the best thing about Switzerland?........I don't know but the flag is a big Plus..."; |
| 88 | + } |
| 89 | +} |
0 commit comments