Sunday, 15 April 2012

Seven Segment

//Driver Method

sevenSegments ss = new sevenSegments(); 
int gapx = 100;     //gape between numbers
int gapy = 120;
int sizex = 100;        //width of segments
int sizey  = 100;      //height of segments
int xi = 0;         //innitial positions of frame
int yi = 30;          
void setup(){
size(750,300);        
}

void draw(){
  background(0);
 // fill(255,0,0);

ss.segment(sizex,sizey,xi+0,yi+0,0);      // object for each 0 and so on
ss.segment(sizex,sizey,xi+gapx,yi+0,1);
ss.segment(sizex,sizey,xi+gapx*2,yi+0,2);
ss.segment(sizex,sizey,xi+gapx*3,yi+0,3);
ss.segment(sizex,sizey,xi+gapx*4,yi+0,4);
ss.segment(sizex,sizey,xi+gapx*5,yi+0,5);
ss.segment(sizex,sizey,xi+gapx*6,yi+0,6);
ss.segment(sizex,sizey,xi+0,yi+gapy,7);
ss.segment(sizex,sizey,xi+gapx,yi+gapy,8);
ss.segment(sizex,sizey,xi+gapx*2,yi+gapy,9);
}

////////////Segments Class/////////////////

class sevenSegments{
  float  x1,x2,x3,x4,x5,x6,x7;        // x positions of segments
  float y1,y2,y3,y4,y5,y6,y7;         // y positions of segments
  float W1,W2,W3,W4,W5,W6,W7,H1,H2,H3,H4,H5,H6,H7;  // W and H , width and height of segments

void segment(int myWidtH, int myHeight, int x, int y, int myCase){


  W1=myWidtH*0.1;            
  W2=myWidtH*0.7;
  W3=W1;
  W4=W1;
  W5=W2;
  W6=W1;
  W7=W2;
  H1=myHeight*0.25;
  H2=myHeight*0.1;
  H3=H1;
  H4=H1;
  H5=H2;
  H6=H1;
  H7=H2;


x1=x+myWidtH*0.1;
x2=x+myWidtH*0.2;
x5=x2;
x6=x1;
x7=x2;

y1= y+myHeight*0.2;
y3=y1;
y4=y+myHeight*.55;
y6=y4;
x3=x+myWidtH*.9 ;
x4=x3;
y2=y+myHeight*.1;
y7=y+myHeight*.45;
y5=y+myHeight*.80;

switch(myCase){
case 0:                  // draw zero
fill(#30ED31);
rect(x1,y1,W1,H1);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x6,y6,W6,H6);
break;

case 1:                // draw one
fill(#FFFFFF);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
break;

case 2:              // draw two and so on upto 9
fill(#F548E1);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x5,y5,W5,H5);
rect(x6,y6,W6,H6);
rect(x7,y7,W7,H7);
break;

case 3:
fill(#F54716);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x7,y7,W7,H7);
break;

case 4:
fill(#F548E1);
rect(x1,y1,W1,H1);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
rect(x7,y7,W7,H7);
break;

case 5:
fill(#F54716);
rect(x1,y1,W1,H1);
rect(x2,y2,W2,H2);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x7,y7,W7,H7);
break;

case 6:
fill(#F548E1);
rect(x1,y1,W1,H1);
rect(x2,y2,W2,H2);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x6,y6,W6,H6);
rect(x7,y7,W7,H7);
break;

case 7:
fill(#FFFFFF);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
break;

case 8:
fill(#30FA38);
rect(x1,y1,W1,H1);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x6,y6,W6,H6);
rect(x7,y7,W7,H7);
break;

case 9:
fill(#FA4E30);
rect(x1,y1,W1,H1);
rect(x2,y2,W2,H2);
rect(x3,y3,W3,H3);
rect(x4,y4,W4,H4);
rect(x5,y5,W5,H5);
rect(x7,y7,W7,H7);
break;
}

}

}

Thursday, 12 April 2012

Openprocessing Reference Project

http://openprocessing.org/sketch/43932

Seven Segment Class Code

class sevenSegments{
public void segment(int w,int H ){

  float x=5;
float y=5;
float x1=w*.1;
float x2=w*.2;
float x3=w*.6;
float x4=x3;
float x5=x2;
float x6=x1;
float x7=x2;
float y1=H*.2;
float y2=H*.1;
float y3=y1;
float y4=H*.45;
float y5=H*.8;
float y6=y4;
float y7=H*.45;


 

rect(x1,y1,10,40);  // 1 upper left
rect(x2,y2,40,10);  // 2 upper
rect(x3,y3,10,40);  // 3 upper right
rect(x4,y4,10,40);  // 4 lower right
rect(x5,y5,40,10);  // 5 lower
rect(x6,y6,10,40);  // 6 lower left
rect(x7,y7,40,10);  // 7 Mid rect
}
}
sevenSegments ss= new sevenSegments();
void setup(){
 
size(300,300);


}
void draw(){
 
  background(200,100,200);
 
ss.segment(100,100);
}

Sunday, 8 April 2012


class A implements XYZ{
public void test(){}
}
-Since and interface is an abstract entity, it cannot be instantiated i.e. an object cannot be created just like an abstract class.
===
implement Vs. override
-implement means to provide a method body
-override means to replace the existing body with a newer one
-an implementer class MUST implement all methods of an interface otherwise it will become abstract
---
-An interface reference can be created to hold objects of implementor classes
Why:
Super class reference variable can be used to hold a child class object reference
e.g.
interface X{
public void t()
}
class A implements X{
public void t{}
}
int main(){
X refX = new A();
}
---

-an interface can inherit from other interfaces
Why:
an interface contains only method declarations and more method declarations can add to this list of declarations
e.g.
interface X{
public void a();
}
interface Y extends X{
public void b();
}
//the following class must provide implementation for both a() and b()
class ABC implements Y{
public void a(){}
public void b(){}
}
---


Abstract Class : Contain Abstract and Concrete Methods
Interface : Can extends Interface, Abstract Methods and Concrete class.

e.g

interface xyz
{
1 Method declare
2 Method declare
}
Class A implements xyz
{
1....(){}
2....(){}
}
If all the methods of interface class are not defined in the implement class, then it is called abstract class.

E.g:

interface xyz
{
1 Method declare
2 Method declare
}
Class A implements xyz
{
2....(){}
}

Question


Which statements about interfaces are true?

Select the two correct answers.

(a) Interfaces allow multiple implementation inheritance.

(b) Interfaces can be extended by any number of interfaces.

(c) Interfaces can extend any number of interfaces.

(d) Members of an interface are never static.

(e) Members of an interface can always be declared
static.

Clock

Clock:

SegmentsDot d;
Segments s;
SegmentsMnt m;
SegmentsSec sec;
void setup(){
size(600,200);
//noLoop();
}
void draw(){
for(int i = 0; i < 10; i ++){

}


m = new SegmentsMnt();
d = new SegmentsDot();
sec = new SegmentsSec();
d.dots();
s = new Segments();
fill(255,0,0);
if(keyPressed) {
background(0);
if (key == '0') {
s.Num0();
m.Num0();
sec.Num0();
}
if (key == '1') {
background(0);
s.Num1();
m.Num1();
sec.Num1();
}
if (key == '2') {
background(0);
s.Num2();
m.Num2();
sec.Num2();
}
if (key == '3') {
background(0);
s.Num3();
m.Num3();
sec.Num3();
}
if (key == '4') {
background(0);
s.Num4();
m.Num4();
sec.Num4();
}
if (key == '5') {
background(0);
s.Num5();
m.Num5();
sec.Num5();
}
if (key == '6') {
background(0);
s.Num6();
m.Num6();
sec.Num6();
}
if (key == '7') {
background(0);
s.Num7();
m.Num7();
sec.Num7();
}
if (key == '8') {
background(0);
s.Num8();
m.Num8();
sec.Num8();
}
if (key == '9') {
background(0);
s.Num9();
m.Num9();
sec.Num9();
}

} else {
//s.Num0();
}
}
public class Segments {

public void Num0(){
rect(20,20,10,50); // segment 1 top left vertical
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(20,80,10,50); // segment 6 bottom left
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal

}


public void Num1(){ // Number 1
rect(20,20,10,50); // segment 1 top left vertical
rect(20,80,10,50); // segment 6 bottom left
}
public void Num2(){
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(20,80,10,50); // segment 6 bottom left
rect(30,130,50,10); // segment 5 bottm horizontal
}
public void Num3(){
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal
}
public void Num4(){
rect(20,20,10,50); // segment 1 top left vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(80,80,10,50); // segment 4 bottom right

}
public void Num5(){
rect(30,10,50,10); // segment 2 top horizontal
rect(20,20,10,50); // segment 1 top left vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal

}
public void Num6(){
rect(30,10,50,10); // segment 2 top horizontal
rect(20,20,10,50); // segment 1 top left vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal
rect(20,80,10,50); // segment 6 bottom left

}
public void Num7(){
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(80,80,10,50); // segment 4 bottom right
}
public void Num8(){
rect(20,20,10,50); // segment 1 top left vertical
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(20,80,10,50); // segment 6 bottom left
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal
}
public void Num9(){
rect(20,20,10,50); // segment 1 top left vertical
rect(30,10,50,10); // segment 2 top horizontal
rect(80,20,10,50); // segment 3 top right vertical
rect(30,70,50,10); // segment 7 middle horizontal
rect(80,80,10,50); // segment 4 bottom right
rect(30,130,50,10); // segment 5 bottm horizontal
}

}
public class SegmentsDot
{
public void dots(){
rect(110,40,10,10);
rect(110,90,10,10);
rect(320,40,10,10);
rect(320,90,10,10);
}
}
public class SegmentsMnt extends Segments {

int gape = 130;
int gape2 = 210;
public void Num0(){
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(20+gape,80,10,50); // segment 6 bottom left
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal


rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(20+gape2,80,10,50); // segment 6 bottom left
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
}


public void Num1(){ // Number 1
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(20+gape,80,10,50); // segment 6 bottom left

rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(20+gape2,80,10,50); // segment 6 bottom left
}
public void Num2(){
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(20+gape,80,10,50); // segment 6 bottom left
rect(30+gape,130,50,10); // segment 5 bottm horizontal

rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(20+gape2,80,10,50); // segment 6 bottom left
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
}
public void Num3(){
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal

rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
}
public void Num4(){
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(80+gape,80,10,50); // segment 4 bottom right

rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(80+gape2,80,10,50); // segment 4 bottom right

}
public void Num5(){
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal

rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal


}
public void Num6(){
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal
rect(20+gape,80,10,50); // segment 6 bottom left

rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
rect(20+gape2,80,10,50); // segment 6 bottom left

}
public void Num7(){
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(80+gape,80,10,50); // segment 4 bottom right

rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(80+gape2,80,10,50); // segment 4 bottom right
}
public void Num8(){
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(20+gape,80,10,50); // segment 6 bottom left
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal

rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(20+gape2,80,10,50); // segment 6 bottom left
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
}
public void Num9(){
rect(20+gape,20,10,50); // segment 1 top left vertical
rect(30+gape,10,50,10); // segment 2 top horizontal
rect(80+gape,20,10,50); // segment 3 top right vertical
rect(30+gape,70,50,10); // segment 7 middle horizontal
rect(80+gape,80,10,50); // segment 4 bottom right
rect(30+gape,130,50,10); // segment 5 bottm horizontal

rect(20+gape2,20,10,50); // segment 1 top left vertical
rect(30+gape2,10,50,10); // segment 2 top horizontal
rect(80+gape2,20,10,50); // segment 3 top right vertical
rect(30+gape2,70,50,10); // segment 7 middle horizontal
rect(80+gape2,80,10,50); // segment 4 bottom right
rect(30+gape2,130,50,10); // segment 5 bottm horizontal
}

}
public class SegmentsSec extends SegmentsMnt {

int gape = 130;
int gape2 = 210;
int gape3 = 350;
int gape4 = 430;
public void Num0(){
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(20+gape3,80,10,50); // segment 6 bottom left
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal


rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(20+gape4,80,10,50); // segment 6 bottom left
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
}


public void Num1(){ // Number 1
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(20+gape3,80,10,50); // segment 6 bottom left

rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(20+gape4,80,10,50); // segment 6 bottom left
}
public void Num2(){
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(20+gape3,80,10,50); // segment 6 bottom left
rect(30+gape3,130,50,10); // segment 5 bottm horizontal

rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(20+gape4,80,10,50); // segment 6 bottom left
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
}
public void Num3(){
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal

rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
}
public void Num4(){
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(80+gape3,80,10,50); // segment 4 bottom right

rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(80+gape4,80,10,50); // segment 4 bottom right

}
public void Num5(){
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal

rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal


}
public void Num6(){
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal
rect(20+gape3,80,10,50); // segment 6 bottom left

rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
rect(20+gape4,80,10,50); // segment 6 bottom left

}
public void Num7(){
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(80+gape3,80,10,50); // segment 4 bottom right

rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(80+gape4,80,10,50); // segment 4 bottom right
}
public void Num8(){
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(20+gape3,80,10,50); // segment 6 bottom left
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal

rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(20+gape4,80,10,50); // segment 6 bottom left
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
}
public void Num9(){
rect(20+gape3,20,10,50); // segment 1 top left vertical
rect(30+gape3,10,50,10); // segment 2 top horizontal
rect(80+gape3,20,10,50); // segment 3 top right vertical
rect(30+gape3,70,50,10); // segment 7 middle horizontal
rect(80+gape3,80,10,50); // segment 4 bottom right
rect(30+gape3,130,50,10); // segment 5 bottm horizontal

rect(20+gape4,20,10,50); // segment 1 top left vertical
rect(30+gape4,10,50,10); // segment 2 top horizontal
rect(80+gape4,20,10,50); // segment 3 top right vertical
rect(30+gape4,70,50,10); // segment 7 middle horizontal
rect(80+gape4,80,10,50); // segment 4 bottom right
rect(30+gape4,130,50,10); // segment 5 bottm horizontal
}

}

Thursday, 5 April 2012

7 Segement Display Codes

Concrete Class

Function or Method
1   2  3
RT FN (PL)
{
//Body 4
}
-items 1,2,3 are called function header
-items 2,3 are know as function signature
-the function header is also know as declaration when written in an abstract class or interface
-items 1,2,3,4 are known as function definition
===
Important concepts:
Function Declaration
Function Definition
===
Concrete Class:
What:
A class that in which all methods are fully defined.
e.g.
class A{}
A is a class which has no methods in it but still it is a concrete class. It seems to be a useless class.
class B{
  private int x;
  public int getx(){ return x; };
  public void setx(int t){ x=t; }
  public String toString(){  return "" + x;  }
}
B is a concrete class also.
class C extends A{
  private int x;
  public int getx(){ return x; };
  public void setx(int t){ x=t; }
  public String toString(){  return "" + x;  }
}
C is also a concrete class inherited from A
===
Abstract Class:
What
It is an incomplete class i.e. it has some incomplete functionality
How:
by using the keyword abstract before class name
or declaring an abstract method in a class
or by inheriting a class from an abstract class
e.g.
abstract class P{
  public void dummy(){};
}
abstract class Q extends P{
 public abstract void test();
 public void full(){}
}
class R extends Q{
  public void full(){}
}
class T extends R{
  public void test(){}
}
class S extends P{}
the P class is abstract;
the Q class contains an abstract method
the R class is also abstract because it inherits an abstract method but does not override it
the T class is concrete because it properly overrides the test method from R

Wednesday, 4 April 2012

Khalid Mughal Book Link

Equivalence Class

Late Binding VS Early Binding

Dynamic binding and static binding have to do with inheritance. In Java, any derived class object can be assigned to a base class variable. For instance, if you have a class named Animal from which you derived the class Dog, you can do this:
Animal myAnimal = new Dog();
The variable on the left is type Animal, but the object on the right is type Dog. As long as the variable on the left is a base class of Dog, you are allowed to do that. Being able to do assignments like that sets up what is called “polymorphic behavior”: if the Dog class has a method that is the same as a method in the Animal class, then the version of the method in the Dog class will be called. For instance, if both classes define a method called show(), and you do this:
myAnimal.show();
the version of show() in the Dog class will be called. Even though you are using an Animal variable type to call the method show(), the version of show() in the Animal class won’t be executed. Instead, it is the version of show() in the Dog class that will be executed. The type of the object that is assigned to the Animal variable determines the method that is called.
So, when the compiler scans the program and sees a statement like this:
myAnimal.show();
it knows that myAnimal is of type Animal, but the compiler also knows that myAnimal can be a reference to any class derived from Animal. Therefore, the compiler doesn’t know what version of show() that statement is calling. It’s not until the assignment:
Animal myAnimal = new Dog();
is executed that the version of show() is determined. Since the assignment doesn’t occur until runtime, it’s not until runtime that the correct version of show() is known. That is known as “dynamic binding” or “late binding”: it’s not until your program performs some operation at runtime that the correct version of a method can be determined. In Java, most uses of inheritance involve dynamic binding.
“Static binding” or “early binding” occurs when the compiler can readily determine the correct version of something during compile time, i.e. before the program is executed. In Java, member variables have static binding because Java does not allow for polymorphic behavior with member variables. That means if both the Animal class and the Dog class have a member variable with the same name, it’s the base class version that is used. For instance, if you set up the necessary ingredients for polymorphic behavior:
Animal myAnimal = new Dog();
and both the Animal and Dog classes have a String member variable ‘type’, then if you do this:
String str = myAnimal.type;
the value of ‘type’ can be fully determined by the compiler. Because polymorphic behavior is not allowed for member variables, that statement is referring to the value of ‘type’ in the Animal class–not the Dog’s value for ‘type’. The result is: with member variables, it’s the type of the variable(e.g. myAnimal) that determines which version is called–not the type of the object the variable refers to(e.g. Dog). When the compiler is able to figure out the correct version of something during compilation, that’s known as static binding.
Here is an example of both dynamic and static binding:
class Animal
{
public String type = “mammal”;
public void show()
{
System.out.println(“The animal is a: ” + type);
}
}
class Dog extends Animal
{
public String type; //same member variable name as in base class
public Dog(String type)
{
this.type = type;
}
public void show() //same method signature as in base class
{
System.out.println(“The dog is a: ” + type);
}
}
public class DemoStaticBinding
{
public static void main(String[] args)
{
Animal doggie = new Dog(“daschund”);
doggie.show(); // “The dog is a: daschund” (dynamic binding)
System.out.println(“The type is: ” + doggie.type); //”The type is: mammal” (static binding)
}
}