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

Commit 6d14c3c

Browse files
Add files via upload
1 parent c08d87c commit 6d14c3c

File tree

4 files changed

+303
-0
lines changed

4 files changed

+303
-0
lines changed

Chevurusumanth/NumberGuessing.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.*;
2+
import java.util.Random;
3+
public class NumberGuessing {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
Random random = new Random();
7+
System.out.println("Welcome to the Number Guessing Game!");
8+
System.out.println("I have selected a number between 1 and 100. Try to guess it!");
9+
int maxAttempts = 10;
10+
int secretNumber = random.nextInt(100) + 1;
11+
int attempts = 0;
12+
boolean guessedCorrectly = false;
13+
while (attempts < maxAttempts) {
14+
System.out.print("Enter your guess (between 1 and 100): ");
15+
int guess = scanner.nextInt();
16+
attempts++;
17+
if (guess == secretNumber) {
18+
guessedCorrectly = true;
19+
break;
20+
} else if (guess < secretNumber) {
21+
System.out.println("Too low! Try again.");
22+
} else {
23+
System.out.println("Too high! Try again.");
24+
}
25+
}
26+
27+
if (guessedCorrectly) {
28+
System.out.println("Congratulations! You've guessed the number " + secretNumber + " correctly in " + attempts + " attempts!");
29+
} else {
30+
System.out.println("Sorry, you've exceeded the maximum number of attempts. The correct number was: " + secretNumber);
31+
}
32+
33+
scanner.close();
34+
}
35+
}

Chevurusumanth/Temp.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import java.util.Scanner;
2+
3+
public class Temp {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
7+
System.out.println("Welcome to Temperature Converter!");
8+
System.out.println("Enter the temperature scale you want to convert from:");
9+
System.out.println("1. Celsius");
10+
System.out.println("2. Fahrenheit");
11+
System.out.println("3. Kelvin");
12+
13+
System.out.print("Enter your choice (1/2/3): ");
14+
int choiceFrom = scanner.nextInt();
15+
16+
System.out.print("Enter the temperature value: ");
17+
double temperature = scanner.nextDouble();
18+
19+
double convertedTemperature = 0;
20+
21+
switch (choiceFrom) {
22+
case 1:
23+
System.out.println("Convert Celsius to:");
24+
System.out.println("1. Fahrenheit");
25+
System.out.println("2. Kelvin");
26+
System.out.print("Enter your choice (1/2): ");
27+
int choiceToCelsius = scanner.nextInt();
28+
if (choiceToCelsius == 1) {
29+
convertedTemperature = celsiusToFahrenheit(temperature);
30+
System.out.println(temperature + " Celsius = " + convertedTemperature + " Fahrenheit");
31+
} else if (choiceToCelsius == 2) {
32+
convertedTemperature = celsiusToKelvin(temperature);
33+
System.out.println(temperature + " Celsius = " + convertedTemperature + " Kelvin");
34+
} else {
35+
System.out.println("Invalid choice!");
36+
}
37+
break;
38+
case 2:
39+
System.out.println("Convert Fahrenheit to:");
40+
System.out.println("1. Celsius");
41+
System.out.println("2. Kelvin");
42+
System.out.print("Enter your choice (1/2): ");
43+
int choiceToFahrenheit = scanner.nextInt();
44+
if (choiceToFahrenheit == 1) {
45+
convertedTemperature = fahrenheitToCelsius(temperature);
46+
System.out.println(temperature + " Fahrenheit = " + convertedTemperature + " Celsius");
47+
} else if (choiceToFahrenheit == 2) {
48+
convertedTemperature = fahrenheitToKelvin(temperature);
49+
System.out.println(temperature + " Fahrenheit = " + convertedTemperature + " Kelvin");
50+
} else {
51+
System.out.println("Invalid choice!");
52+
}
53+
break;
54+
case 3:
55+
System.out.println("Convert Kelvin to:");
56+
System.out.println("1. Celsius");
57+
System.out.println("2. Fahrenheit");
58+
System.out.print("Enter your choice (1/2): ");
59+
int choiceToKelvin = scanner.nextInt();
60+
if (choiceToKelvin == 1) {
61+
convertedTemperature = kelvinToCelsius(temperature);
62+
System.out.println(temperature + " Kelvin = " + convertedTemperature + " Celsius");
63+
} else if (choiceToKelvin == 2) {
64+
convertedTemperature = kelvinToFahrenheit(temperature);
65+
System.out.println(temperature + " Kelvin = " + convertedTemperature + " Fahrenheit");
66+
} else {
67+
System.out.println("Invalid choice!");
68+
}
69+
break;
70+
default:
71+
System.out.println("Invalid choice!");
72+
}
73+
74+
scanner.close();
75+
}
76+
77+
public static double celsiusToFahrenheit(double celsius) {
78+
return (celsius * 9 / 5) + 32;
79+
}
80+
81+
public static double celsiusToKelvin(double celsius) {
82+
return celsius + 273.15;
83+
}
84+
85+
public static double fahrenheitToCelsius(double fahrenheit) {
86+
return (fahrenheit - 32) * 5 / 9;
87+
}
88+
89+
public static double fahrenheitToKelvin(double fahrenheit) {
90+
return (fahrenheit + 459.67) * 5 / 9;
91+
}
92+
93+
public static double kelvinToCelsius(double kelvin) {
94+
return kelvin - 273.15;
95+
}
96+
97+
public static double kelvinToFahrenheit(double kelvin) {
98+
return (kelvin * 9 / 5) - 459.67;
99+
}
100+
}

