ElaKiri Programmer's Club

tery123

Well-known member
  • Feb 25, 2011
    6,031
    177
    63
    34
    PHP:
    class CLADemo1{  
     public static void main(String args[]){  
      try{  
       String name=args[0];  
       float price=Float.parseFloat(args[1]);  
       float VAT=Float.parseFloat(args[2]);  
       float Total=price+VAT;  
       System.out.println(name +" :  " + Total);  
      }catch(ArrayIndexOutOfBoundsException e){  
       System.out.println("Incorrect usage!");  
      }catch(NumberFormatException e){  
       System.out.println("Invalid number " + e.getMessage());  
      }  
     }  
    }

    meke FLOAT.parseFloat kiyala ai array index ekata assaign karala thiyenne???
     

    tery123

    Well-known member
  • Feb 25, 2011
    6,031
    177
    63
    34
    PHP:
    /** 
     *class  : Cube 
     *Author : Kanishka Dilshan 
     *Purpose: Demonstrate inheritance in Java 
     *Blog   : http://javaxclass.blogspot.com 
     */  
      
      
    class Cube {  
     protected int length;  
     protected int width;  
     protected int height;  
       
     public Cube(int l,int w,int h){  
      length=l;  
      width=w;  
      height=h;  
     }  
       
     public void setLength(int l){  
      length=l;   
     }  
       
     public void setWidth(int w){  
      width=w;   
     }   
       
     public void setHeight(int h){  
      width=h;   
     }  
       
     public int getVolume(){  
      return(length*width*height);  
     }  
      
     public void showInfo(){  
      System.out.println("Length \t:"+this.length);  
      System.out.println("Width  \t:"+this.width);  
      System.out.println("Height \t:"+this.height);  
      System.out.println("Volume \t:"+getVolume());  
     }  
    }

    PHP:
    /** 
     *class  : ColorCube 
     *Author : Kanishka Dilshan 
     *Purpose: Demonstrate inheritance in Java 
     *Blog   : http://javaxclass.blogspot.com 
     */  
      
    class ColorCube extends Cube {  
     String color;  
       
     public ColorCube(int l,int w,int h,String color){  
      //constructing the parent  
      super(l,w,h);  
      this.color=color;  
     }  
       
     public void setColor(String color){  
      this.color=color;  
     }  
       
     public void showInfo(){  
      super.showInfo();  
      System.out.println("Color \t:"+this.color);  
     }  
    }

    PHP:
    /** 
     *class  : InheritanceDemo 
     *Author : Kanishka Dilshan 
     *Purpose: Demonstrate inheritance in Java 
     *Blog   : http://javaxclass.blogspot.com 
     */  
      
    class InheritanceDemo {  
     public static void main(String args[]){  
      Cube cube1=new Cube(3,7,5);  
      ColorCube ccb1=new ColorCube(2,9,4,"Blue");  
        
      cube1.showInfo();  
      System.out.println("_____________________________");  
      ccb1.showInfo();  
        
      System.out.println("\nMaking changes to cube objects....");  
      cube1.setWidth(8);  
      ccb1.setColor("Yellow");  
      ccb1.setHeight(6); //this methods is inherited by the Cube class  
      System.out.println("New info. of modified objects\n");    
      cube1.showInfo();  
      System.out.println("_____________________________");  
      ccb1.showInfo();    
     }  
    }

    menna meke out put eke waradak thiyenawada???

    8wm6c0.png


    meke ccb1 kiyana object eke out put eka 2,9,6,108 ,yello neda???dewini para modify kalahama????
     
    Last edited: