Basic Java learning - Ignou MCA students

Session 4  ex 2




class players {
String name,age;
}
class cricket_players extends players
{
    void get_data(String n,int age)
    {
        System.out.println("Name : "+n + "Age "+age);
    }
}
class football_players extends players
{
    void get_data(String n,int age)
    {
        System.out.println("Name : "+n + "Age "+age);
    }
}
class hockey_players extends players
{
    void get_data(String n,int age)
    {
        System.out.println("Name : "+n + "Age "+age);
    }
}

class ketan
{
    public static void main(String args[])
    {
        cricket_players c=new cricket_players();
        football_players f=new football_players();
        hockey_players h=new hockey_players();
       
        c.get_data("ABC",25);
        f.get_data("ABCD",28);
        h.get_data("ABCE",35);
    }
}
==================================================================

session 4 ex-3


class worker
{
String name;
int rate=20;
}
class dailyworker extends worker
{
    void compay(int h)
    {
       
    }
}
class salariedworker extends worker
{
    void compay(int h)
    {
        System.out.println("Total salary "+40*rate);
    }
}


public class session4_ex3 {
public static void main(String args[])
{
    dailyworker d=new dailyworker();
    salariedworker s =new salariedworker();
    d.compay(15);
    s.compay(34);
}
}
==============================================================
session 5 ex 1

package balance;
public class account {
   
public int display_balances()
{int bal;
    bal=5000;
    return(bal);
}
}

import balance.account;
public class pkg {

    public static void main(String args[])
    {
        int bal;
        account a=new account();
        bal=a.display_balances();
        System.out.println("Balance is "+ bal);
    }
}

======================================================
session 5 ex 2

interface kd
{
    public float pie=3.14f;
    public void cal();
}

class demo implements kd
{
    public void cal()
    {
    System.out.println("Area is "+ pie*16);
    }
}

public class interface_demo
{
public static void main(String args[])
{
    demo d =new demo();
    d.cal();   
}
}

============================================================
session 5 ex 3


package session5_ex3;

interface kd
{
    public int a=10,b=3;
    public void division();
    public void modules();
   
}
class cal implements kd
{
    public void division()
    {
        System.out.println("Division is "+a/b);
    }
    public void modules()
    {
        System.out.println("Modules is "+a%b);
    }
}
public class inter_demo {

    public static void main(String args[])
    {
        cal a=new cal();
        a.division();
        a.modules();
    }
}
=========================================================

session 7 ex 1

package session7;

class a extends Thread
{
   
public void run()
{int i;
    for(i=0;i<=10;i++)
        System.out.println("Thread One is active " + i);
    if (i==45)
    {
        try {
            a.sleep(200);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
}
class b extends  Thread
{int i;
    public void run()
    {
        for(i=0;i<=10;i++)
            System.out.println("Thread two is active " + i);
    }
}
class c extends Thread
{
    public void run()
    {int i;
        for(i=0;i<=10;i++)
            System.out.println("Thread three is active " + i);
    }
}
public class Ex1 {
public static void main(String args[])
{
    a a=new a();
    b b=new b();
    c c=new c();
    a.start();
    b.start();
    c.start();
    //a.setPriority(10);
    //b.setPriority(8);
}
}
=========================================================

session 8 ex 1

package session8_ex1;

public class Ex1 {
public static void main(String args[])
{
    String name="Palanpuar";
    int i,ch,count=0,pos;
    System.out.println("Name length "+ name.length());
   
    ch=name.charAt(0);
    for(i=0;i<=name.length();i++)
    {
        if(name.charAt(i)=='a')
        {
            count++;
            System.out.println("A found on position "+ i);
        }
    }
    System.out.println("Total occurance "+count);
   
}
}
============================================================

session 8 ex 2

package session8_ex2;

public class Ex2 {
public static void main(String args[])
{
    StringBuffer s=new StringBuffer("ketan");
    String s1="ketan";
   
    System.out.println("Capacity "+s.capacity());
    System.out.println("Reverse "+s.reverse());
    System.out.println("Upper Case "+ s1.toUpperCase());
    System.out.println("Appended "+s.append(s1));
}
}
==============================================================

Comments

Popular posts from this blog

Applet Not initialized properly’ Error in Finacle – Solution

Create an HTML document giving details of your name, age, telephone number, address, TLC code & enrolment number aligned in proper order.

Fresh installation of CSI Applications and Database