diff --git a/Decisionml.ipynb b/Decisionml.ipynb new file mode 100644 index 0000000..450229c --- /dev/null +++ b/Decisionml.ipynb @@ -0,0 +1,86 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyN7gRVOaNVFamNga0m0FXjk", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Decision Tree Implementation" + ], + "metadata": { + "id": "gIiEk7EZbOJ8" + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "tzAc2dvVariz", + "outputId": "e7f2fad8-70d6-4c26-cc22-19b544c5459d" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Accuracy: 1.0\n" + ] + } + ], + "source": [ + "from sklearn.tree import DecisionTreeClassifier\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.datasets import load_iris\n", + "from sklearn.metrics import accuracy_score\n", + "\n", + "# Load the iris dataset\n", + "iris = load_iris()\n", + "X = iris.data\n", + "y = iris.target\n", + "\n", + "# Split data into training and testing sets\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", + "\n", + "# Create a Decision Tree Classifier\n", + "clf = DecisionTreeClassifier()\n", + "\n", + "# Train the model\n", + "clf.fit(X_train, y_train)\n", + "\n", + "# Make predictions\n", + "y_pred = clf.predict(X_test)\n", + "\n", + "# Evaluate the model's accuracy\n", + "accuracy = accuracy_score(y_test, y_pred)\n", + "print(\"Accuracy:\",accuracy)" + ] + } + ] +} \ No newline at end of file diff --git a/SimpleCalculator.java b/SimpleCalculator.java new file mode 100644 index 0000000..bc6d517 --- /dev/null +++ b/SimpleCalculator.java @@ -0,0 +1,60 @@ +import java.util.Scanner; + +public class SimpleCalculator { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // Displaying the menu + System.out.println("Simple Calculator"); + System.out.println("Select an operation:"); + System.out.println("1. Addition"); + System.out.println("2. Subtraction"); + System.out.println("3. Multiplication"); + System.out.println("4. Division"); + + // Reading the user's choice + System.out.print("Enter your choice (1-4): "); + int choice = scanner.nextInt(); + + // Reading the two numbers + System.out.print("Enter first number: "); + double num1 = scanner.nextDouble(); + System.out.print("Enter second number: "); + double num2 = scanner.nextDouble(); + + double result = 0; + boolean validChoice = true; + + // Performing the chosen operation + switch (choice) { + case 1: + result = num1 + num2; + break; + case 2: + result = num1 - num2; + break; + case 3: + result = num1 * num2; + break; + case 4: + if (num2 != 0) { + result = num1 / num2; + } else { + System.out.println("Error: Division by zero is not allowed."); + validChoice = false; + } + break; + default: + System.out.println("Invalid choice! Please select a valid operation (1-4)."); + validChoice = false; + } + + // Displaying the result + if (validChoice) { + System.out.println("The result is: " + result); + } + + scanner.close(); + } +} diff --git a/TemperatureConverter.java b/TemperatureConverter.java new file mode 100644 index 0000000..c829d78 --- /dev/null +++ b/TemperatureConverter.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class TemperatureConverter { + + public static void main(String[] args) { + + + Scanner input = new Scanner(System.in); + + + System.out.print("Enter temperature value: "); + double temp = input.nextDouble(); + + System.out.print("Enter temperature scale (C, F, or K): "); + String scale = input.next(); + + double celsius; + switch(scale.toUpperCase()) { + case "C": + celsius = temp; + break; + case "F": + celsius = (temp - 32) * 5 / 9; + break; + case "K": + celsius = temp - 273.15; + break; + default: + System.out.println("Invalid temperature scale."); + return; + } + + double fahrenheit = celsius * 9 / 5 + 32; + + double kelvin = celsius + 273.15; + + System.out.println("Celsius: " + celsius + " C"); + System.out.println("Fahrenheit: " + fahrenheit + " F"); + System.out.println("Kelvin: " + kelvin + " K"); + } + +} \ No newline at end of file diff --git a/ToDoList.java b/ToDoList.java new file mode 100644 index 0000000..1de1c41 --- /dev/null +++ b/ToDoList.java @@ -0,0 +1,95 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class ToDoList { + private static ArrayList tasks = new ArrayList<>(); + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + while (true) { + System.out.println("\nToDo List:"); + displayTasks(); + + System.out.println("\nChoose an option:"); + System.out.println("1. Add Task"); + System.out.println("2. Delete Task"); + System.out.println("3. Mark Task as Completed"); + System.out.println("4. Exit"); + + System.out.print("Enter your choice: "); + int choice = scanner.nextInt(); + + switch (choice) { + case 1: + addTask(scanner); + break; + case 2: + deleteTask(scanner); + break; + case 3: + markAsCompleted(scanner); + break; + case 4: + System.out.println("Exiting ToDo List..."); + scanner.close(); + return; + default: + System.out.println("Invalid choice! Please choose again."); + } + } + } + + private static void displayTasks() { + if (tasks.isEmpty()) { + System.out.println("No tasks available."); + } else { + for (int i = 0; i < tasks.size(); i++) { + System.out.println((i + 1) + ". " + tasks.get(i)); + } + } + } + + private static void addTask(Scanner scanner) { + scanner.nextLine(); // Consume newline + System.out.print("Enter task description: "); + String task = scanner.nextLine(); + tasks.add(task); + System.out.println("Task added successfully."); + } + + private static void deleteTask(Scanner scanner) { + if (tasks.isEmpty()) { + System.out.println("No tasks available to delete."); + return; + } + + System.out.print("Enter task number to delete: "); + int taskNumber = scanner.nextInt(); + if (taskNumber < 1 || taskNumber > tasks.size()) { + System.out.println("Invalid task number!"); + return; + } + + tasks.remove(taskNumber - 1); + System.out.println("Task deleted successfully."); + } + + private static void markAsCompleted(Scanner scanner) { + if (tasks.isEmpty()) { + System.out.println("No tasks available to mark as completed."); + return; + } + + System.out.print("Enter task number to mark as completed: "); + int taskNumber = scanner.nextInt(); + if (taskNumber < 1 || taskNumber > tasks.size()) { + System.out.println("Invalid task number!"); + return; + } + + String completedTask = tasks.get(taskNumber - 1) + " (Completed)"; + tasks.set(taskNumber - 1, completedTask); + System.out.println("Task marked as completed."); + } +} diff --git a/numberguessing.java b/numberguessing.java new file mode 100644 index 0000000..7e5b213 --- /dev/null +++ b/numberguessing.java @@ -0,0 +1,77 @@ +// Java program for the above approach +import java.util.Scanner; + +public class GFG { + + // Function that implements the + // number guessing game + public static void + guessingNumberGame() + { + // Scanner Class + Scanner sc = new Scanner(System.in); + + // Generate the numbers + int number = 1 + (int)(100 + * Math.random()); + + // Given K trials + int K = 5; + + int i, guess; + + System.out.println( + "A number is chosen" + + " between 1 to 100." + + "Guess the number" + + " within 5 trials."); + + // Iterate over K Trials + for (i = 0; i < K; i++) { + + System.out.println( + "Guess the number:"); + + // Take input for guessing + guess = sc.nextInt(); + + // If the number is guessed + if (number == guess) { + System.out.println( + "Congratulations!" + + " You guessed the number."); + break; + } + else if (number > guess + && i != K - 1) { + System.out.println( + "The number is " + + "greater than " + guess); + } + else if (number < guess + && i != K - 1) { + System.out.println( + "The number is" + + " less than " + guess); + } + } + + if (i == K) { + System.out.println( + "You have exhausted" + + " K trials."); + + System.out.println( + "The number was " + number); + } + } + + // Driver Code + public static void + main(String arg[]) + { + + // Function Call + guessingNumberGame(); + } +}