Sunday, 8 April 2012

Graph of polynomials




int x=0;
int u=0;
int y=0;
void setup(){
background(0,0,0);
size(400,400);
stroke(255,255,255);// colour of point
line(0,200,400,200);//axis lin
line(200,0,200,400);//axis line
noLoop();// removing the loop
}
void draw(){
for(int i=-20; i<=20; i++)
{
u=2*i*i+i+1; /// This is the line where you have to put your equation///
pointg(i,u);
}

}
void pointg(int p,int k)
{
int x1=200; // value of initial x
int y1=200;// inital y
x1+=p*10;// the formula for locating x points
y1-=k*10;// the formula for locating y point
stroke(255,255,255);
strokeWeight(4);
point(x1,y1);// poiint
x=x1;
y=y1;
}



7 segment Display processing code


Main class

void setup(){
size(1000,200);


}
void draw(){
  background(255);
   int s = second();
   int m=minute();
   int h=hour();
segment s1= new segment(150,300,h);
s1.calc();
segment s2=new segment(490,640,m);
s2.calc();
segment s3=new segment(790,940,s);
s3.calc();
}

//////////////////////////////////////////////


class of the segment
///////////////////////////////////////////

class segment {
  private int sizeofobject;
  private int sizeofobject2;
  private int minutes;
  private int c1=0, c2=0;


  public segment(int sizeofobject, int sizeofobject2, int minutes) {
    this.sizeofobject=sizeofobject;
    this.minutes=minutes;
    this.sizeofobject2=sizeofobject2;
  }

  void container1(int cases) {
    line(sizeofobject, 0, sizeofobject, height);
    switch (cases) {
    case 0:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle
      rect(sizeofobject-140, 25, 15, 70);//up right
      rect(sizeofobject-25, 25, 15, 70);// up left

      rect(sizeofobject-140, 110, 15, 70);//down right
      rect(sizeofobject-25, 110, 15, 70); //down left
      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 1:
     fill(234, 123, 21);

      rect(sizeofobject-25, 25, 15, 160);// up left

      break;
    case 2:
     fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle

      rect(sizeofobject-25, 25, 15, 70);// up left
      rect(sizeofobject-140, 95, 130, 15);// middle
      rect(sizeofobject-140, 110, 15, 70);//down right

      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 3:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle

      rect(sizeofobject-25, 25, 15, 70);// up left
      rect(sizeofobject-140, 95, 130, 15);// middle

      rect(sizeofobject-25, 110, 15, 70); //down left
      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 4:
  fill(234, 123, 21);
      rect(sizeofobject-140, 25, 15, 70);//up right
      rect(sizeofobject-25, 25, 15, 70);// up left
      rect(sizeofobject-140, 95, 130, 15);// middle

      rect(sizeofobject-25, 110, 15, 70); //down left

      break;
    case 5:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle
      rect(sizeofobject-140, 25, 15, 70);//up right

      rect(sizeofobject-140, 95, 130, 15);// middle

      rect(sizeofobject-25, 110, 15, 70); //down left
      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 6:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle
      rect(sizeofobject-140, 25, 15, 70);//up right

      rect(sizeofobject-140, 95, 130, 15);// middle
      rect(sizeofobject-140, 110, 15, 70);//down right
      rect(sizeofobject-25, 110, 15, 70); //down left
      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 7:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle

      rect(sizeofobject-25, 25, 15, 160);// up left


      break;
    case 8:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle
      rect(sizeofobject-140, 25, 15, 70);//up right
      rect(sizeofobject-25, 25, 15, 70);// up left
      rect(sizeofobject-140, 95, 130, 15);// middle
      rect(sizeofobject-140, 110, 15, 70);//down right
      rect(sizeofobject-25, 110, 15, 70); //down left
      rect(sizeofobject-140, 180, 130, 15);// last
      break;
    case 9:
      fill(234, 123, 21);
      rect(sizeofobject-140, 10, 130, 15);//top rectangle
      rect(sizeofobject-140, 25, 15, 70);//up right
      rect(sizeofobject-25, 25, 15, 70);// up left
      rect(sizeofobject-140, 95, 130, 15);// middle

      rect(sizeofobject-25, 110, 15, 70); //down left

      break;
    }
  }
  void container2(int cases) {
    line(sizeofobject2, 0, sizeofobject2, height);
    switch (cases) {
    case 0:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle
      rect(sizeofobject2-140, 25, 15, 70);//up right
      rect(sizeofobject2-25, 25, 15, 70);// up left

      rect(sizeofobject2-140, 110, 15, 70);//down right
      rect(sizeofobject2-25, 110, 15, 70); //down left
      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 1:
  fill(234, 123, 21);
      rect(sizeofobject2-25, 25, 15, 160);// up left

      break;
    case 2:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle

      rect(sizeofobject2-25, 25, 15, 70);// up left
      rect(sizeofobject2-140, 95, 130, 15);// middle
      rect(sizeofobject2-140, 110, 15, 70);//down right

      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 3:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle

      rect(sizeofobject2-25, 25, 15, 70);// up left
      rect(sizeofobject2-140, 95, 130, 15);// middle

      rect(sizeofobject2-25, 110, 15, 70); //down left
      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 4:
  fill(234, 123, 21);
      rect(sizeofobject2-140, 25, 15, 70);//up right
      rect(sizeofobject2-25, 25, 15, 70);// up left
      rect(sizeofobject2-140, 95, 130, 15);// middle

      rect(sizeofobject2-25, 110, 15, 70); //down left

      break;
    case 5:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle
      rect(sizeofobject2-140, 25, 15, 70);//up right

      rect(sizeofobject2-140, 95, 130, 15);// middle

      rect(sizeofobject2-25, 110, 15, 70); //down left
      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 6:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle
      rect(sizeofobject2-140, 25, 15, 70);//up right

      rect(sizeofobject2-140, 95, 130, 15);// middle
      rect(sizeofobject2-140, 110, 15, 70);//down right
      rect(sizeofobject2-25, 110, 15, 70); //down left
      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 7:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle

      rect(sizeofobject2-25, 25, 15, 160);// up left

      break;
    case 8:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle
      rect(sizeofobject2-140, 25, 15, 70);//up right
      rect(sizeofobject2-25, 25, 15, 70);// up left
      rect(sizeofobject2-140, 95, 130, 15);// middle
      rect(sizeofobject2-140, 110, 15, 70);//down right
      rect(sizeofobject2-25, 110, 15, 70); //down left
      rect(sizeofobject2-140, 180, 130, 15);// last
      break;
    case 9:
      fill(234, 123, 21);
      rect(sizeofobject2-140, 10, 130, 15);//top rectangle
      rect(sizeofobject2-140, 25, 15, 70);//up right
      rect(sizeofobject2-25, 25, 15, 70);// up left
      rect(sizeofobject2-140, 95, 130, 15);// middle

      rect(sizeofobject2-25, 110, 15, 70); //down left

      break;
    }
  }
  void calc()
  {
    if (minutes<=9)
    {
      container1(0);
      container2(minutes);
    }
    else
    {
      c1=minutes%10;
      c2=minutes/10;
      container1(c2);
      container2(c1);
    }
  }
}


