OneCompiler

Singleton_Null_Employee

114

Singleton Pattern:
package singleton;

public class SingleObject {

   //create an object of SingleObject
   private static SingleObject instance = new SingleObject();

   //make the constructor private so that this class cannot be
   //instantiated
   private SingleObject(){}

   //Get the only object available
   public static SingleObject getInstance(){
      return instance;
   }

   public void showMessage(){
      System.out.println("Hello World!");
   }
}

package singleton;

public class SingletonPatternDemo {
public static void main(String[] args) {

      //illegal construct
      //Compile Time Error: The constructor SingleObject() is not visible
      //SingleObject object = new SingleObject();

      //Get the only object available
      SingleObject object = SingleObject.getInstance();

      //show the message
      object.showMessage();
   }
}

#p2.Write a Python Program to find all null values in a given data set andd remove them
import pandas as pd
#import matplotlib.pyplot as plt
df=pd.read_csv('iris_null_values.csv')
print(df)
df.isnull().sum()
df[df['sepal.length'].isnull()]
df[df['sepal.width'].isnull()]
df.fillna('default')

#df.dropna()

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employee Registration</title> <script> function validateForm() { var dob = document.getElementById('dob').value; var joiningDate = document.getElementById('joiningDate').value; var salary = document.getElementById('salary').value;
        var dateRegex = /^\d{4}-\d{2}-\d{2}$/;
        var salaryRegex = /^\d+$/;

        var currentDate = new Date();
        currentDate.setDate(currentDate.getDate() - 1); // Adjust for one day less than the current date

        var dobDate = new Date(dob);
        var joiningDateDate = new Date(joiningDate);

        if (!dateRegex.test(dob) || !dateRegex.test(joiningDate)) {
            alert('Invalid date format. Please enter valid dates (YYYY-MM-DD).');
            return false;
        }

        if (dobDate >= currentDate || joiningDateDate >= currentDate) {
            alert('DOB and Joining Date should be less than the current date.');
            return false;
        }

        if (!salaryRegex.test(salary) || salary <= 0) {
            alert('Invalid salary. Please enter a positive number for salary.');
            return false;
        }

        // If all validations pass, the form will be submitted
        alert('Employee registered successfully!');
        return true;
    }
</script>
</head> <body> <form id="employeeForm" onsubmit="return validateForm()"> <label for="dob">Date of Birth:</label> <input type="date" id="dob" name="dob" required>
    <label for="joiningDate">Joining Date:</label>
    <input type="date" id="joiningDate" name="joiningDate" required>

    <label for="salary">Salary:</label>
    <input type="number" id="salary" name="salary" required>

    <button type="submit">Submit</button>
</form>
</body> </html>