วันพุธที่ 30 กันยายน พ.ศ. 2558

LAB 5 Find base 2 from base ten

def findBaseTwo(number):
   reverstBase=""
   result =""
   while(number>=1):
   
      intValue = str(int(number%2))
      if(number/2>0):
         reverstBase = reverstBase + intValue
      number = number /2
   
   count = 0
   while(count<len(reverstBase)):
      result = result + reverstBase[len(reverstBase)-count-1]
      count = count+1

   return result

print (findBaseTwo(30))
assert (findBaseTwo(30)=="11110")
print (findBaseTwo(300))
assert (findBaseTwo(300)=="100101100")


ผลลัพธ์
11110
100101100

วันอังคารที่ 29 กันยายน พ.ศ. 2558

LAB 5 my_startwith my_endwith

def setup():
   array = "overloader    Over"
   assert (my_startwith(array,"over"))
   print ("boolean of start with is",my_startwith(array,"over"))
   assert (my_endwith(array,"er"))
   print ("boolean of end with is",my_endwith(array,"er"))

def my_startwith(array,startWith):
   if(len(array)>=len(startWith)):
      i=0
      while(i<len(startWith)):
         if(array[i]==startWith[i]):
            i=i+1
         else:
            return False
      return True
 
def my_endwith(array,endWith):
   if(len(array)>=len(endWith)):
      i=len(array)-len(endWith)
      count = 0
      while(i<len(array)):
         if(array[i]==endWith[count]):
            i=i+1
            count=count+1
         else:
            return False
      return True
 
setup()  

ผลลัพธ์
boolean of start with is True
boolean of end with is True

LAB 5 Strip

def setup():
   array = "overloader    Over"
   print (my_strip(array))
   assert (my_strip(array)=="overloaderOver")



   
def my_strip(array):
   newArray = ""
   i = 0
   while(i<len(array)):
      if(array[i]!=" "):
         newArray = newArray + array[i]
      i=i+1
   return newArray


setup()  

ผลลัพธ์
overloaderOver

LAB 5 my_count my_find

def setup():
   array = "overloader"
   print ("value =",my_count(array,"e"))
   assert (my_count(array,"e")==2)
 
   print ("you fist index e is",my_find(array,"e"))
   assert (my_find(array,"e")==2)

def my_count(array,wantCount):
      i = 0
      count =0
      while(i < len(array)):
         if(array[i]==wantCount):
            count=count+1
         i=i+1
      return count
 
 
def my_find(array,wantFind):
   i = 0
   while(i<=len(array)):
      if(array[i] == wantFind):
         return i
      i=i+1
   return "."

   
 
   

setup()  


ผลลัพธ์
value = 2
you fist index e is 2

วันเสาร์ที่ 26 กันยายน พ.ศ. 2558

AS 1 VER1

วันพุธที่ 23 กันยายน พ.ศ. 2558

LAB 5 Increase

def increase():
   A=[5,10,15,8,9]
   count = 0
   percentage = 0.1
   while(count < len(A)):
      print("A[",count,"] is",A[count],"before")
      A[count] = A[count]*percentage
      print("A[",count,"] is",A[count],"after")
      count = count +1
increase()

ผลลัพธ์
A[ 0 ] is 5 before
A[ 0 ] is 0.5 after
A[ 1 ] is 10 before
A[ 1 ] is 1.0 after
A[ 2 ] is 15 before
A[ 2 ] is 1.5 after
A[ 3 ] is 8 before
A[ 3 ] is 0.8 after
A[ 4 ] is 9 before
A[ 4 ] is 0.9 after

LAB 5 Find average

def findAverage():
   A =[1,2,3,4,5,6,7,8,9,10]
   count = 0
   sumA = 0
   while(count < len(A)):
      sumA = sumA + A[count]
      count = count + 1
   average = sumA/len(A)
   print(average," is average")
findAverage()

ผลลัพธ์
5.5  is average

วันจันทร์ที่ 21 กันยายน พ.ศ. 2558

LAB 5 Count num positive number in array

