From 12c8fe7bb034cab156ae7160fa1aa23148af0420 Mon Sep 17 00:00:00 2001 From: lokeshkatti Date: Tue, 18 Jun 2024 11:07:17 +0530 Subject: [PATCH 1/5] Create Task1 --- Lokesh/Java/Task1 | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Lokesh/Java/Task1 diff --git a/Lokesh/Java/Task1 b/Lokesh/Java/Task1 new file mode 100644 index 0000000..5d5bee9 --- /dev/null +++ b/Lokesh/Java/Task1 @@ -0,0 +1,56 @@ +import java.util.Scanner; +public class SimpleCalculator { + public static void main(String[] args) { + // Create a Scanner object for user input + Scanner scanner = new Scanner(System.in); + + // Prompt the user to enter the first number + System.out.print("Enter the first number: "); + double firstNumber = scanner.nextDouble(); + + // Prompt the user to enter the second number + System.out.print("Enter the second number: "); + double secondNumber = scanner.nextDouble(); + + // Prompt the user to choose an operation + System.out.println("Choose an operation:"); + System.out.println("1. Addition (+)"); + System.out.println("2. Subtraction (-)"); + System.out.println("3. Multiplication (*)"); + System.out.println("4. Division (/)"); + System.out.print("Enter your choice: "); + int choice = scanner.nextInt(); + + double result = 0; + + // Perform the selected operation based on user's choice + switch (choice) { + case 1: + result = firstNumber + secondNumber; + break; + case 2: + result = firstNumber - secondNumber; + break; + case 3: + result = firstNumber * secondNumber; + break; + case 4: + if (secondNumber != 0) { + result = firstNumber / secondNumber; + } else { + System.out.println("Error: Cannot divide by zero"); + return; // Exit the program + } + break; + default: + System.out.println("Invalid choice"); + return; // Exit the program + } + + // Display the result + System.out.println("Result: " + result); + + // Close the scanner to release resources + scanner.close(); + } +} From 7cb060f976d954edee38cb38a450a9a433398ab1 Mon Sep 17 00:00:00 2001 From: lokeshkatti Date: Tue, 18 Jun 2024 11:11:37 +0530 Subject: [PATCH 2/5] ToDo List --- Lokesh/Java/task2 | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Lokesh/Java/task2 diff --git a/Lokesh/Java/task2 b/Lokesh/Java/task2 new file mode 100644 index 0000000..5389266 --- /dev/null +++ b/Lokesh/Java/task2 @@ -0,0 +1,116 @@ +import java.util.ArrayList; +import java.util.Scanner; + +class Task { + private String name; + private boolean completed; + + public Task(String name) { + this.name = name; + this.completed = false; + } + + public String getName() { + return name; + } + + public boolean isCompleted() { + return completed; + } + + public void markCompleted() { + this.completed = true; + } +} + +public class TaskManager { + private ArrayList tasks; + private Scanner scanner; + + public TaskManager() { + tasks = new ArrayList<>(); + scanner = new Scanner(System.in); + } + + public void displayMenu() { + System.out.println("Task Manager Menu:"); + System.out.println("1. Add Task"); + System.out.println("2. Delete Task"); + System.out.println("3. Mark Task as Completed"); + System.out.println("4. View Tasks"); + System.out.println("5. Exit"); + System.out.print("Enter your choice: "); + } + + public void addTask(String taskName) { + Task task = new Task(taskName); + tasks.add(task); + System.out.println("Task added successfully!"); + } + + public void deleteTask(int index) { + if (index >= 0 && index < tasks.size()) { + tasks.remove(index); + System.out.println("Task deleted successfully!"); + } else { + System.out.println("Invalid task index!"); + } + } + + public void markTaskCompleted(int index) { + if (index >= 0 && index < tasks.size()) { + tasks.get(index).markCompleted(); + System.out.println("Task marked as completed!"); + } else { + System.out.println("Invalid task index!"); + } + } + + public void viewTasks() { + System.out.println("Tasks:"); + for (int i = 0; i < tasks.size(); i++) { + Task task = tasks.get(i); + System.out.println((i + 1) + ". " + task.getName() + " - Completed: " + task.isCompleted()); + } + } + + public static void main(String[] args) { + TaskManager taskManager = new TaskManager(); + Scanner scanner = new Scanner(System.in); + int choice; + + do { + taskManager.displayMenu(); + choice = scanner.nextInt(); + scanner.nextLine(); // Consume newline + + switch (choice) { + case 1: + System.out.print("Enter task name: "); + String taskName = scanner.nextLine(); + taskManager.addTask(taskName); + break; + case 2: + System.out.print("Enter index of task to delete: "); + int deleteIndex = scanner.nextInt(); + taskManager.deleteTask(deleteIndex - 1); + break; + case 3: + System.out.print("Enter index of task to mark as completed: "); + int completeIndex = scanner.nextInt(); + taskManager.markTaskCompleted(completeIndex - 1); + break; + case 4: + taskManager.viewTasks(); + break; + case 5: + System.out.println("Exiting..."); + break; + default: + System.out.println("Invalid choice. Please enter a number between 1 and 5."); + } + } while (choice != 5); + + scanner.close(); + } +} From 57685af36cc507d9e7827c14643b5fd2b7ad1051 Mon Sep 17 00:00:00 2001 From: lokeshkatti Date: Tue, 18 Jun 2024 12:25:20 +0530 Subject: [PATCH 3/5] NumberGuessing --- Lokesh/Java/Task3 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Lokesh/Java/Task3 diff --git a/Lokesh/Java/Task3 b/Lokesh/Java/Task3 new file mode 100644 index 0000000..825c24c --- /dev/null +++ b/Lokesh/Java/Task3 @@ -0,0 +1,36 @@ +import java.util.*; +import java.util.Random; +public class NumberGuessing { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + System.out.println("Let's Play Number Guessing Game!"); + //Enter the number to Guess + System.out.println("I have selected a number between 1 and 100. Try to guess it!"); + int maxAttempts = 10; + int secretNumber = random.nextInt(100) + 1; + int attempts = 0; + boolean guessedCorrectly = false; + while (attempts < maxAttempts) { + System.out.print("Enter your guess (between 1 and 100): "); + int guess = scanner.nextInt(); + attempts++; + if (guess == secretNumber) { + guessedCorrectly = true; + break; + } else if (guess < secretNumber) { + System.out.println("Too low! Try again."); + } else { + System.out.println("Too high! Try again."); + } + } + + if (guessedCorrectly) { + System.out.println("Congratulations! You've guessed the number " + secretNumber + " correctly in " + attempts + " attempts!"); + } else { + System.out.println("Sorry, you've exceeded the maximum number of attempts. The correct number was: " + secretNumber); + } + + scanner.close(); + } +} From 4fb0199acd6867579214cc11c564c0f6d5ba3d09 Mon Sep 17 00:00:00 2001 From: lokeshkatti Date: Tue, 18 Jun 2024 12:27:04 +0530 Subject: [PATCH 4/5] TemperatureConverter --- Lokesh/Java/Task4 | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Lokesh/Java/Task4 diff --git a/Lokesh/Java/Task4 b/Lokesh/Java/Task4 new file mode 100644 index 0000000..cf205b8 --- /dev/null +++ b/Lokesh/Java/Task4 @@ -0,0 +1,100 @@ +import java.util.Scanner; + +public class Temp { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Welcome to Temperature Converter!"); + System.out.println("Enter the temperature scale you want to convert from:"); + System.out.println("1. Celsius"); + System.out.println("2. Fahrenheit"); + System.out.println("3. Kelvin"); + + System.out.print("Enter your choice (1/2/3): "); + int choiceFrom = scanner.nextInt(); + + System.out.print("Enter the temperature value: "); + double temperature = scanner.nextDouble(); + + double convertedTemperature = 0; + + switch (choiceFrom) { + case 1: + System.out.println("Convert Celsius to:"); + System.out.println("1. Fahrenheit"); + System.out.println("2. Kelvin"); + System.out.print("Enter your choice (1/2): "); + int choiceToCelsius = scanner.nextInt(); + if (choiceToCelsius == 1) { + convertedTemperature = celsiusToFahrenheit(temperature); + System.out.println(temperature + " Celsius = " + convertedTemperature + " Fahrenheit"); + } else if (choiceToCelsius == 2) { + convertedTemperature = celsiusToKelvin(temperature); + System.out.println(temperature + " Celsius = " + convertedTemperature + " Kelvin"); + } else { + System.out.println("Invalid choice!"); + } + break; + case 2: + System.out.println("Convert Fahrenheit to:"); + System.out.println("1. Celsius"); + System.out.println("2. Kelvin"); + System.out.print("Enter your choice (1/2): "); + int choiceToFahrenheit = scanner.nextInt(); + if (choiceToFahrenheit == 1) { + convertedTemperature = fahrenheitToCelsius(temperature); + System.out.println(temperature + " Fahrenheit = " + convertedTemperature + " Celsius"); + } else if (choiceToFahrenheit == 2) { + convertedTemperature = fahrenheitToKelvin(temperature); + System.out.println(temperature + " Fahrenheit = " + convertedTemperature + " Kelvin"); + } else { + System.out.println("Invalid choice!"); + } + break; + case 3: + System.out.println("Convert Kelvin to:"); + System.out.println("1. Celsius"); + System.out.println("2. Fahrenheit"); + System.out.print("Enter your choice (1/2): "); + int choiceToKelvin = scanner.nextInt(); + if (choiceToKelvin == 1) { + convertedTemperature = kelvinToCelsius(temperature); + System.out.println(temperature + " Kelvin = " + convertedTemperature + " Celsius"); + } else if (choiceToKelvin == 2) { + convertedTemperature = kelvinToFahrenheit(temperature); + System.out.println(temperature + " Kelvin = " + convertedTemperature + " Fahrenheit"); + } else { + System.out.println("Invalid choice!"); + } + break; + default: + System.out.println("Invalid choice!"); + } + + scanner.close(); + } + + public static double celsiusToFahrenheit(double celsius) { + return (celsius * 9 / 5) + 32; + } + + public static double celsiusToKelvin(double celsius) { + return celsius + 273.15; + } + + public static double fahrenheitToCelsius(double fahrenheit) { + return (fahrenheit - 32) * 5 / 9; + } + + public static double fahrenheitToKelvin(double fahrenheit) { + return (fahrenheit + 459.67) * 5 / 9; + } + + public static double kelvinToCelsius(double kelvin) { + return kelvin - 273.15; + } + + public static double kelvinToFahrenheit(double kelvin) { + return (kelvin * 9 / 5) - 459.67; + } +} From 36be83abeaeb459974ede5f121e81e5f126c62b9 Mon Sep 17 00:00:00 2001 From: lokeshkatti Date: Wed, 19 Jun 2024 15:09:23 +0530 Subject: [PATCH 5/5] README.md --- Lokesh/Java/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Lokesh/Java/README.md diff --git a/Lokesh/Java/README.md b/Lokesh/Java/README.md new file mode 100644 index 0000000..5190299 --- /dev/null +++ b/Lokesh/Java/README.md @@ -0,0 +1,12 @@ +Task-1:about Simple Calculator + +Develop a basic calculator application capable of performing addition, subtraction, multiplication, and division operations. +Task-2: about ToDo List + +Create a console-based or GUI application for managing a list of tasks with features like adding, deleting, and marking tasks as completed. +Task-3: About Number Guessing Game + +Implement a simple number guessing game where the computer generates a random number and the player tries to guess it within a certain number of attempts. +Task-4: about Temperature Converter + +Build an application that converts temperatures between Celsius, Fahrenheit, and Kelvin scales