Saturday, October 10, 2020

write python turtle program to draw letter E

 import turtle

t=turtle.Turtle()

t.penup()

t.setpos(0,50)

t.pendown()

t.pensize(20)

t.pencolor("red")

t.forward(100)

t.backward(100)

t.right(90)

t.forward(100)

t.left(90)

t.forward(100)

t.backward(100)

t.right(90)

t.forward(100)

t.left(90)

t.forward(100)

write python turtle program for creating Archimedean spiral

 from turtle import *

from math import *

color("blue")

down()

for i in range(200):

    t = i / 20 * pi

    x = (1 + 5 * t) * cos(t)

    y = (1 + 5 * t) * sin(t)

    goto(x, y)

up()

done()

write a python program for creating a class Student with method and constructor

class student:

  def __init__(self,name,age):

        self.name=name

        self.age=age


  def myfunc(self,a,b):

        a=a+b

        return a


p1=student("john",23)

print("My names is",p1.name)

d=p1.myfunc(2,3)

print("sum is",d)

write a python program for creating class person with adding constructor, method

 class Person:

  def __init__(self, name, age):

    self.name = name

    self.age = age


  def myfunc(self):

    print("Hello my name is " + self.name)


p1 = Person("John", 36)

p1.myfunc()

write a java program for demonstration of Finally block

 class Finally1 

{

public static void main(String[] args) 

{

int data =20;

//case 4:finally block not exceuted when use the following method

System.exit(0);

try

{

int c=data/0;

System.out.println("c value is"+c);

}

finally

{

System.out.println("Finally block exceuted");

}

System.out.println("rest of the code exceuted");

}

}


write a java program for exception propagation

 class  Exceptionprop

{

static void s()

{

int data= 20/0;

}

static void  n()

{

        s();

}

static void  m()

{

n();

}

public static void main(String[] args) 

{

m();

System.out.println("Exception Caught at m()");

}

}


write a java program for creating own exception

class InvalidageExeption extends Exception 

{

InvalidageExeption(String s)

{

super(s);

}

}



class TestException 

{

static void validate(int age) throws InvalidageExeption

{

if(age<18)

throw new InvalidageExeption("not valid");

}

public static void main(String[] args) throws InvalidageExeption

{

validate(13);


}

}

 

Sunday, October 4, 2020

write a java program creating static variables?

class static12 

{

int x=5;

int y=10;

static int z=7;

public static void main(String[] args) 

{

      static12  s1=new static12();

System.out.println(s1.x+s1.y);

         System.out.println(z);

}

}

 

write a java program using throw keyword ?

 class Ex2 

{

static void  validate(int age)

{

if(age<18)

throw new ArithmeticException("not valid");

else

       System.out.println("age is valid");

}

public static void main(String[] args) 

{

try

{

validate(13);

}

catch(Exception e)

{

System.out.println(e);

}

System.out.println("rest of code");

}

}


write a java program for generating arithmetic exception division by zero

 class  Ex1

{

public static void main(String[] args) 

{

int a=5;

try

{

float b=5/0;

}

catch(Exception e)

{

System.out.println("exception caught");

       System.out.println(e);


}

      System.out.println("rest of code");

}

}


write a java program demonstrating relationship between abstract class and interface

 interface In

{

public void ms();

}

interface In1 extends In

{

public void msg();

}

abstract class  A23 implements In1

{

public void msg1()

{

System.out.println("abstract class method");

}

}

class A21 extends A23

{

public void msg()

{

System.out.println("In1 interface is implemented");

}

public void ms()

{

System.out.println("In interface is implemented");

}

public static void main(String[] args) 

{

A21 a1=new A21();

a1.msg();

a1.msg1();

a1.ms();

}

};

write a java program for exhibiting multiple inheritance through the interfaces

 interface showbale

{

void show();

static void print()

{

System.out.println("Hello World!");

}

}

interface printable

{

void print();

}

class  A221 implements showbale,printable

{

public void show()

{

System.out.println("Hello World!");

}

public void print()

{

System.out.println("Hello World!");

}

public static void main(String[] args) 

{

A221 a2=new A221();

a2.print();

a2.show();

}

}