Sunday, January 29, 2017

Employee's Management in an Organization

Following program will help in managing employee's in an organization it ask details for each new employee and have functions for printing details of any employee and increment their salary by 5%.

Code::

import java.util.*;
class employee
{  Scanner in=new Scanner(System.in); 
    private String name;
    private double salary;
    private int year,month,day;
    employee()
    {
        System.out.print("Enter Name of Employee: ");
        name=in.nextLine();
        System.out.print("Enter Salary of Employee: ");
        salary=in.nextDouble();
        System.out.println("Enter Date of Joining(in DD/MM/YYYY format): ");
        System.out.print("Date:");
        day=in.nextInt();
        System.out.print("Month:");
        month=in.nextInt();
        System.out.print("Year: ");
        year=in.nextInt();
    }
    public void increment()
    {
        salary=salary+salary*0.05;
    }
    public void show()
    {
        System.out.println("Details of Employee: ");
        System.out.println("Name: "+name);
        System.out.println("Salary: "+salary);
        System.out.printf("Date of Joining: %d/%d/%d\n",day,month,year);
    }
}
public class Organization 
{
    public static void main(String[] nt) 
    {
        employee[] staff=new employee[2];
        staff[0]=new employee();
        staff[0].increment();
        staff[0].show();
    }
}

Output::


here you can declare any number of employees,i have declared only one and increment and show the details of that particular employee....

Lottery Draw Java

Following program will produce a ticket number with given no of digits randomly and will help in Lottery Draw :

Code::

import java.util.*;
public class LotteryDraw 
{
    public static void main(String[] nt) 
    {
        Scanner in=new Scanner(System.in);
        System.out.print("How many digits a ticket have: ");
        int k=in.nextInt();
        int [] num=new int[10];
        for(int i=0;i<num.length;i++)
        {
            num[i]=i;
        }
        int [] result=new int[k];
        for(int i=0;i<result.length;i++)
        {
            int r=(int)(Math.random()*10); //here 10 bcz the random function will produce positive value less than 1.0 
            result[i]=num[r];
        }
        System.out.print("So the Jackpot Ticket is: ");
        for(int i=0;i<result.length;i++)
        {
            System.out.print(result[i]);
        }
        System.out.println();
    }
}

Output::


Saturday, January 28, 2017

More Operations on datetime :)

Suppose we want to Display only current Month, Year or Day. Python allows us to do this through some predefined Functions.
Following Program Illustrates it:

from datetime import datetime
current=datetime.now(); #assigning variable
print(current.year);    #Current year
print(current.month);    #Current month
print(current.day);    #Current date




Functions for Time:

print(current.hour);    #Current Hour
print(current.minute);    #Current Minute
print(current.second);    #Current Second



Date and Time in Python :)

Python contains Library datetime which allows us to keep track of current Time and Date.
Following Program shows the usage of datetime Library:

from datetime import datetime  #importing datetime library
current=datetime.now();  #assigning variable to current date and time
print(current);



datetime.now() Function is used to get the current date and time.

Note: # keyword is used for Comments.

Common Elements In Two Lists

Question::
Define a function is_common() that takes two lists and returns True if they have at least one member in common, False otherwise.

Code::

def is_common(d,n):
    for i in d:
        for j in n:
             if(j==i):
              return True
    return False 
n=input("Enter list: ")
nt=n.split(",")    
d=input("Enter another list: ")
dm=d.split(",")
if(is_common(dm,nt)):
    print("Yes There are Common Elements")
else:
    print("No There are no Common Elements")
    

Output::




Searching value in a List

Question::

Write a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of aFalse otherwise.

Code::
def is_member(d,n):
    for i in n:
        if(d==i):
            return True
    return False 
n=input("Enter list:")
nt=n.split(",")    
d=input("Enter Value to be searched:")
if(is_member(d,nt)):
    print("Yes it is Present")
else:

    print("No it is not Present")


Output::


String Palindrome or Not Python

Question::

Define a function reverse() that computes the reversal of a string. For example, reverse("I am testing") should return the string "gnitset ma I".

Code::
def reverse(l):
    return"".join(l[i] for i in range(len(l)-1,-1,-1)) 
name=input("Enter String:")
rev=reverse(name)
print("Reverse is:",rev)
if(rev==name):
    print("String is Palindrome")
else:

    print("Not a Palindrome")

Output::