def findSumPositive():
   A=[-10,-20,11,20,30,-50,10,-60]
   count = 0
   sumPositive = 0
   countPositiveNumber =0
   while(count<len(A)):
      if(A[count]>0):
         countPositiveNumber = countPositiveNumber +1
      count = count +1
   print(countPositiveNumber," is sum count positive number in array")
findSumPositive()
       
ผลลัพธ์
4  is sum count positive number in array

LAB 5 Find sum positve number in array

def findSumPositive():
   A=[-10,-20,11,20,30,-50,10,-60]
   count = 0
   sumPositive = 0
   while(count<len(A)):
      if(A[count]>0):
         sumPositive = sumPositive + A[count]
      count = count +1
   print(sumPositive," is sum Positive number is array")
findSumPositive()
       
ผลลัพธ์

71  is sum Positive number is array

LAB 5 Find first and last index in maxinumvalue


def find_maxinum_value(A):
   maxNumber = 0;
   count = 0;
  
   while(count<len(A)):
      if(A[count] > maxNumber):
         maxNumber = A[count]
      count = 1+count
   return maxNumber

def find_first_max_value(A):
   maxN = find_maxinum_value(A)
   count = 0;
   while(count<len(A)):
      if(A[count] == maxN):
         index = count
         count = len(A)
      count = 1+count
   return index
   
def setup():
   A = [-5,5,10,20,30,40,-50,-60,-80,-100,40]
   print (find_maxinum_value(A),"is the maxinum value")
   print (find_first_max_value(A)," is the first index in maxvalue")
   
setup()

   
ผลลัพธ์
40 is the maxinum value
5  is the first index in maxvalue



def find_maxinum_value(A):
   maxNumber = 0;
   count = 0;

   while(count<len(A)):
      if(A[count] > maxNumber):
         maxNumber = A[count]
      count = 1+count
   return maxNumber

def find_first_max_value(A):
   maxN = find_maxinum_value(A)
   count = 0;
   while(count<len(A)):
      if(A[count] == maxN):
         index = count
      count = 1+count
   return index
 
def setup():
   A = [-5,5,10,20,30,40,-50,-60,-80,-100,40]
   print (find_maxinum_value(A),"is the maxinum value")
   print (find_first_max_value(A)," is the first index in maxvalue")
 
setup()

ผลลัพธ์
40 is the maxinum value
10  is the last index in maxvalue
 

 

 



   

LAB 5 Find maxinum value in array


def find_maxinum_value():
   A = [-5,5,10,20,30,40,-50,-60,-80,-100]
   maxNumber = 0;
   count = 0;
 
   while(count<len(A)):
      if(A[count] > maxNumber):
         maxNumber = A[count]
      count = 1+count
   print (maxNumber)

find_maxinum_value()
       
       
   
 
 
ผลลัพธ์
40

วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558

LAB 5 find Sum of value in array and show value any array

def findSumAndValueIndex():
   A = [1,2,3,4,5,6,7,8,9,10]
   sumA = 0
   index = 0
 
   while(index<len(A)):
      sumA = sumA + A[index]
      print("A[",index,"] is",A[index])
      index = index + 1
   print ("sum values in array",sumA)
   print ("How many index is ",len(A))
 
findSumAndValueIndex()

ผลลัพธ์
A[ 0 ] is 1
A[ 1 ] is 2
A[ 2 ] is 3
A[ 3 ] is 4
A[ 4 ] is 5
A[ 5 ] is 6
A[ 6 ] is 7
A[ 7 ] is 8
A[ 8 ] is 9
A[ 9 ] is 10
sum values in array 55
How many index is  10

LAB 4 extra Sumprim number

def sumPrim(number):
   count =0
   sumPrim = 0
   print("all prim number", 0," to ", number," is ")
   while(count<number):
      if(count!=1):
         if((count==2)|(count==3)|(count==5)|(count==7)):
            sumPrim=sumPrim+count
            print (count)
         elif((count%2!=0)&(count%3!=0)&(count%5!=0)&(count%7!=0)):
                sumPrim=sumPrim+count
                print (count)
      count = count+1
   print ("sum primnumber",0," to ",number,"is")
   print (sumPrim)

sumPrim(100)
       

ผลลัพธ์

all prim number 0  to  100  is 
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
sum primnumber 0  to  100 is
1060

