Tuesday, 1 April 2014

JAVA Programming : Inheritance - Interface - examples

import java.io.*;
interface access
{
public int str=54;
public void input();
public void calc();
public void printop();

}abstract class student implements access
{
int tot,fee;String stu=new String();String name=new String();
String grade =new String();
public void input()
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter your name\n");
name=br.readLine();
System.out.println("Enter your total \n");
stu=br.readLine();
tot=Integer.parseInt(stu);
System.out.println("Enter your Semester fees \n");
stu=br.readLine();
fee=Integer.parseInt(stu);grade="*****";
}
catch(Exception e)
{System.out.println("Student details are not given in correct format\n");}
}


 public void printop()
{
System.out.println("Name of the student is :  \n"+name);
System.out.println("Total Mark is \t " + tot  +"grade is \n"+ grade);
System.out.println("fee amount in $ :" + (fee/str)+"$\n");
}
}
class student1 extends student
{
public void calc()
{System.out.println("Demo for partial implementation of interface\n");
System.out.println("Abstract class Student cannot be instantated , so student1 class is generated by extending student\n");
}
}
class empl implements access
{
int sal,tax;String emp=new String();String name=new String();
public void input()
{


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Employee name\n");
name=br.readLine();
System.out.println("Enter your total income \n");
emp=br.readLine();
sal=Integer.parseInt(emp);
}
catch(Exception e)
{System.out.println("Enter your correct details\n");}
}

public void calc()
{
if (sal>500000)
{tax=10000;}
else if (sal>400000)
{tax=9000;}
else if (sal>300000)
{tax=8000;}
else
{tax=5000;}
}
 public void printop()
{System.out.println("Name of the Employee is :  \n"+name);
System.out.println("Total Income is \t " + sal  +"TAX  is \n"+ tax);
}
}
public class mulinh
{
    public static void main(String[] args)
    {
// Printing Student details
    student1 stud1=new student1();
    stud1.input();
    stud1.calc();
    stud1.printop();
// printing Employee details

    empl emp1=new empl();

    emp1.input();
    emp1.calc();
    emp1.printop();

    }
}



program2

import java.io.*;
interface access
{
public int str=54;
public void input();
public void calc();
public void printop();
}
interface access1 extends access
{
public void hobbies();
}
abstract class student implements access
{
int tot,fee;String stu=new String();String name=new String();
String grade =new String();
public void input()
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter your name\n");
name=br.readLine();
System.out.println("Enter your total \n");
stu=br.readLine();
tot=Integer.parseInt(stu);
System.out.println("Enter your Semester fees \n");
stu=br.readLine();
fee=Integer.parseInt(stu);grade="*****";
}
catch(Exception e)
{System.out.println("Student details are not given in correct format\n");}
}


 public void printop()
{
System.out.println("Name of the student is :  \n"+name);
System.out.println("Total Mark is \t " + tot  +"grade is \n"+ grade);
System.out.println("fee amount in $ :" + (fee/str)+"$\n");
}
}
class student1 extends student
{
public void calc()
{System.out.println("Demo for partial implementation of interface\n");
System.out.println("Abstract class Student cannot be instantated , so student1 class is generated by extending student\n");
}
}
class empbonus
{int bonus=20000;
}
class empl extends empbonus implements access
{
int sal,tax;String emp=new String();String name=new String();
public void input()
{


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Employee name\n");
name=br.readLine();
System.out.println("Enter your total income \n");
emp=br.readLine();
sal=Integer.parseInt(emp);
}
catch(Exception e)
{System.out.println("Enter your correct details\n");}
}

public void calc()
{
if (sal>500000)
{tax=10000;}
else if (sal>400000)
{tax=9000;}
else if (sal>300000)
{tax=8000;}
else
{tax=5000;}
}
 public void printop()
{System.out.println("Name of the Employee is :  \n"+name);
System.out.println("Total Income is \t " + sal  +"TAX  is \n"+ tax);
System.out.println("bonus \n" + bonus);
System.out.println("bonus  amount in $:" + (bonus/str)+"$\n");
}
}
public class mulinh1
{
    public static void main(String[] args)
    {
// Printing Student details
    student1 stud1=new student1();
    stud1.input();
    stud1.calc();
    stud1.printop();
// printing Employee details

    empl emp1=new empl();

    emp1.input();
    emp1.calc();
    emp1.printop();

    }
}
program 3
import java.io.*;
interface access
{
public int str=54;
public void input();
public void calc();
public void printop();
}
interface access1 extends access
{
public void hobbies();
}
abstract class student implements access
{
int tot,fee;String stu=new String();String name=new String();
String grade =new String();
public void input()
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter your name\n");
name=br.readLine();
System.out.println("Enter your total \n");
stu=br.readLine();
tot=Integer.parseInt(stu);
System.out.println("Enter your Semester fees \n");
stu=br.readLine();
fee=Integer.parseInt(stu);grade="*****";
}
catch(Exception e)
{System.out.println("Student details are not given in correct format\n");}
}


 public void printop()
{
System.out.println("Name of the student is :  \n"+name);
System.out.println("Total Mark is \t " + tot  +"grade is \n"+ grade);
System.out.println("fee amount in $ :" + (fee/str)+"$\n");
}
}
class student1 extends student
{
public void calc()
{System.out.println("Demo for partial implementation of interface\n");
System.out.println("Abstract class Student cannot be instantated , so student1 class is generated by extending student\n");
}
}
class empbonus
{int bonus=20000;
}
class empl extends empbonus implements access
{
int sal,tax;String emp=new String();String name=new String();
public void input()
{


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Employee name\n");
name=br.readLine();
System.out.println("Enter your total income \n");
emp=br.readLine();
sal=Integer.parseInt(emp);
}
catch(Exception e)
{System.out.println("Enter your correct details\n");}
}

