13 Apr 2009

Elevator Pitch 1

Web Applications needs too much time to be developed in changing environment.

Thus, how can I develop web application rapidly with OO technique?

From ITC594 course the lecturer lets us know the answer is using Ruby on Rails. Before this course, I know nothing about ROR. After exercises and workshops, we learn ROR step by step, for example, from e-business modeling concept to Ruby coding.

Honestly, we hit many technical issues for installing & configuring ROR, for instance, Ruby cannot connect to MySQL successfully. Some syntaxes are changed with newer version of ROR. Also, although there are many supporting forum & wiki, the supporting does not have golden rule. We need to try by myself and feel painful.

However, after working harder with ROR, I feel Ruby is GOOD now. I can build a web application within a minute by using scaffolding. Scaffolding is one feature of ROR. ROR is extremely fast than other programing language in term of development duration. Beside scaffolding, ROR offers default value making things simpler & smaller. Also ROR supports MVC. M-Model is active record handling backend database request. V-View is action view forming presentation to users. C-controller is action Controller defining functions, receiving requests,
communicating with model and view.

It is time to study hard for the next assignment.

This is Joseph Cheung's Progress Report through Elevator Pitch

(225 words)

The audio version of elevator pitch is uploaded to CSU interaction.

Q3. Compare the Ruby and Python versions of the dog years calculator:

Ruby

#!/usr/bin/ruby

# The Dog year calculator program called dogyears.rb

def dogyears
# get the original age
puts “Enter your age (in human years): "
age = gets # gets is a method for input from keyboard
puts # is a method or operator for screen output

#do some range checking, then print result
if age <0
puts "Negative age?!? I don't think so."
elsif age > 110
puts "Frankly, I don't believe you."
else
puts "That's", age*7, "in dog years."
end
dogyears

Python

#!/usr/bin/python
# The Dog year calculator program called dogyears.py

def dogyears():
# get the original age
age = input("Enter your age (in human years): ")
print # print a blank line

# do some range checking, then print result
if age <0
print "Negative age?!? I don't think so."
elif age > 110:
print "Frankly, I don't believe you."
else:
print "That's", age*7, "in dog years."

### pause for Return key (so window doesn't disappear)
raw_input('press Return>')

def main():
dogyears()
main()

Answer:

The codes of Ruby and Python are very similar. They first accepts the input from keyboard. The input represents year-old. Then, they verify the input to see whether the input is in reasonable range. If so, they will calculate and print the result.

The difference of the codes is ....
1. Ruby uses "puts" to output on screen when Python uses "print" to output.
2. Ruby uses the reserved words "elsif" buy Python uses "elif"
3. Ruby needs "end" to complete the if-then-else, whereas, Python does not need.
4. Ruby uses "def dogyears" to define the dog years class while Python uses "def dogyears()"
5. Ruby does not need main() class when Python needs main() class




Q2. Write a Ruby program called fizzbuzz.rb ...

Q2. Write a Ruby program called fizzbuzz.rb that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Answer:

The fizzbuzz.rb has been developed and the program code & program output are as follow...

Diagram-51 - the fizzbuzz.rb is run

The code and complete program output are stated below....

The source code:
#!C:\InstantRails-2.0-win\ruby\bin\ruby
# 1. Print Number 1 to 100
# 2. When multiples of 3, pint Fizz instead of number
# 3. When multiples of 5, pint Buzz instead of number
# 4. When multiples of 3 & 5, pint FizzBuzz instead of number

def fizzbuzz
i=1
loop do
break if i>100
if (i%3)==0 && (i%5)==0
puts "FizzBuzz"
elsif (i%3)==0
puts "Fizz"
elsif (i%5)==0
puts "Buzz"
else
puts i
end
i=i+1
end
end
fizzbuzz

The output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

Q1. Create, test and debug a Ruby program called dognames.rb or catnames.rb...

Q1. Create, test and debug a Ruby program called dognames.rb or catnames.rb to accept 3 names from the keyboard and to display each name on the screen in alphabetical order WITHOUT using a data structure such as a list. Answer:

I have written the dognames.rb ruby program. The diagram-50 shows the screen dump (result) of running dognames.rb in Ruby console.

Diagram-50 - The result of running dognames.rb

The code of dognames.rb is listed below...

#!C:\InstantRails-2.0-win\ruby\bin\ruby
# The Dog Name Program to sort the dogname without using sort method
# assume all inputs of the dog names are not the same

def dognames
# get the three dogs' names
puts "Enter the first dog's name: "
$dog1 = STDIN.gets
puts "Enter the second dog's name: "
$dog2 = STDIN.gets
puts "Enter the third dog's name: "
$dog3 = STDIN.gets

first=""
second=""
third=""

if ($dog1 <=> $dog2)==-1 && ($dog1 <=> $dog3)==-1
first=$dog1
if ($dog2 <=> $dog3)==-1
second=$dog2
third=$dog3
else
second=$dog3
third=$dog2
end
elsif ($dog1 <=> $dog2)==-1 && ($dog1 <=> $dog3)==1
first=$dog3
second=$dog1
third=$dog2
elsif ($dog1 <=> $dog2)==1 && ($dog1 <=> $dog3)==-1
third=$dog3
second=$dog1
first=$dog2
elsif ($dog1 <=> $dog2)==1 && ($dog1 <=> $dog3)==1
third=$dog1
if ($dog2 <=> $dog3)==1
second=$dog2
first=$dog3
else
second=$dog3
first=$dog2
end
end

puts "The order of dogs' names is "
puts
puts first+" "+second+" "+third
end
dognames