วันเสาร์ที่ 19 กันยายน พ.ศ. 2558

AS1 ver 0.1 NOT Complete

วันพุธที่ 16 กันยายน พ.ศ. 2558

LAB 4 extra service

def choice(package,service,oz):
   pond = oz/16
   if(package=="box"):
      if(service=="2day"):
         cost = 7+((pond-1)*0.5)
         if(cost<7):
            cost=7
      if(service=="next day standard"):
         cost = 13.75+(pond-1)
         if(cost<13.75):
            cost=13.75
      if(service=="next day priority"):
         cost = 15.75+((pond-1)*1.25)
         if(cost<15.75):
            cost=15.75
   if(package=="letter"):
      if(oz>8):
         cost = "(cant use this service)"
      else:
         if(service=="2day"):
            cost = "(sorry that not available)"
         if(service=="next day standard"):
            cost = 10.50
         if(service=="next day priority"):
            cost = 12.00
   print("you chois is",package,"and",service,oz,"Oz","your cost is",cost)
choice("box","2day",16)
choice("box","2day",32)
choice("box","next day standard",16)
choice("box","next day standard",32)
choice("box","next day priority",16)
choice("box","next day priority",32)

choice("letter","2day",16)
choice("letter","2day",32)
choice("letter","next day standard",8)
choice("letter","next day standard",7)
choice("letter","next day priority",8)
choice("letter","next day priority",9)


ผลลัพธ์

you chois is box and 2day 16 Oz your cost is 7.0
you chois is box and 2day 32 Oz your cost is 7.5
you chois is box and next day standard 16 Oz your cost is 13.75
you chois is box and next day standard 32 Oz your cost is 14.75
you chois is box and next day priority 16 Oz your cost is 15.75
you chois is box and next day priority 32 Oz your cost is 17.0
you chois is letter and 2day 16 Oz your cost is (cant use this service)
you chois is letter and 2day 32 Oz your cost is (cant use this service)
you chois is letter and next day standard 8 Oz your cost is 10.5
you chois is letter and next day standard 7 Oz your cost is 10.5
you chois is letter and next day priority 8 Oz your cost is 12.0
you chois is letter and next day priority 9 Oz your cost is (cant use this service)

วันอังคารที่ 15 กันยายน พ.ศ. 2558

LAB 4 extra Power of ten

def namePower(powN):
      if(powN==6):
         print ("10 ^",powN,"is Million")
      if(powN==9):
         print ("10 ^",powN,"is Billion")
      if(powN==12):
         print ("10 ^",powN,"is Trillion")
      if(powN==15):
         print ("10 ^",powN,"is Quadrillion")
      if(powN==18):
         print ("10 ^",powN,"is Quintillion")
      if(powN==21):
         print ("10 ^",powN,"is Sextillion")
      if(powN==30):
         print ("10 ^",powN,"is Nonillion")
      if(powN==100):
         print ("10 ^",powN,"is Googol")
       
namePower(6)
namePower(9)
namePower(12)
namePower(15)
namePower(18)
namePower(21)
namePower(30)
namePower(100)

ผลลัพธ์

10 ^ 6 is Million
10 ^ 9 is Billion
10 ^ 12 is Trillion
10 ^ 15 is Quadrillion
10 ^ 18 is Quintillion
10 ^ 21 is Sextillion
10 ^ 30 is Nonillion
10 ^ 100 is Googol

LAB 4 extra leapYear

def fineLeap(numyear):
   if(year(numyear)):
      print(numyear," is leap year")
   else:
      print(numyear, "is not leap year")

def year(year):
   if(year%4==0):
      if(year%100==0):
         if(year%400==0):
            return True
         else:
            return False
      else:
         return True
   else:
      return False
 
fineLeap(4)
fineLeap(5)
fineLeap(100)
fineLeap(105)
fineLeap(400)
fineLeap(405)
fineLeap(2100)
fineLeap(2400)


ผลลัพธ์

4  is leap year
5 is not leap year
100 is not leap year
105 is not leap year
400  is leap year
405 is not leap year
2100 is not leap year
2400  is leap year

วันจันทร์ที่ 14 กันยายน พ.ศ. 2558

LAB 4 extra multiplication

