-----------------------------------------------------------------------------------------------------------------------------

 java Assignment programs. 

-----------------------------------------------------------------------------------------------------------------------------

 

(1).

import java.util.*;

class stringOperation{

    Scanner sc = new Scanner(System.in);

    StringBuffer str= new StringBuffer("hello my my my name is nevil");

    String s1 = new String(str);

    int p,sp,ep;

    String s;  

    void setString(){

    }

    void display(){

         System.out.print("String is:-");

            System.out.print(str);   

    }

    void insert(){

        System.out.print("Enter the position:-");

        p =sc.nextInt();

        sc.nextLine();

        

        System.out.print("Enter the String:-");

        s =sc.nextLine();    


        str.insert(p,s);

    }

    void search(){

        System.out.print("Enter the String which you want to search:-");

        s =sc.nextLine();    

        int c = 0;

        String word[] = s1.split(" ");

        for (int i = 0; i < word.length; i++)

        {

            if (s.equals(word[i])){

                 c++;

            }

        }

        System.out.println("String is :-"+c);

    }

    void del(){

        System.out.print("Enter the Starting position:-");

        sp =sc.nextInt();

        System.out.print("Enter the Ending position:-");

        ep =sc.nextInt();

        str.delete(sp, ep);

    }

}

class inserchdel {

    public static void main(String args[]){ 

        Scanner sc = new Scanner(System.in);

        stringOperation s = new stringOperation();

        int ch;

        do{

            System.out.println("\n\n1.insert");

            System.out.println("2.serach or count");

            System.out.println("3.delete");

            System.out.println("4.display");

            System.out.println("5.Exit");


            System.out.print("Enter the choise:-");

            ch = sc.nextInt();

            s.setString();

            switch(ch){

                case 1:

                    s.insert();        

                    break;

                case 2:

                    s.search();

                    break;

                case 3:

                    s.del();

                    break;

                case 4:

                    s.display();

                    break;

            }        

        }while(ch!=5);  

    }

}

-----------------------------------------------------------------------------------------------------------------------------

//19  applet


import java.applet.*;

import java.awt.*;


/*

    <applet code="appletdate2.class" height="500" width="500">

    </applet>

*/

public class appletdate2 extends Applet {

    public void paint(Graphics g) {

        int x[] = { 200, 100, 300 };

        int y[] = { 100, 300, 300 };

        g.setColor(Color.cyan);

        g.drawPolygon(x, y, 3);

        g.fillPolygon(x, y, 3);


        g.setColor(Color.yellow);

        g.drawOval(140, 180, 120, 120);

        g.fillOval(140, 180, 120, 120);


        g.setColor(Color.black);

        g.drawString("13 / 3 / 2022", 170, 250);

        // g.setColor(Color.cyan);

        // g.fillOval(100, 100, 200, 200);

    }

}




-----------------------------------------------------------------------------------------------------------------------------


//21  home


import java.applet.*;

import java.awt.*;


/*

<applet code="home.class" height="900" width="1000"></applet>

*/


public class home extends Applet{

public void paint(Graphics g){

int x[]={200,100,300};

int y[]={100,200,200};

g.setColor(Color.yellow);

g.fillPolygon(x,y,3);

g.drawPolygon(x,y,3);

g.setColor(Color.cyan);

g.fillRect(100,200,200,200);

g.drawRect(100,200,200,200);

g.setColor(Color.green);

g.fillRect(150,250,100,150);

g.drawRect(150,250,100,150);

g.setColor(Color.black);

int a[] ={200,600,600,300};

int b[] ={100,100,200,200};

g.drawPolygon(a,b,4);

g.fillPolygon(a,b,4);

g.setColor(Color.red);

g.fillRect(300,200,300,200);

g.drawRect(300,200,300,200);

g.setColor(Color.gray);

g.fillRect(400,250,100,100);

g.drawRect(400,250,100,100);

}

}



-----------------------------------------------------------------------------------------------------------------------------


//7

import java.util.*;


class Publisher

{

    int pubid;

    String pubName;


    Scanner sc = new Scanner(System.in);


    void setPublisher()

{

        System.out.print("Enter the publisher id:-");

        pubid = sc.nextInt();


        sc.nextLine();


        System.out.print("Enter the publisher Name:-");

        pubName = sc.nextLine();        

    }

}

class book extends Publisher{

    Scanner sc = new Scanner(System.in);

    

    int Bookid;

    String BookName;

    String Author;


    void setBookDetails(){

        System.out.print("Enter the book id:-");

        Bookid = sc.nextInt();


        sc.nextLine();


        System.out.print("Enter the book Name:-");

        BookName = sc.nextLine();    

        

        System.out.print("Enter the book Author:-");

        Author = sc.nextLine();    

    }

    void getBookDetails(){

        System.out.print("\npublisher id i1s:- "+pubid);

        System.out.print("\npublisher Name is:- "+pubName);

        System.out.print("\nbook id is:- "+Bookid);

        System.out.print("\nbook Name is:- "+BookName);

        System.out.print("\nAuthor is:- "+Author);

    }

}

class bookpub {

    public static void main(String args[]){

        book b = new book();

        b.setPublisher();

        b.setBookDetails();

        b.getBookDetails();

    }    

}



-----------------------------------------------------------------------------------------------------------------------------

//7
import java.util.*;

class Publisher
{
    int pubid;
    String pubName;

    Scanner sc = new Scanner(System.in);

    void setPublisher()
{
        System.out.print("Enter the publisher id:-");
        pubid = sc.nextInt();

        sc.nextLine();

        System.out.print("Enter the publisher Name:-");
        pubName = sc.nextLine();        
    }
}
class book extends Publisher{
    Scanner sc = new Scanner(System.in);
    
    int Bookid;
    String BookName;
    String Author;

    void setBookDetails(){
        System.out.print("Enter the book id:-");
        Bookid = sc.nextInt();

        sc.nextLine();

        System.out.print("Enter the book Name:-");
        BookName = sc.nextLine();    
        
        System.out.print("Enter the book Author:-");
        Author = sc.nextLine();    
    }
    void getBookDetails(){
        System.out.print("\npublisher id i1s:- "+pubid);
        System.out.print("\npublisher Name is:- "+pubName);
        System.out.print("\nbook id is:- "+Bookid);
        System.out.print("\nbook Name is:- "+BookName);
        System.out.print("\nAuthor is:- "+Author);
    }
}
class bookpub {
    public static void main(String args[]){
        book b = new book();
        b.setPublisher();
        b.setBookDetails();
        b.getBookDetails();
    }    
}