Thursday 18 February 2016

Class Composition Example (Genealogy)


Person.java
  
   

package my.kkc.geneology;

public class Person {
    private String name;
    private Person father;
    private Person mother;

    public Person() {
        father = new Person();
        mother = new Person();
    }

    public Person(String name, Person father, Person mother) {
        this.name = name;
        this.father = father;
        this.mother = mother;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person getFather() {
        return father;
    }

    public void setFather(Person father) {
        this.father = father;
    }

    public Person getMother() {
        return mother;
    }

    public void setMother(Person mother) {
        this.mother = mother;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Person person = (Person) o;

        if (name != null ? !name.equals(person.name) : person.name != null) return false;
        if (father != null ? !father.equals(person.father) : person.father != null) return false;
        return mother != null ? mother.equals(person.mother) : person.mother == null;

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (father != null ? father.hashCode() : 0);
        result = 31 * result + (mother != null ? mother.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", father=" + father +
                ", mother=" + mother +
                '}';
    }
}
  
Marriage.java
  
   
package my.kkc.geneology;

public class Marriage {
    private Person husband;
    private Person wife;

    public Marriage() {
        husband = new Person();
        wife = new Person();
    }

    public Marriage(Person husband, Person wife) {
        this.husband = husband;
        this.wife = wife;
    }

    public Person getHusband() {
        return husband;
    }

    public void setHusband(Person husband) {
        this.husband = husband;
    }

    public Person getWife() {
        return wife;
    }

    public void setWife(Person wife) {
        this.wife = wife;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Marriage marriage = (Marriage) o;

        if (husband != null ? !husband.equals(marriage.husband) : marriage.husband != null) return false;
        return wife != null ? wife.equals(marriage.wife) : marriage.wife == null;

    }

    @Override
    public int hashCode() {
        int result = husband != null ? husband.hashCode() : 0;
        result = 31 * result + (wife != null ? wife.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Marriage{" +
                "husband=" + husband +
                ", wife=" + wife +
                '}';
    }
}
  
Main.java
  
   
package my.kkc.geneology;

public class Main {
    public static void main(String[] args) {
        geneologyFn();
    }
    static void geneologyFn() {
        Person a = new Person("Jivabhai",null,null);
        Person b = new Person("Jyotiben",null,null);
        Person c = new Person("Karsanbhai",a,b);
        Person d = new Person("Ambaben",null,null);
        Person e = new Person("Godadbhai",a,b);
        Person f = new Person("Navalben",null,null);
        Person g = new Person("Kundan",c,d);
        Person h = new Person("Vinod",e,f);

        Marriage m1 = new Marriage(a,b);
        Marriage m2 = new Marriage(c,d);
        Marriage m3 = new Marriage(e,f);

        System.out.println(g.getFather().getFather());
        System.out.println(h.getMother().getFather());

    }
}
  

Make Linked List in Java (Class Composition Example) without using built-in Class


LinkNode.java
  
   

package my.kkc.LinkedList;

public class LinkNode {
    private int no;
    private String name;
    public LinkNode next;

    public LinkNode(int no, String name) {
        this.no = no;
        this.name = name;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

  
LinkList.java
  
   
package my.kkc.LinkedList;

public class LinkList {

    private LinkNode first, last;

    public void insert(LinkNode linkNode) {
        if(first == null) {
            first = last = linkNode;
        } else {
            last.next = linkNode;
            last = linkNode;
        }
    }

    public void print() {
        LinkNode temp = first;
        while (temp!=null) {
            System.out.println(temp.getName()+" | "+temp.getNo());
            temp = temp.next;
        }
    }

    public LinkNode delete() {
        LinkNode temp = first;
        first = first.next;
        return temp;
    }
}

  
Main.java
  
   

package my.kkc.LinkedList;

public class Main {
    public static void main(String[] args) {
        LinkList linkList = new LinkList();

        linkList.insert(new LinkNode(121,"Midft"));
        linkList.insert(new LinkNode(122,"Midft"));
        linkList.insert(new LinkNode(123,"Midft"));

        linkList.print();
        linkList.delete();
        linkList.print();
    }
}
 
  

Tuesday 13 October 2015

Create Android Emulator using Command line


This video tutorial content following:

  • How to make Android emulator for test your Android apps
  • Use of command line in android sdk
  • How to change hardware setting for emulator
  • How to open avd manager using command line



Full Setup Android Environment for developing Android Application


This tutorial video content following:

  • Download android studio
  • Download android SDK
  • Install Android studio
  • Set environment variable 


Friday 9 October 2015

what's new in Whats App this week

Nowadays Whats app introduce its new feature for whats user that user can mute there friends notification. it is quite good feature for this user have many panic friends send random number massage every 4 to 5 minutes. 

Also feature like
  • make chat as read or unread 
  • new emoji
  • other language support like bangali and urdu 





Monday 5 October 2015

Find given string is palindrome or not using string library function.

  
   
#include<stdio.h>
#include<string.h>
void main() {
    char string[25], reverse_string[25] = {'\0'};
    int i, length = 0, flag = 0;
    printf("Enter a string \n");
    gets(string);
    length = strlen(string);
    printf("The length of the string '%s' = %d\n", string, length);
    for (i = length - 1; i >= 0; i--) {
        reverse_string[length - i - 1] = string[i];
    }
    for (i = 0; i < length; i++) {
        if (reverse_string[i] == string[i])
            flag = 1;
        else
            flag = 0;
    }
    if (flag == 1)
        printf("%s is a palindrome \n", string);
    else
        printf("%s is not a palindrome \n", string);
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

Write a program convert character(String) into TOggLe character(String)

  
   
#include<stdio.h>
void main() {
    char str[100];
    int i;
    printf("Please enter a string: ");
    gets(str);
    for (i = 0; str[i] != NULL; i++) {
        if (str[i] >= 'A' && str[i] <= 'Z')
            str[i] += 32;
        else if (str[i] >= 'a' && str[i] <= 'z')
            str[i] -= 32;
    }
    printf("String in toggle case is: %s", str);
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

Write a program to join two strings.

  
   
#include<stdio.h>
#include<string.h>
//#include<conio.h>
void main() {
    char a[100], b[100];
    printf("Enter the first string\n");
    gets(a);
    printf("Enter the first string \n");
    gets(b);
    strcat(a, b);
    printf("String after joining is %s\n", a);
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

Write a program to copy one string to another string.

  
   
#include<stdio.h>
//#include<conio.h>
void main() {
    char name1[100], name2[100];
    int i = 0;
    //clrscr();
    printf(" Please Give The STRING OF name1 \n:");
    gets(name1);
    while (name1[i] != '\0') {
        name2[i] = name1[i];
        i++;
    }
    name2[i] = name1[i];
    printf("string name1 is : % s\n", name1);
    printf("string name2 is : % s\n", name2);
    //getch();
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

Find length of string using strlen( ) function

  
   
#include<stdio.h>
#include<string.h>
#include<ctype.h>
//#include<conio.h>
void main() {
    int strlength;
    char str[100];
    //clrscr();
    printf("\nEnter the string: ");
    gets(str);
    strlength = strlen(str);
    printf("\nThe length of the string is %d.", strlength);
    //getch();
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.

Write a program to count total words in text.

  
   
#include<stdio.h>
#include<string.h>
#include<ctype.h>
//#include<conio.h>
void main() {
    char sen[100];
    int i, count = 1;
    //clrscr();
    printf("Enter a Sentence : \n");
    gets(sen);
    for (i = 0; i < strlen(sen); i++) {
        if (isspace(sen[i])) {
            count++;
        }
    }
    printf("Number of words in the sentence = %d", count);
    printf("\n");
    //getch();
}
Note: Remove the comment line when you are use Turbo C IDE for run your program.