Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HungDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do Manh Hung
17 changes: 9 additions & 8 deletions kadai1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
year = gets.to_i #gets(標準入力)

# 以下の条件分岐に、新しい条件を追加してください
if
puts "#年にオリンピックはまだありません"
elsif

elsif
puts "#年は夏季オリンピックが開催されました"
else
puts "#年は夏季オリンピックイヤーではありません"

if year < 1896
puts "#{year} 年は夏季オリンピックイヤーではありません"
elsif [1916, 1940, 1944].include?(year)
puts "#{year} 年はオリンピックが開催されませんした"
elsif year % 4 != 0
puts "#{year} 年にオリンピックはまだありません"
elsif year % 4 == 0
puts "#{year} 年は夏季オリンピックが開催されました"
end
11 changes: 9 additions & 2 deletions kadai2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
{year: 1920, city: "アントワープ"},
{year: 1924, city: "パリ", note: "同じ都市での2回目の開催は初"},
{year: 1928, city: "アムステルダム"},
{year: 1932, city: "ロサンゼルス"}
{year: 1932, city: "ロサンゼルス"},
{year: 2020, city: "東京", note: "コロナウイルスで2021年に延期"},

]

puts "第1~10回大会のオリンピック一覧"

# each文を用いて、オリンピックの情報を出力してください


olympics.each do |olympic|
puts "-------------------------"
puts "#{olympic[:year]}年 #{olympic[:city]} 大会"
next unless olympic[:note]
puts "豆知識: #{olympic[:note]}"
end

# 豆知識がある場合のみ豆知識について出力してください
10 changes: 8 additions & 2 deletions kadai3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ class Menu

# get_total_priceメソッドを定義してください



def get_total_price count
total_price = count * price

if count >= 3
total_price -= 10000
end

return "#{self.name} #{total_price}vnd"
end
Expand All @@ -15,4 +19,6 @@ class Menu
menu1.name = "Phở"
menu1.price = 30000

puts menu1.get_total_price 4

# menu1に対してget_total_priceメソッドを呼び出してください
13 changes: 9 additions & 4 deletions kadai4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ def info
end

#メニューの変数を定義してください
menu1 =
menu2 =
menu3 =
menu1 = Menu.new name: "Pho", price: 30000
menu2 = Menu.new name: "BunCha", price: 40000
menu3 = Menu.new name: "BanhMi", price: 20000

# 変数menusを定義して配列を代入してください

menus = [menu1, menu2, menu3]

# menusに対して繰り返し処理を実行してください
# menusに対して繰り返し処理を実行してください

menus.each do |menu|
puts menu.info
end
10 changes: 9 additions & 1 deletion kadai5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class Drink < Menu
attr_accessor :size

# initializeメソッドをオーバーライドする
# nameとpriceはsuperとする
def initialize(name:, price:, size:)
super(name: name, price: price)
self.size = size
end


def info
return "#{self.name} #{self.price}vnd (#{self.size}サイズ)"
Expand All @@ -29,6 +33,10 @@ def info

# Drinkの変数を定義してください

drink1 = Drink.new name: "tra", price: 5000, size: "S"
drink2 = Drink.new name: "tra", price: 10000, size: "M"

menus = [menu1, menu2, menu3, drink1, drink2]

# 変数menusを定義して配列を代入してください

Expand Down
56 changes: 56 additions & 0 deletions kadai6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Menu
attr_accessor :name
attr_accessor :price

def initialize(name:, price:)
self.name = name
self.price = price
end

def info
return "#{self.name} #{self.price}vnd"
end
end

class Drink < Menu
attr_accessor :size

# initializeメソッドをオーバーライドする
def initialize(name:, price:, size:)
super(name: name, price: price)
self.size = size
end


def info
return "#{self.name} #{self.price}vnd (#{self.size}サイズ)"
end
end

menu1 = Menu.new(name: "Phở", price: 30000)
menu2 = Menu.new(name: "Bún chả", price: 40000)
menu3 = Menu.new(name: "bánh mì", price: 20000)

# Drinkの変数を定義してください

drink1 = Drink.new name: "tra", price: 5000, size: "S"
drink2 = Drink.new name: "tra", price: 10000, size: "M"

menus = [menu1, menu2, menu3, drink1, drink2]

# 変数menusを定義して配列を代入してください


menus.each_with_index do |menu, index|
puts "#{index}. #{menu.info}"
end

puts "------------------"
puts "メニュー番号を選択してください"
order = gets.to_i

selected_menu = menus[order]

return unless selected_menu
puts "選択されたメニュ-: #{selected_menu.name}"
puts "お会計は #{selected_menu.price} VND です"