0% found this document useful (0 votes)
91 views3 pages

Program Based On Interface and Abstract Class: ///19BDS0083 VASANTH KUMAR

1. The document describes an interface called Exam that contains a method called Pass() that returns total marks. It also describes an interface called Classify that contains a method called Average() that returns a string. It then describes a class called Result that implements both interfaces - the Pass() method gets marks from the user and returns the total, and the Average() method calculates the average marks and returns a classification string. 2. It then describes an abstract class called Net with an abstract method called Process() that takes two double parameters. It creates a subclass called Discount that implements Process() using a formula to return a net amount, and a subclass called Tax that overrides the implementation to return a total using a different formula.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views3 pages

Program Based On Interface and Abstract Class: ///19BDS0083 VASANTH KUMAR

1. The document describes an interface called Exam that contains a method called Pass() that returns total marks. It also describes an interface called Classify that contains a method called Average() that returns a string. It then describes a class called Result that implements both interfaces - the Pass() method gets marks from the user and returns the total, and the Average() method calculates the average marks and returns a classification string. 2. It then describes an abstract class called Net with an abstract method called Process() that takes two double parameters. It creates a subclass called Discount that implements Process() using a formula to return a net amount, and a subclass called Tax that overrides the implementation to return a total using a different formula.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program Based on Interface and abstract class

1. Write an interface called Exam with a method Pass ( ) that returns the total marks.
Write another interface called Classify with a method Average (int total) which
returns a string. Write a Class called Result which implements both Exam and
Classify. The Pass method should get the marks from the user and finds the total
marks and return. The Division method calculate the average marks and return
“First” if the average is 60 or more, “SECOND” when average is 50 or more but
below 60, “NO DIVISION” when average is less than 50
CODE:

///19BDS0083 VASANTH KUMAR
import java.io.*;
import java.util.Scanner;

interface Exam
{
    boolean Pass(int mark);
}
 
interface Classify
{
    String Division(int avg);
}
 
class Result implements Exam,Classify
{
    public boolean Pass(int mark)
    {
            if(mark>=50)
                return true;
            else
                return false;
    }
 
    public String Division(int avg)
    {
        if(avg>=60)
            return "First";
        else if(avg>=50)
            return "Second";
        else
            return "No-Division";
    }   
}
 
public class Int {
    public static void main(String[] args) {
        boolean pass;
        int mark,avg;
        String division;
        Scanner in=new Scanner(System.in);
        Result res=new Result();
        for(int i=0;i<=2;i++)
        {

        
            System.out.println("Enter the mark : ");
            mark=Integer.parseInt(in.nextLine());
            System.out.println("Enter the average : ");
            avg=Integer.parseInt(in.nextLine());
            pass=res.Pass(mark);
            division=res.Division(avg);
            if(pass)
                System.out.println("Passed - "+ division + ".");
            else
                System.out.println("Failed - " + division+ ".");
        }
        
    }
}

OUTPUT:

2. Write an abstract class special with an abstract method double Process (double
P,double R). Create a subclass Discount and implement the Process() method
with the following formula: net=P-P*R/100. Return the Process() method with
the following formula: total=P+P*R/100. Return the total.
CODE:

import java.util.*;
import java.util.Scanner;
//19BDS0083 D VASANTH KUMAR
abstract class Net
{
    double p;double r;
    abstract void Process(double P,double R);
}
class Discount extends Net
{
    public void Process(double x,double y)
    {
    p=x;r=y;
    }
public double getdata()
{
    double net=p-p*r/100;
    return net;
}
}
class Tax extends Discount
{
    public double getdata()
    {
        double total=p+p*r/100;
        return total;
    }
}
   

public class abstract2 {
    public static void main(String[] args)
    {
       Discount ob1=new Discount();
       Tax ob2=new Tax();
       System.out.println("\nEnter the values of P and R:");
       Scanner a=new Scanner(System.in);
       double u=a.nextDouble();
       Scanner b=new Scanner(System.in);
       double v=b.nextDouble();
       ob1.Process(u, v);
       ob2.Process(u,v);
       System.out.println("\nThe net and Total is:"+ob1.getdata()+" and "+ob2.getdata());
    }
    
}
OUTPUT:

You might also like