-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal.rb
54 lines (48 loc) · 1 KB
/
cal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
TAX = {"北海道" => 0.0685, "東日本" => 0.08, "西日本" => 0.0625, "四国" => 0.04, "九州" => 0.0825}
DISCOUNT = {1000 => 0.03, 5000 => 0.05, 7000 => 0.07, 10000 => 0.10, 50000 => 0.15}
def discount_rate sum
if (sum < 1000)
return 0
elsif ( sum < 5000 )
return 0.03
elsif ( sum < 7000 )
return 0.05
elsif ( sum < 10000 )
return 0.07
elsif ( sum < 50000 )
return 0.1
else
return 0.15
end
end
price_str = ARGV[0]
num_str = ARGV[1]
area = ARGV[2]
price = price_str.to_i
num = num_str.to_i
sum = price * num
tax = TAX[area]
discount = discount_rate(sum)
amount = sum * ( 1 + tax)
puts "price:#{price}"
puts "num:#{num}"
puts "area:#{area}"
puts "sum:#{sum}"
puts "tax:#{tax}"
puts "amount:#{amount}"
puts "discount#{discount}"
def discount_rate sum
if (sum < 1000)
return 0
elsif ( sum < 5000 )
return 0.03
elsif ( sum < 7000 )
return 0.05
elsif ( sum < 10000 )
return 0.07
elsif ( sum < 50000 )
return 0.1
else
return 0.15
end
end