def multiplication(start,end):
   while(start<=end):
      count = 1
      while(count<=12):
         print(start," x ",count," = ",count*start)
         count=count+1
      start=start+1
      print(" ")

multiplication(2,5)

ผลลัพธ์

2  x  1  =  2
2  x  2  =  4
2  x  3  =  6
2  x  4  =  8
2  x  5  =  10
2  x  6  =  12
2  x  7  =  14
2  x  8  =  16
2  x  9  =  18
2  x  10  =  20
2  x  11  =  22
2  x  12  =  24
 
3  x  1  =  3
3  x  2  =  6
3  x  3  =  9
3  x  4  =  12
3  x  5  =  15
3  x  6  =  18
3  x  7  =  21
3  x  8  =  24
3  x  9  =  27
3  x  10  =  30
3  x  11  =  33
3  x  12  =  36
 
4  x  1  =  4
4  x  2  =  8
4  x  3  =  12
4  x  4  =  16
4  x  5  =  20
4  x  6  =  24
4  x  7  =  28
4  x  8  =  32
4  x  9  =  36
4  x  10  =  40
4  x  11  =  44
4  x  12  =  48
 
5  x  1  =  5
5  x  2  =  10
5  x  3  =  15
5  x  4  =  20
5  x  5  =  25
5  x  6  =  30
5  x  7  =  35
5  x  8  =  40
5  x  9  =  45
5  x  10  =  50
5  x  11  =  55
5  x  12  =  60

LAB 4 extra area Circle

PI=22/7

def findArea(radius):
   area=PI*((radius)**2)
   print("Area is ",area)
       
def findCircleference(radius):
   circleference=2*PI*radius
   print("circleference is ",circleference)
 
def circle(radius):
   findArea(radius)
   findCircleference(radius)
 
circle(2)
 

ผลลัพธ์

Area is  12.571428571428571
circleference is  12.571428571428571

LAB 4 extra BMI

def findBMI(weight,hight):
   BMI = weight/((hight/100)**2)
   print("BMI IS ",BMI)
 
findBMI(57,171)

ผลลัพธ์


BMI IS  19.493177387914233


LAB 4 extra Fine Sum

def fineSum(start,finish):
   Sum=0
   while(start<=finish):
      Sum=Sum+start
      start=start+1
   print (Sum)

fineSum(1,2)
fineSum(1,3)
fineSum(1,5)
fineSum(1,10)



 ผลลัพธ์
3
6
15
55

LAB 4 extra Python Grade

def showGrade(score):
   print("Your score is ",score)
   if(score>=50):
      if(score>=60):
         if(score>=70):
            if(score>=80):
               print("Your Grade is A")
            else:
               print("Your Grade is B")
         else:
            print("Your Grade is C")
      else:
         print("Your Grade is D")
   else:
      print("Your Grade is F")

   
showGrade(40)    
showGrade(50)
showGrade(60)
showGrade(70)
showGrade(80)


ผลลัพธ์

Your score is  40
Your Grade is F
Your score is  50
Your Grade is D
Your score is  60
Your Grade is C
Your score is  70
Your Grade is B
Your score is  80
Your Grade is A
           
   
       

วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558

LAB 4 Loan

void setup() {
  size(800, 550);
  background(0);
  draw_text(20, 40);
  draw_line(10, 5);
  calculat(150,80);
}

void calculat(int X,int Y){
  //set base value
  float beginBalance = 6000;
  float interestRPM =0.12/12; // IRPM is interestRatePerMonth because rate is 12 per year so per month is 12/12
  float interest =0;
  float payment =beginBalance*(interestRPM/(1-pow(1+interestRPM,-12)));
  float prinCipal = 0;
  float endingBalance =0;
  float sumInterest =0;
  int count = 1;

  while(count<=12){
    interest = interestRPM*beginBalance;
    prinCipal = payment - interest;
    endingBalance = beginBalance - prinCipal;
    sumInterest = sumInterest + interest;
 
    text(nf(+beginBalance,3,1),X,Y);
    text(nf(+interest,2,1),X+130,Y);
    text(nf(+prinCipal,3,1),X+220,Y);
    text(nf(+endingBalance,3,1),X+350,Y);
    text(nf(+sumInterest,3,1),X+530,Y);
    beginBalance = endingBalance;
    Y += 40;
    count ++ ;
  }
}
 




// function draw every text
void draw_text(int X, int Y) {
  int month=1;// set base value month
  textSize(16);
  fill(255, 0, 0);
  text("Month      BeginningBalance        Interest      Principal         EndingBalance                  InterestSum", X, Y);
  text_month(X+20,Y+40,month);
}

// function draw line
void draw_line(int X, int Y) {
  line_holizon(X, Y);
  line_vertical(X, Y);
}

// draw line vertical
void line_vertical(int X, int Y) {
  stroke(0, 0, 200);
  line(X+70, 0, X+70, 550);
  line(X+250, 0, X+250, 550);
  line(X+340, 0, X+340, 550);
  line(X+440, 0, X+440, 550);
  line(X+640, 0, X+640, 550);
}

// draw line holizon
void line_holizon(int X, int Y) {
  while (Y<550) {
    stroke(255);
    line(0, Y, 800, Y);
    Y+=40;
  }
}

// function draw number month
void text_month(int X,int Y,int month){
  fill(255);
  while(month<=12){
    text(month,X,Y);
    Y+=40;
    month++;
  }
}




LAB 4 PrimeNumber

void setup() {
  size(600, 400);
  background(0);
  int count = 0; // is start count to finish
  int finish = 100;
  text_sum(20, 20, count, finish, sum(count, finish));
}





//function for text
void text_sum(int X, int Y, int start, int finish, int sum) {
  textSize(20);
  text(" Sum Prime Number of      "+start, X, Y);
  text(" To "+finish, X+300, Y);
  text(" Sum is "+sum, X, Y+40);
  draw_prim(X,Y,start,finish);
}




//function for fine sum
int sum(int count, int finish) {
  int sum=0;
  while (count<=finish) {
    if (fineBoolean(count)) {
      sum = sum+count;
    }
    count++;
  }
  return sum;
}





// function for cheack boolean
boolean fineBoolean(int count) {
  if ((count!=2&&count%2==0)||count==1||(count!=3&&count%3==0)||(count!=5&&count%5==0)||(count!=7&&count%7==0)) {
    return false;
  }
  return true;
}




//function draw number that is prim
void draw_prim(int X,int Y,int count,int finish){
  text(" Prime number set is", X , Y+70);
  Y +=100;
  X +=20;
  while (count<=finish) {
    if (fineBoolean(count)) {
      if(X<530){
        X += 40;
        text(+count,X,Y);
      }else{
        X = 20;
        Y += 50;
        text(+count,X,Y);
      }
    }
    count++;
  }
}


วันเสาร์ที่ 12 กันยายน พ.ศ. 2558

LAB 4 favourit TORADORA

void setup() {
  size(500, 500);
  frameRate(10);
}

int limit=0; // set base value of limie of size
void draw() {
  int count=0; //count for make value to out loop
  int upSize=18; //upsize of circle
  int r=0; //r is radiuse of circle
  int colour=5; //for change colour

  background(0);
  strokeWeight(30);

  draw_rect(20, 480);
  limit++;
  //set selection for constant or resize
  if (mousePressed) {
    while (count<=limit) {
      fill(50);
      stroke(255-(colour/4), colour, random(20, 200));
      ellipse(250, 250, r, r);

      // change value
      r=r+upSize;
      count++;
      colour+=40;

      draw_toradora(130, 250);
    }
  } else {
    r=350;
    fill(50);
    stroke(255-(colour/4), colour, random(20, 200));
    ellipse(250, 250, r, r);
    draw_toradora(130, 250);
  }


  // SET Limit of size circle
  if (limit==20) {
    limit=0;
  }
}

// function draw set rect
void draw_rect(int X, int Y) {
  stroke(255);
  rect(X, Y, 20, -random(20, 300));
  rect(X+80, Y, 20, -random(20, 300));
  rect(X+160, Y, 20, -random(20, 300));
  rect(X+240, Y, 20, -random(20, 300));
  rect(X+320, Y, 20, -random(20, 300));
  rect(X+400, Y, 20, -random(20, 300));
  rect(X+470, Y, 20, -random(20, 300));
  fill(0);
}

