Slip11

 Q1) Define an interface “Operation” which has method volume( ).Define a constant PI having a value 3.142 Create a class cylinder which implements this interface (members – radius,height). Create one object and calculate the volume. [10 marks] 

//slip 11_1

interface operation

{

       static double PI=3.14;

       double area();

       double volume();

}


class Cylinder implements operation

{

        int rad;

        int height; 

        Cylinder(int rad,int height)

        {

                this.rad=rad;

                this.height=height;  

        }

        public double  area()

        {

                System.out.print("\nArea of Cylinder:");

return 2*PI*rad*height + 2*PI*Math.pow(rad,2);                

        }

        public double volume()

        {

   System.out.print("\nVolume of Cylinder:");                  

  return PI*Math.pow(rad,2)*height;

        }

}

public class Ass3SetA3

{

        public static void main(String args[])

        {

                operation op = new Cylinder(3,4);            

                System.out.println(op.area()+"........");

                System.out.println(op.volume()+"......");               

        }

}

Q2) Write a program to accept the username and password from user if username and password are not same then raise "Invalid Password" with appropriate msg.

//Slip11_2

import java.util.Scanner;

class InvalidIDPasswordException extends Exception

{

        InvalidIDPasswordException() 

        {

           System.out.println("You Have entered Wrong Userid or Password");

        }

}


class InvalidEmailException extends Exception

{

        InvalidEmailException() 

        {

           System.out.println("The given Email id is invalid ");

        }

}

public class EmailCheck

{   

String UserName,password;

EmailCheck()

{

UserName=" ";

password=" ";

}

EmailCheck(String id,String pass)

{

UserName=id;

password=pass;

}

   public static void main(String args[])

   {  

        try

{

Scanner sc = new Scanner(System.in);

  System.out.println("Enter your Email id");

  String uname = sc.next();

System.out.println("Password");

  String pass = sc.next();

EmailCheck u1=new EmailCheck(uname,pass);

        if(u1.UserName.indexOf("@")>0 && u1.UserName.indexOf(".")>0)

     System.out.println("You have entered Valid Email Id");    

  else

throw new InvalidEmailException();

if((u1.UserName.equals("abc@gmail.com"))&& (u1.password.equals("123")))

System.out.println("Successful Login");    

  else

throw new InvalidIDPasswordException();

}

catch(InvalidEmailException e){}

catch(InvalidIDPasswordException e){}

    }    

}


Comments

Popular posts from this blog

Slip1

Slip3

Slip2