Sunday, 27 October 2013

Package in java

// a simple package

package MyPack;

public class Balance{
    String name;
    double bal;

public Balance(String n, double b){
    this.name=n;
    this.bal=b;
    }

public void show(){
    if(bal<0)
    System.out.print("LESS THAN ZERO BALANCE -->");
    System.out.println(name +": $" +bal);
    } 
}

-------------------------------------------------------------------------------------------------------------------
import MyPack.Balance;
 
class AccountBalance{
    public static void main(String args[]){
        Balance current[] = new Balance[3];
       
        current[0] = new Balance("SATEESH BAGADHI", 502.53);
        current[1] = new Balance("JAGADHEESH K", 268.06);
        current[2] = new Balance("MURALI K ", -12.33);
       
        for (int i=0;i<3;i++)
        current[i].show();
   
    }
}