Thursday, January 19, 2017

Interface in java !!

Tags

//This program helps you to understand the working of an interface



import java.util.Scanner; //package for scanning purpose
public class Purchase
{
int num,x;
Scanner obj=  new Scanner (System.in);
public void getinfo()
{
System.out.println("Enter the amount of packets purchased: ");
num=obj.nextInt();
System.out.println("Enter amount of defective packets: ");
x=obj.nextInt();

}

public static void main(String[] args)
{
result obj1=new result();
obj1.getinfo();
obj1.amtleft();
stock obj2=new result();
obj2.stk();
obj1.rslt();
}
}
class Preturn extends Purchase
{
int ret;
public void amtleft()
{
System.out.println("Amount left: ");
ret=num-x;
System.out.println(ret);

}
}
interface stock
{
public void stk();
Scanner ob = new Scanner (System.in);

}
class result extends Preturn implements stock
{
int y;

public void stk()
{
System.out.println("Enter previous stock if any: ");


}
public void rslt()
{
y= ob.nextInt();
System.out.println("Packets to be sold : "+(y+ret));
}



}