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

EASY LEVEL TASKS #20

Open
wants to merge 1 commit 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
27 changes: 27 additions & 0 deletions R DEVISH- EASY LEVEL/NumberGuessingGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Random;
import java.util.Scanner;

public class NumberGuessingGame {
public static void main(String args[]) {
Random random = new Random();
Scanner scanner = new Scanner(System.in);
int chances = 5;
int randomNumber = random.nextInt(100);

System.out.println("Welcome to the Number Guessing Game!");
System.out.println("You have " + chances + " chances to guess the number.");

for (int i = 0; i < chances; i++) {
System.out.println("Enter your guess (between 0 and 99):");
int guess = scanner.nextInt();

if (guess == randomNumber) {
System.out.println("Congratulations! You guessed it right!");
break;
} else {
System.out.println("Incorrect guess. You have " + (chances - i - 1) + " chances left.");
}
}
scanner.close();
}
}
43 changes: 43 additions & 0 deletions R DEVISH- EASY LEVEL/SimpleCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Simple Calculator");
System.out.println("Enter the first number:");
double num1 = scanner.nextDouble();
System.out.println("Enter the second number:");
double num2 = scanner.nextDouble();
System.out.println("Select operation:");
System.out.println("1. Addition (+)");
System.out.println("2. Subtraction (-)");
System.out.println("3. Multiplication (*)");
System.out.println("4. Division (/)");
int choice = scanner.nextInt();
double result;
switch (choice) {
case 1:
result = num1 + num2;
System.out.println("Result: " + result);
break;
case 2:
result = num1 - num2;
System.out.println("Result: " + result);
break;
case 3:
result = num1 * num2;
System.out.println("Result: " + result);
break;
case 4:
if (num2 == 0) {
System.out.println("Error: Division by zero");
} else {
result = num1 / num2;
System.out.println("Result: " + result);
}
break;
default:
System.out.println("Invalid choice");
}
scanner.close();
}
}
91 changes: 91 additions & 0 deletions R DEVISH- EASY LEVEL/TaskManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@


import java.util.ArrayList;
import java.util.Scanner;

public class TaskManager {
private static ArrayList<String> tasks = new ArrayList<>();

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean exit = false;

while (!exit) {
System.out.println("Task Manager");
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: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline character

switch (choice) {
case 1:
System.out.print("Enter task to add: ");
String taskToAdd = scanner.nextLine();
addTask(taskToAdd);
break;
case 2:
System.out.print("Enter index of task to delete: ");
int indexToDelete = scanner.nextInt();
scanner.nextLine(); // Consume newline character
deleteTask(indexToDelete);
break;
case 3:
System.out.print("Enter index of task to mark as completed: ");
int indexToComplete = scanner.nextInt();
scanner.nextLine(); // Consume newline character
markTaskAsCompleted(indexToComplete);
break;
case 4:
viewTasks();
break;
case 5:
exit = true;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please enter a number between 1 and 5.");
}
}

scanner.close();
}

private static void addTask(String task) {
tasks.add(task);
System.out.println("Task added successfully.");
}

private static void deleteTask(int index) {
if (index >= 0 && index < tasks.size()) {
tasks.remove(index);
System.out.println("Task deleted successfully.");
} else {
System.out.println("Invalid index. No task deleted.");
}
}

private static void markTaskAsCompleted(int index) {
if (index >= 0 && index < tasks.size()) {
String task = tasks.get(index);
tasks.set(index, "[Completed] " + task);
System.out.println("Task marked as completed.");
} else {
System.out.println("Invalid index. No task marked as completed.");
}
}

private static void viewTasks() {
if (tasks.isEmpty()) {
System.out.println("No tasks found.");
} else {
System.out.println("Tasks:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println(i + ". " + tasks.get(i));
}
}
}
}
86 changes: 86 additions & 0 deletions R DEVISH- EASY LEVEL/TemperatureConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import java.util.Scanner;
public class TemperatureConverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Temperature Converter");
System.out.println("Choose the original temperature scale:");
System.out.println("1. Celsius");
System.out.println("2. Fahrenheit");
System.out.println("3. Kelvin");
int originalScale = scanner.nextInt();

System.out.println("Enter the temperature:");
double temperature = scanner.nextDouble();

System.out.println("Choose the target temperature scale:");
System.out.println("1.Celsius");
System.out.println("2.Fahrenheit");
System.out.println("3.Kelvin");
int targetScale = scanner.nextInt();

double convertedTemperature = convertTemperature(temperature, originalScale, targetScale);

System.out.println("Converted temperature:" + convertedTemperature);

scanner.close();
}

public static double convertTemperature(double temperature, int originalScale, int targetScale) {
switch (originalScale) {
case 1:
switch (targetScale) {
case 1:
return temperature;
case 2:
return celsiusToFahrenheit(temperature);
case 3: // Celsius to Kelvin
return celsiusToKelvin(temperature);
}
case 2:
switch (targetScale) {
case 1:
return fahrenheitToCelsius(temperature);
case 2:
return temperature;
case 3:
return fahrenheitToKelvin(temperature);
}
case 3: // Kelvin
switch (targetScale) {
case 1:
return kelvinToCelsius(temperature);
case 2:
return kelvinToFahrenheit(temperature);
case 3:
return temperature;
}
default:
return 0.0;
}
}

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;
}
}