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

Easy Level Task #30

Open
wants to merge 3 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
28 changes: 28 additions & 0 deletions HarshTamboli/NumberGuessingGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package HarshTamboli.NumberGuessingGame;
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();
}
}
44 changes: 44 additions & 0 deletions HarshTamboli/SimpleCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package HarshTamboli.SimpleCalculator;
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();
}
}
87 changes: 87 additions & 0 deletions HarshTamboli/TemperatureConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package HarshTamboli.TemperatureConverter;
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;
}
}
59 changes: 59 additions & 0 deletions HarshTamboli/ToDoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package HarshTamboli.ToDoList;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ToDoList extends Application {
private ListView<String> listView;
private TextField taskInput;

@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
listView = new ListView<>();
taskInput = new TextField();
taskInput.setPromptText("Enter a new task");
Button addButton = new Button("Add");
addButton.setOnAction(e -> addTask());
Button deleteButton = new Button("Delete");
deleteButton.setOnAction(e -> deleteTask());
HBox inputBox = new HBox(10, taskInput, addButton, deleteButton);
inputBox.setAlignment(Pos.CENTER);
inputBox.setPadding(new Insets(10));
VBox centerBox = new VBox(10, listView, inputBox);
centerBox.setPadding(new Insets(10));
root.setCenter(centerBox);
Scene scene = new Scene(root, 300, 400);
primaryStage.setTitle("ToDo List");
primaryStage.setScene(scene);
primaryStage.show();
}

private void addTask() {
String taskDescription = taskInput.getText().trim();
if (!taskDescription.isEmpty()) {
listView.getItems().add(taskDescription);
taskInput.clear();
}
}

private void deleteTask() {
int selectedIndex = listView.getSelectionModel().getSelectedIndex();
if (selectedIndex != -1) {
listView.getItems().remove(selectedIndex);
}
}

public static void main(String[] args) {
launch(args);
}
}