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

Easy level Tasks #48

Open
wants to merge 5 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
12 changes: 12 additions & 0 deletions sai chukka/README.md
Original file line number Diff line number Diff line change
@@ -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
116 changes: 116 additions & 0 deletions sai chukka/Task-2
Original file line number Diff line number Diff line change
@@ -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<Task> 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();
}
}
56 changes: 56 additions & 0 deletions sai chukka/task-1
Original file line number Diff line number Diff line change
@@ -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();
}
}
36 changes: 36 additions & 0 deletions sai chukka/task-3
Original file line number Diff line number Diff line change
@@ -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();
}
}
100 changes: 100 additions & 0 deletions sai chukka/task-4
Original file line number Diff line number Diff line change
@@ -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;
}
}