Java code to illustrate package and Interface.

Here screenshot shows two packages -First and second.
Package First contains Interface myinterface.(myinterface.java)
Package second contains Class Banking(Banking.java)





myinterface.class 


package First;

public interface myinterface {
public void createAccount(int v);
public void displayBalance();
public void displayRecords();
public void updateBalance(int val);

}


Banking.java

package second;
import java.util.Scanner;

import First.myinterface;
public class Banking implements myinterface{
static int no;
int account_no;
int balance;
String Cust_name;

void getdata()
{
System.out.println("Enter Balance");
Scanner sc=new Scanner(System.in);
balance=sc.nextInt();
System.out.println("Enter Customer Name");
Cust_name=sc.next();
}
public void createAccount(int val)
{
account_no=val;
getdata();
}

int getAccno()
{
return account_no;
}

public void displayBalance()
{
System.out.println(balance);
}
public void displayRecords()
{


System.out.println(Cust_name+"   "+account_no+"  "+balance+"  ");
}
public void updateBalance(int val)
{
balance=val;
}
public static void main(String args[])
{
Banking[] accounts = new Banking[70];
for ( int i=0; i<accounts.length; i++) {
accounts[i]=new Banking();
}
String ch="y";
int i=0;
int total_accouts=0;
int menu_choice;
int ano;
while(ch.equals("y") || ch.equals("Y"))
{
System.out.println("1.Create Account");
System.out.println("2.Dispay  Balance of particular Account");
System.out.println("3.Display All records");
System.out.println("4.Update Balance of particular Account");
System.out.println("Enter your Choice");
Scanner sc1=new Scanner(System.in);
menu_choice=sc1.nextInt();
switch(menu_choice)
{
case 1:
no=no+1;
accounts[total_accouts].createAccount(no);
            total_accouts=total_accouts+1;

break;
case 2:int flag=0;
System.out.println("Enter account no");
int num=sc1.nextInt();
for(int n1=0;n1<total_accouts;n1++)
if(num==accounts[n1].getAccno())
{flag=1;
accounts[n1].displayBalance();
}
if(flag==0)
System.out.println("Record not found");

break;
case 3:
for(int n1=0;n1<total_accouts;n1++)
accounts[n1].displayRecords();
break;
case 4:int flag1=0;
System.out.println("Enter Account No");
int num1=sc1.nextInt();
for(int n1=0;n1<total_accouts;n1++)
{
if(num1==accounts[n1].getAccno())
{flag1=1;
System.out.println("Enter new balance");
//sc1=new Scanner(System.in);
int val=sc1.nextInt();
accounts[n1].updateBalance(val);
//accounts[n1].displayBalance();
}
}
if(flag1==0)
System.out.println("Record not found");

break;
}

System.out.println("Do you want to continue(y/n)?");
sc1=new Scanner(System.in);
ch=sc1.next();
}
}
}


/*
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
1
Enter Balance

1000
Enter Customer Name

spp
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
2
Enter account no
1
1000
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
2
Enter account no
4
Record not found
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
3
spp   1  1000 
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
1
Enter Balance
4000
Enter Customer Name
pss
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
3
spp   1  1000 
pss   2  4000 
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
4
Enter Account No
2
Enter new balance
10000
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
3
spp   1  1000 
pss   2  10000 
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
4
Enter Account No
10
Record not found
Do you want to continue(y/n)?
y
1.Create Account
2.Dispay  Balance of particular Account
3.Display All records
4.Update Balance of particular Account
Enter your Choice
3
spp   1  1000 
pss   2  10000 
Do you want to continue(y/n)?
*/



Popular posts from this blog

DDL DML DCL and TCL

Implementation of Calculator using lex and yacc

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.