Chevurusumanth/ToDoList.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import java.util.ArrayList;
2+
import java.util.Scanner;
3+
4+
class Task {
5+
private String name;
6+
private boolean completed;
7+
8+
public Task(String name) {
9+
this.name = name;
10+
this.completed = false;
11+
}
12+
13+
public String getName() {
14+
return name;
15+
}
16+
17+
public boolean isCompleted() {
18+
return completed;
19+
}
20+
21+
public void markCompleted() {
22+
this.completed = true;
23+
}
24+
}
25+
26+
public class TaskManager {
27+
private ArrayList<Task> tasks;
28+
private Scanner scanner;
29+
30+
public TaskManager() {
31+
tasks = new ArrayList<>();
32+
scanner = new Scanner(System.in);
33+
}
34+
35+
public void displayMenu() {
36+
System.out.println("Task Manager Menu:");
37+
System.out.println("1. Add Task");
38+
System.out.println("2. Delete Task");
39+
System.out.println("3. Mark Task as Completed");
40+
System.out.println("4. View Tasks");
41+
System.out.println("5. Exit");
42+
System.out.print("Enter your choice: ");
43+
}
44+
45+
public void addTask(String taskName) {
46+
Task task = new Task(taskName);
47+
tasks.add(task);
48+
System.out.println("Task added successfully!");
49+
}
50+
51+
public void deleteTask(int index) {
52+
if (index >= 0 && index < tasks.size()) {
53+
tasks.remove(index);
54+
System.out.println("Task deleted successfully!");
55+
} else {
56+
System.out.println("Invalid task index!");
57+
}
58+
}
59+
60+
public void markTaskCompleted(int index) {
61+
if (index >= 0 && index < tasks.size()) {
62+
tasks.get(index).markCompleted();
63+
System.out.println("Task marked as completed!");
64+
} else {
65+
System.out.println("Invalid task index!");
66+
}
67+
}
68+
69+
public void viewTasks() {
70+
System.out.println("Tasks:");
71+
for (int i = 0; i < tasks.size(); i++) {
72+
Task task = tasks.get(i);
73+
System.out.println((i + 1) + ". " + task.getName() + " - Completed: " + task.isCompleted());
74+
}
75+
}
76+
77+
public static void main(String[] args) {
78+
TaskManager taskManager = new TaskManager();
79+
Scanner scanner = new Scanner(System.in);
80+
int choice;
81+
82+
do {
83+
taskManager.displayMenu();
84+
choice = scanner.nextInt();
85+
scanner.nextLine(); // Consume newline
86+
87+
switch (choice) {
88+
case 1:
89+
System.out.print("Enter task name: ");
90+
String taskName = scanner.nextLine();
91+
taskManager.addTask(taskName);
92+
break;
93+
case 2:
94+
System.out.print("Enter index of task to delete: ");
95+
int deleteIndex = scanner.nextInt();
96+
taskManager.deleteTask(deleteIndex - 1);
97+
break;
98+
case 3:
99+
System.out.print("Enter index of task to mark as completed: ");
100+
int completeIndex = scanner.nextInt();
101+
taskManager.markTaskCompleted(completeIndex - 1);
102+
break;
103+
case 4:
104+
taskManager.viewTasks();
105+
break;
106+
case 5:
107+
System.out.println("Exiting...");
108+
break;
109+
default:
110+
System.out.println("Invalid choice. Please enter a number between 1 and 5.");
111+
}
112+
} while (choice != 5);
113+
114+
scanner.close();
115+
}
116+
}

Chevurusumanth/cal.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.util.Scanner;
2+
3+
public class Cal {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
7+
System.out.println("Welcome to Basic Calculator!");
8+
System.out.println("Enter the operation you want to perform:");
9+
System.out.println("1. Addition (+)");
10+
System.out.println("2. Subtraction (-)");
11+
System.out.println("3. Multiplication (*)");
12+
System.out.println("4. Division (/)");
13+
14+
System.out.print("Enter your choice (1/2/3/4): ");
15+
int choice = scanner.nextInt();
16+
17+
System.out.print("Enter the first number: ");
18+
double num1 = scanner.nextDouble();
19+
20+
System.out.print("Enter the second number: ");
21+
double num2 = scanner.nextDouble();
22+
23+
double result = 0;
24+
25+
switch (choice) {
26+
case 1:
27+
result = num1 + num2;
28+
System.out.println("Result: " + num1 + " + " + num2 + " = " + result);
29+
break;
30+
case 2:
31+
result = num1 - num2;
32+
System.out.println("Result: " + num1 + " - " + num2 + " = " + result);
33+
break;
34+
case 3:
35+
result = num1 * num2;
36+
System.out.println("Result: " + num1 + " * " + num2 + " = " + result);
37+
break;
38+
case 4:
39+
if (num2 != 0) {
40+
result = num1 / num2;
41+
System.out.println("Result: " + num1 + " / " + num2 + " = " + result);
42+
} else {
43+
System.out.println("Error: Division by zero!");
44+
}
45+
break;
46+
default:
47+
System.out.println("Invalid choice!");
48+
}
49+
50+
scanner.close();
51+
}
52+
}

0 commit comments

Comments
 (0)