From a592c060fabb5a3e43208c0099615ac4da17cefe Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:12:58 +0530 Subject: [PATCH 1/6] Create OnlineBankingSystem --- padmini/task1/OnlineBankingSystem | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 padmini/task1/OnlineBankingSystem diff --git a/padmini/task1/OnlineBankingSystem b/padmini/task1/OnlineBankingSystem new file mode 100644 index 0000000..802b721 --- /dev/null +++ b/padmini/task1/OnlineBankingSystem @@ -0,0 +1,70 @@ +import java.util.Scanner; + +class BankAccount { + private String accountNumber; + private double balance; + + public BankAccount(String accountNumber, double balance) { + this.accountNumber = accountNumber; + this.balance = balance; + } + + public void deposit(double amount) { + balance += amount; + System.out.println("Deposited $" + amount + ". Current balance: $" + balance); + } + + public void withdraw(double amount) { + if (amount > balance) { + System.out.println("Insufficient funds."); + } else { + balance -= amount; + System.out.println("Withdrew $" + amount + ". Current balance: $" + balance); + } + } + + public double getBalance() { + return balance; + } +} + +class Customer { + private String name; + private BankAccount account; + + public Customer(String name, BankAccount account) { + this.name = name; + this.account = account; + } + + public void makeDeposit(double amount) { + account.deposit(amount); + } + + public void makeWithdrawal(double amount) { + account.withdraw(amount); + } + + public double checkBalance() { + return account.getBalance(); + } +} + +public class OnlineBankingSystem { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // Create a bank account + BankAccount account1 = new BankAccount("123456", 1000); + + // Create a customer + Customer customer1 = new Customer("Alice", account1); + + // Perform transactions + customer1.makeDeposit(500); + customer1.makeWithdrawal(200); + System.out.println("Current balance: $" + customer1.checkBalance()); + + scanner.close(); + } +} From 95bcabaf83c7e98de3cadd410881243a0efbb7e8 Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sat, 4 May 2024 18:17:07 +0530 Subject: [PATCH 2/6] Create Calculator --- padmini/Calculator | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 padmini/Calculator diff --git a/padmini/Calculator b/padmini/Calculator new file mode 100644 index 0000000..445f701 --- /dev/null +++ b/padmini/Calculator @@ -0,0 +1,79 @@ +import java.awt.*; +import java.awt.event.*; +class Calculator implements ActionListener +{ + Frame f=new Frame(); + Label l1 = new Label("First Number"); + Label l2 = new Label("Second Number"); + Label l3 = new Label("Result"); + TextField t1= new TextField(); + TextField t2= new TextField(); + TextField t3= new TextField(); + Button b1 = new Button("Add"); + Button b2 = new Button("Sub"); + Button b3 = new Button("Mul"); + Button b4 = new Button("Div"); + Button b5 = new Button("Cancel"); + Calculator() + { + l1.setBounds(50,100,100,20); + l2.setBounds(50,140,100,20); + l3.setBounds(50,180,100,20); + t1.setBounds(200,100,150,20); + t2.setBounds(200,140,150,20); + t3.setBounds(200,180,150,20); + b1.setBounds(50,250,70,20); + b2.setBounds(110,250,70,20); + b3.setBounds(170,250,70,20); + b4.setBounds(230,250,70,20); + b5.setBounds(290,250,70,20); + f.add(l1); + f.add(l2); + f.add(l3); + f.add(t1); + f.add(t2); + f.add(t3); + f.add(b1); + f.add(b2); + f.add(b3); + f.add(b4); + f.add(b5); + b1.addActionListener(this); + b2.addActionListener(this); + b3.addActionListener(this); + b4.addActionListener(this); + b5.addActionListener(this); + f.setLayout(null); + f.setVisible(true); + f.setSize(400,350); +} +public void actionPerformed(ActionEvent e) +{ + int n1 = Integer.parseInt(t1.getText()); + int n2 = Integer.parseInt(t2.getText()); + if(e.getSource()==b1) + { + t3.setText(String.valueOf(n1+n2)); + } + if(e.getSource()==b2) + { + t3.setText(String.valueOf(n1-n2)); + } + if(e.getSource()==b3) + { + t3.setText(String.valueOf(n1*n2)); + } + if(e.getSource()==b4) + { + t3.setText(String.valueOf(n1/n2)); + } + if(e.getSource()==b5) + { + System.exit(0); + } +} +public static void main(String [] args) +{ + new Calculator(); + } +} From b9dceb69d46337c9a9c0d1d6e3b772f20059b167 Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sat, 4 May 2024 18:24:13 +0530 Subject: [PATCH 3/6] Create Number Guessing Game --- padmini/Number Guessing/Number Guessing Game | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 padmini/Number Guessing/Number Guessing Game diff --git a/padmini/Number Guessing/Number Guessing Game b/padmini/Number Guessing/Number Guessing Game new file mode 100644 index 0000000..18d816d --- /dev/null +++ b/padmini/Number Guessing/Number Guessing Game @@ -0,0 +1,35 @@ +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("Welcome to the Number Guessing Game!"); + 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(); + } +} From e94146f5e64e1b94579f8241bb6acf60a66dd0ed Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sat, 4 May 2024 18:31:01 +0530 Subject: [PATCH 4/6] Create Temperature Converter Program --- .../Temperature Converter Program | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 padmini/Temperature Converter/Temperature Converter Program diff --git a/padmini/Temperature Converter/Temperature Converter Program b/padmini/Temperature Converter/Temperature Converter Program new file mode 100644 index 0000000..cf205b8 --- /dev/null +++ b/padmini/Temperature Converter/Temperature Converter Program @@ -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; + } +} From 2045c3ca13d3da7b5a4fe0fa1af23f83464b2813 Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sat, 4 May 2024 18:36:14 +0530 Subject: [PATCH 5/6] Create ToDoTask --- padmini/ToDoList/ToDoTask | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 padmini/ToDoList/ToDoTask diff --git a/padmini/ToDoList/ToDoTask b/padmini/ToDoList/ToDoTask new file mode 100644 index 0000000..5389266 --- /dev/null +++ b/padmini/ToDoList/ToDoTask @@ -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 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(); + } +} From ed18d3bc413da774ba72ec49a201d2aa917c9dab Mon Sep 17 00:00:00 2001 From: padhu-js-2004 <150575097+padhu-js-2004@users.noreply.github.com> Date: Sat, 4 May 2024 18:39:14 +0530 Subject: [PATCH 6/6] Create Calculator --- padmini/SimpleCalculator/Calculator | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 padmini/SimpleCalculator/Calculator diff --git a/padmini/SimpleCalculator/Calculator b/padmini/SimpleCalculator/Calculator new file mode 100644 index 0000000..445f701 --- /dev/null +++ b/padmini/SimpleCalculator/Calculator @@ -0,0 +1,79 @@ +import java.awt.*; +import java.awt.event.*; +class Calculator implements ActionListener +{ + Frame f=new Frame(); + Label l1 = new Label("First Number"); + Label l2 = new Label("Second Number"); + Label l3 = new Label("Result"); + TextField t1= new TextField(); + TextField t2= new TextField(); + TextField t3= new TextField(); + Button b1 = new Button("Add"); + Button b2 = new Button("Sub"); + Button b3 = new Button("Mul"); + Button b4 = new Button("Div"); + Button b5 = new Button("Cancel"); + Calculator() + { + l1.setBounds(50,100,100,20); + l2.setBounds(50,140,100,20); + l3.setBounds(50,180,100,20); + t1.setBounds(200,100,150,20); + t2.setBounds(200,140,150,20); + t3.setBounds(200,180,150,20); + b1.setBounds(50,250,70,20); + b2.setBounds(110,250,70,20); + b3.setBounds(170,250,70,20); + b4.setBounds(230,250,70,20); + b5.setBounds(290,250,70,20); + f.add(l1); + f.add(l2); + f.add(l3); + f.add(t1); + f.add(t2); + f.add(t3); + f.add(b1); + f.add(b2); + f.add(b3); + f.add(b4); + f.add(b5); + b1.addActionListener(this); + b2.addActionListener(this); + b3.addActionListener(this); + b4.addActionListener(this); + b5.addActionListener(this); + f.setLayout(null); + f.setVisible(true); + f.setSize(400,350); +} +public void actionPerformed(ActionEvent e) +{ + int n1 = Integer.parseInt(t1.getText()); + int n2 = Integer.parseInt(t2.getText()); + if(e.getSource()==b1) + { + t3.setText(String.valueOf(n1+n2)); + } + if(e.getSource()==b2) + { + t3.setText(String.valueOf(n1-n2)); + } + if(e.getSource()==b3) + { + t3.setText(String.valueOf(n1*n2)); + } + if(e.getSource()==b4) + { + t3.setText(String.valueOf(n1/n2)); + } + if(e.getSource()==b5) + { + System.exit(0); + } +} +public static void main(String [] args) +{ + new Calculator(); + } +}