//function draw text
void draw_toradora(int X, int Y) {
  fill(255);
  textSize(35);
  text(" TORADORA ", X, Y);
  fill(0);
}


LAB 4 Bird

void setup() {
  size(600, 380);
}

void draw() {

  // set base value
  // x_left or x_right is X of reference point of bird in X line
  // Y is reference point of bird in Y line
  // slide is value for move reference point in X line
  // trunDown is value for move reference point Y line
  // upWing is value for trun up and down wing
  // radiuse is value of radiuse of body bird
  int x_left=300;
  int x_right=300;
  int Y=50;
  int slide=50;
  int trunDown=50;
  int upWing=30;
  int radiuse=20;
 
  background(0);
  // selection for make wing up and down
    if(mousePressed){
    upWing=-upWing;
  }
 
 

  // loop for draw bird
  while (Y<350) {
    draw_bird(x_left, Y, upWing, radiuse);
    draw_bird(x_right, Y, upWing, radiuse);
    x_left=x_left-slide;
    x_right=x_right+slide;
    Y=Y+trunDown;
  }

}

void draw_bird(int X, int Y, int upWing, int radiuse) {
  stroke(255);
  strokeWeight(1);
  fill(0, 0, 255);
  wingBird(X, Y, upWing);
  ellipse(X, Y, radiuse, radiuse);//draw body
  eyeBird(X, Y);
}

// function draw wing of bird
void wingBird(int X, int Y, int upWing) {
  line(X+5, Y, X+20, Y+upWing);
  line(X-5, Y, X-20, Y+upWing);
}

//function draw eye of bird
void eyeBird(int X, int Y) {
  stroke(255, 0, 0);
  strokeWeight(5);
  point(X-5, Y);
  point(X+5, Y);
}

วันศุกร์ที่ 11 กันยายน พ.ศ. 2558

LAB 4 Multiplication Table

void setup(){
  size(400,2800);
  background(0);
  textSize(20);
  text(" Multiplication table ",100,50);
  textSize(15);
  // set base value
  // number is value for multiplication
  // stepDown is for plus Y in text multiplication
  // step stepDonwline is value for plus Y in all next number multiplication
  // X and Y is reference point of multiplication each number
  int Number =1;
  int stepDown =15;
  int stepDownLine=30;
  int X=120;
  int Y=100;
  int colour=0;
 
  while(Number<=12){
    int  count = 1;//count for multiplication
    fill(0,70+colour,255-colour);
   
    while(count<=12){ // while for draw multiplication table
      drawMultiplicationTable(X,Y,count,Number);
      Y=Y+stepDown;
      count++;
    }
   
    Y=Y+stepDownLine;
    Number++;
    colour+=15;
  }
 
}


void drawMultiplicationTable(int X,int Y ,int count,int number){
  int sum=0;  // sum is sum of number  *  count
  sum = count * number;
  text(+number,X,Y);
  text(" x " ,X+20,Y);
  text(+count,X+60,Y);
  text(" = ",X+100,Y);
  text(+sum,X+140,Y);
}


LAB 4 Fine sum of 1 to N

void setup(){
  size(600,300);
  background(0);
  //set base value of variable
  //N is real number
  //sum is sum of count to N
  //count is value for check rule
  int count=0;
  int sum=0;
  int N=100;
  textSize(30);
  text("Sum of  "+count,200,100);
  text(" to " +N,350,100);
 
  while(count<=N){
    sum=sum+count;
    count++;
  }

  text("Sum is  "+sum,200,200);
}
 

วันพุธที่ 9 กันยายน พ.ศ. 2558

LAB 4 BALLOON LOOP

void setup(){
  size(700,600);
  background(0);
  stroke(255);
  int X=20;
  int R=20; // r is radiuse
  int Y=500;
  int num=0; // count number of balloon
 
  while(X<600){
    balloon(X,R,Y,num);
    num++;
    X += 80;
    Y -= 40;
    R += 10;
  }
}

// make function for make balloon
void balloon(int X,int R,int Y,int num){
  ellipse(X,Y,R,R);
  line(X,Y,X,Y+2*R);
 
  fill(0);
  text(+num,X-5,Y); // make number off balloon
 
  fill(255);
  }
 
 

วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558

LAB 3 Service

void setup() {
  size(800, 500);
}


void draw() {
  background(0);
  frameRate(5);
  drawText(50, 50);
}

// make function draw text
void drawText(int X, int Y) {
  textSize(20);
  fill(255);
  text("                                       Welcome", X, Y);
  text("For Choice a type of package please pressed B for Box or L for Letter ", X, Y+50);
  text("For Choice a type of service please pressed P for next day priority", X, Y+100);
  text("S for next day standard , 2 for 2-day", X, Y+150);
  text("For Choice a Weight of package please pressed  + or - (Oz)", X, Y+200);
  typePackage(choicePackage(), X, Y);
  typeService(choiceService(), X, Y);
  weight(oz(), X, Y);
  expenses(weightOz, X, Y, expenbox(valueOz(weightOz)));
}

// make function for draw text of type package your choice
void typePackage(int choicePackage, int X, int Y) {
  fill(255, 0, 0);
  switch(choicePackage) {
  case 1:
    text(" You TypePackage is Box", X, Y+250);
    break;
  case 2:
    text(" You TypePackage is Letter", X, Y+250);
    break;
  case 0:
    text(" Please press a choice of package type ", X, Y+250);
    break;
  }
}
//set base value
int choiceP =0;
int choiceS =0;
int weightOz =16;

//make function for choice weight oz
void weight(float oz, int X, int Y) {
  fill(0, 150, 200);
  text(" You weight choice is (oz) "+oz, X, Y+350);
}

//make function for up and down value of weight
float oz() {
  if (keyPressed) {
    if (key=='+') {
      weightOz++;
    }
    if (key=='-') {
      if (weightOz>0) {
        weightOz--;
      }
    }
  }
  return weightOz;
}

// make function for setup value typepackage
int choicePackage() {
  if (key=='B'||key =='b') {
    choiceP=1;
  }
  if (key=='L'||key=='l') {
    choiceP=2;
  }

  return choiceP;
}

// make function for draw text of type service your choice
void typeService(int choiceService, int X, int Y) {
  fill(0, 200, 0);
  switch(choiceService) {
  case 1:
    text(" You TypePackage is Next Day Priority", X, Y+300);
    break;
  case 2:
    text(" You TypePackage is Next Day Standard", X, Y+300);
    break;
  case 3:
    text(" You TypePackage is 2-Day ", X, Y+300);
    break;
  case 0:
    text(" Please press a choice of service type ", X, Y+300);
    break;
  }
}

// make function for setup value typepackage
int choiceService() {
  if (key=='P'||key =='p') {
    choiceS=1;
  }
  if (key=='S'||key=='s') {
    choiceS=2;
  }
  if (key=='2') {
    choiceS=3;
  }

  return choiceS;
}

//transform oz to pound
float valueOz(float oz) {
  float pound;
  pound=oz/16;
  return pound;
}


//set print text of expenses
void expenses(float oz, int X, int Y, float expenBox) {
  fill(150, 150, 0);
  //set for letter
  if ((choiceP==2&&choiceS==1)&&oz<=8.00) {
    text("You expenses is $ 12.00", X, Y+400);
  }
  if ((choiceP==2&&choiceS==2)&&oz<=8.00) {
    text("You expenses is $ 10.50", X, Y+400);
  }
  if ((choiceP==2&&choiceS==3)&&oz<=8.00) {
    text("That not available", X, Y+400);
  }
  if (choiceP==2&&oz>8.00) {
    text("Cant use this service", X, Y+400);
  }
  // set for box

  if (choiceP==1&&oz>=16) {
    text("You expenses is $ "+expenBox, X, Y+400);
  } else {
    if (choiceP==1&&choiceS==1) {
      text("You expenses is $ 15.75", X, Y+400);
    } else {
      if (choiceP==1&&choiceS==2) {
        text("You expenses is $ 13.75", X, Y+400);
      } else {
        if (choiceP==1&&choiceS==3) {
          text("You expenses is $ 7", X, Y+400);
        }
      }
    }
  }
}