Saturday, 3 March 2012

Testing in console


import java.util.*;
public class Driver {

 
    public static void main(String[] args) {
        // TODO code application logic here
  System.out.print("Welcome to the test");
  Questions n=new Questions();
  for(int i=0; i<=3; i++){
   
      n.Ask(i);
   
  }
 n.result();
    }
}



import java.util.*;

public class Questions {

   public String[] q = {
       "WHich one is a multiple of 2",
       "WHos is the founder of pakistan",
       "Who is the founder of apple",
       "which one is a prime number"
   }, choice = {
       "1) 0.5   2) 5     3) 4    ",
       "1) MR zx        2) Qauid e azam     3) aer  ",
       "1) You   2) me     3) steve jobs    ",
       "1) 5   2) 4     3) 2    "
   };
   private int[] ans = {1, 2, 3, 5};
   private int correct = 0, wrong = 0, score;

   public Questions() {
   }
   Scanner in = new Scanner(System.in);
   public int[] stans = new int[ans.length];

     public void setq(String q,int index){this.q[index]=q;}
   public String getq(int index) {
       return q[index];
   }
      public void setchoice(String c,int index){this.choice[index]=c;}

   public String getchoice(int index) {
       return choice[index];
   }

   public void Ask(int index) {
       System.out.println(q[index]);
       System.out.println(choice[index]);
       stans[index] = in.nextInt();
       if(stans[index]<=0 || stans[index] >= 4){
        System.out.println("Wrong input your anser must be in between 1 and 3");
        stans[index] = in.nextInt();    
       }
       correct(stans[index], index);

   }

   public void correct(int stands, int index) {
       if (stans[index] == ans[index]) {
           correct++;
                                                                             score += 3;
       } else {
           wrong++;
           score -= 1;
       }
   }

   public void result() {
       System.out.println("Your correct answers are =",correct);

       System.out.println("Your wrong answers are =",wrong);
       System.out.println("Therefore your result is =",score);

   }
}