Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

ch.lakshmisriprasanna -easy level tasks #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions Decisionml.ipynb
Original file line number Diff line number Diff line change
@@ -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": [
"<a href=\"https://colab.research.google.com/github/Prasannasri575/Java-Programming-Internship/blob/main/Decisionml.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"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)"
]
}
]
}
60 changes: 60 additions & 0 deletions SimpleCalculator.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
42 changes: 42 additions & 0 deletions TemperatureConverter.java
Original file line number Diff line number Diff line change
@@ -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");
}

}
95 changes: 95 additions & 0 deletions ToDoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import java.util.ArrayList;
import java.util.Scanner;

public class ToDoList {
private static ArrayList<String> 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.");
}
}
77 changes: 77 additions & 0 deletions numberguessing.java
Original file line number Diff line number Diff line change
@@ -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();
}
}