public void calc()
{
if (sal>500000)
{tax=10000;}
else if (sal>400000)
{tax=9000;}
else if (sal>300000)
{tax=8000;}
else
{tax=5000;}
}
 public void printop()
{System.out.println("Name of the Employee is :  \n"+name);
System.out.println("Total Income is \t " + sal  +"TAX  is \n"+ tax);
System.out.println("bonus \n" + bonus);
System.out.println("bonus  amount in $:" + (bonus/str)+"$\n");
}
}
class stuhoppies extends student1 implements access1
{
public void hobbies()
{
System.out.println(" Reading books \n");}
}

class stuhoppies1  implements access1
{
public void hobbies()
{System.out.println(" Reading books \n");}
public void input()
{System.out.println(" input section \n");}
public void calc()
{ System.out.println(" Processing Part\n");}
public void printop()
{System.out.println(" End product section \n");}
}



public class mulinh2
{
    public static void main(String[] args)
    {
// Printing Student details
    student1 stud1=new student1();
    stud1.input();
    stud1.calc();
    stud1.printop();
// printing Employee details

    empl emp1=new empl();

    emp1.input();
    emp1.calc();
    emp1.printop();
// printing student details with extending student1 class and interface access1
stuhoppies stuhop1=new stuhoppies();
    stuhop1.input();
    stuhop1.calc();
    stuhop1.printop();
stuhop1.hobbies();
// extending interface
stuhoppies1 stuhop11=new stuhoppies1();
    stuhop11.input();
    stuhop11.calc();
    stuhop11.printop();
stuhop11.hobbies();


    }
}







program4

import java.io.*;
interface access
{
public int str=54;
public void input();
public void calc();
public void printop();
}
interface access1 extends access
{
public void hobbies();
}
abstract class student implements access
{
int tot,fee;String stu=new String();String name=new String();
String grade =new String();
public void input()
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter your name\n");
name=br.readLine();
System.out.println("Enter your total \n");
stu=br.readLine();
tot=Integer.parseInt(stu);
System.out.println("Enter your Semester fees \n");
stu=br.readLine();
fee=Integer.parseInt(stu);grade="*****";
}
catch(Exception e)
{System.out.println("Student details are not given in correct format\n");}
}


 public void printop()
{
System.out.println("Name of the student is :  \n"+name);
System.out.println("Total Mark is \t " + tot  +"grade is \n"+ grade);
System.out.println("fee amount in $ :" + (fee/str)+"$\n");
}
}
class student1 extends student
{
public void calc()
{System.out.println("Demo for partial implementation of interface\n");
System.out.println("Abstract class Student cannot be instantated , so student1 class is generated by extending student\n");
}
}
class empbonus
{int bonus=20000;
}
class empl extends empbonus implements access
{
int sal,tax;String emp=new String();String name=new String();
public void input()
{


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Employee name\n");
name=br.readLine();
System.out.println("Enter your total income \n");
emp=br.readLine();
sal=Integer.parseInt(emp);
}
catch(Exception e)
{System.out.println("Enter your correct details\n");}
}

public void calc()
{
if (sal>500000)
{tax=10000;}
else if (sal>400000)
{tax=9000;}
else if (sal>300000)
{tax=8000;}
else
{tax=5000;}
}
 public void printop()
{System.out.println("Name of the Employee is :  \n"+name);
System.out.println("Total Income is \t " + sal  +"TAX  is \n"+ tax);
System.out.println("bonus \n" + bonus);
System.out.println("bonus  amount in $:" + (bonus/str)+"$\n");
}
}
abstract class stuhoppies extends student implements access1
{
public void hobbies()
{
System.out.println(" Reading books \n");}
}
class stuhopabs extends stuhoppies
{
}

class stuhoppies1  implements access1
{
public void hobbies()
{System.out.println(" Reading books \n");}
public void input()
{System.out.println(" input section \n");}
public void calc()
{ System.out.println(" Processing Part\n");}
public void printop()
{System.out.println(" End product section \n");}
}



public class mulinh2
{
    public static void main(String[] args)
    {
// Printing Student details
    student1 stud1=new student1();
    stud1.input();
    stud1.calc();
    stud1.printop();
// printing Employee details

    empl emp1=new empl();

    emp1.input();
    emp1.calc();
    emp1.printop();
// printing student details with extending student1 class and interface access1
stuhopabs stuhop1=new stuhopabs();
    stuhop1.input();
    stuhop1.calc();
    stuhop1.printop();
stuhop1.hobbies();
// extending interface
stuhoppies1 stuhop11=new stuhoppies1();
    stuhop11.input();
    stuhop11.calc();
    stuhop11.printop();
stuhop11.hobbies();


    }
}














No comments:

Post a Comment