//set value of expensesbox
float expenbox(float weightPound) {
  float expenbox=0;
  if (choiceS==1) {
    expenbox = 15.75 + ((weightPound-1)*1.25);
  }
  if (choiceS==2) {
    expenbox = 13.75 + ((weightPound-1));
  }
  if (choiceS==3) {
    expenbox = 7 + ((weightPound-1)*0.5);
  }
  return expenbox;
}

LAB Error ,Bug 2


Error - unexpected token : void
problem missing right curly bracket "}"

เกิดจาก มีการใช้สัญลักษณ์ ของ } ผิด หรือ ว่า ลืมใช้ในตำแหน่งที่ถูกต้อง

แก้ได้โดยเติมหรือแก้ไห้ถูกต้อง เช่นในกรณีนี้ ต้องเติม } ข้าง บน ฟังก์ชั่น void เพื่อปิด ฟังก์ชั่นด้านบน


LAB 3 Leap Year

void setup(){
  size(800,300);
}

int yearIs = year(); // set base year

void draw(){
  background(0);
  frameRate(10);
  setYear();
  draw_text(80,100);

}

//make function draw text
void draw_text(int X,int Y){
  textSize(20);
  text("choose year by press + or - in your key bord for up and down a year",X,Y);
  text("Your Choice "+yearIs,X+200,Y+50);
  showLeap(leapYear(yearIs),X,Y);
}

//set key for turn up and down year
void setYear(){
  if(keyPressed){
    if(key == '+'){
      yearIs ++;
    }
    if(key =='-'){
      yearIs --;
    }
  }
}

// make function for show is or is'n leap year
void showLeap(boolean booLean,int X,int Y){
  if (booLean == true){
    fill(255,0,0);
    text(" That year is Leap Year ",X+170,Y+100);
    fill(255);
  }else{
    text(" That year isn't Leap Year ",X+170,Y+100);
  }
}

// make function for fine value of boolean
boolean leapYear(int yearIs){
  boolean value=false;
  if(yearIs%4 == 0){
    if(yearIs%100 ==0){
      if(yearIs%400 ==0){
        value = true;}
      }else{
        value = true;}
    }else{
      value = false;
    }
    return value;
}




LAB 3 power of ten

void setup() {
  size(200,450);
}

void draw() {
  background(0);
  draw_text(value(),10,400);
  drawTextRule(40,40);
}

//set rule and show a answer
void draw_text(int value,int X,int Y) {
  switch(value) {
  case 1:
    text("You mean 10^6  that is Million", X, Y);
    break;
  case 2:
    text("You mean 10^9  that is Billion", X, Y);
    break;
  case 3:
    text("You mean 10^12  that is Trillion", X, Y);
    break;
  case 4:
    text("You mean 10^15  that is Quadrillion", X, Y);
    break;
  case 5:
    text("You mean 10^18  that is Quintillion", X, Y);
    break;
  case 6:
    text("You mean 10^21  that is Sextillion", X, Y);
    break;
  case 7:
    text("You mean 10^30  that is Nonillion", X, Y);
    break;
  case 8:
    text("You mean 10^100  that is Googol", X, Y);
    break;
  case 0:
    text("     Please press a key", X, Y);
    break;
  }
}

//make function for set value of key
int value(){
  int value=0;
  if(key=='1'){
    value=1;
  }
  if(key=='2'){
    value=2;
  }
  if(key=='3'){
    value=3;
  }
  if(key=='4'){
    value=4;
  }
  if(key=='5'){
    value=5;
  }
  if(key=='6'){
    value=6;
  }
  if(key=='7'){
    value=7;
  }
  if(key=='8'){
    value=8;
  }
  return value;
}

//draw help text
void drawTextRule(int X,int Y){
  text(" Press a key for show ",X,Y-30);
  text("a word for that number",X,Y);
  text("Key          Power of ten",X,Y+30);
  text(" 1                  6",X,Y+60);
  text(" 2                  9",X,Y+90);
  text(" 3                 12",X,Y+120);
  text(" 4                 15",X,Y+150);
  text(" 5                 18",X,Y+180);
  text(" 6                 21",X,Y+210);
  text(" 7                 30",X,Y+240);
  text(" 8                100",X,Y+270);
 
}