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
14 changes: 7 additions & 7 deletions kadai1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
year = gets.to_i #gets(標準入力)

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

elsif
puts "#年は夏季オリンピックが開催されました"
if year < 1896
puts "#{year}年にオリンピックはまだありません"
elsif year == 1916 || year == 1940 || year ==1944
puts "#{year}年は夏季オリンピックが開催されませんでした"
elsif year % 4 == 0
puts "#{year}年は夏季オリンピックが開催されました"
else
puts "#年は夏季オリンピックイヤーではありません"
puts "#{year}年は夏季オリンピックイヤーではありません"
end
9 changes: 8 additions & 1 deletion 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


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

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




def get_total_price(count)
total_price = self.price*count
if count > 2
total_price -= 10000
end

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

# menu1に対してget_total_priceメソッドを呼び出してください
# menu1に対してget_total_priceメソッドを呼び出してください

puts menu1.get_total_price(3)
puts menu1.get_total_price(2)
puts menu1.get_total_price(4)
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:"Phở", price:30000)
menu2 = Menu.new(name:"Bún chả", price:40000)
menu3 = Menu.new(name:"Bánh mì", price:20000)

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

menus = [menu1, menu2, menu3]

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

menus.each do |menu|
puts menu.info
end
10 changes: 8 additions & 2 deletions kadai5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Drink < Menu

# 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 @@ -28,11 +32,13 @@ def info
menu3 = Menu.new(name: "bánh mì", price: 20000)

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

drink1 = Drink.new(name: "trà", price: 5000, size: "S")
drink2 = Drink.new(name: "trà", price: 10000, size: "M")

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

menus = [menu1, menu2, menu3, drink1, drink2] # 多形配列

menus.each do |menu|
puts "#{menu.info}"
end
end
64 changes: 64 additions & 0 deletions kadai6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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メソッドをオーバーライドする
# 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}サイズ)"
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: "trà", price: 5000, size: "S")
drink2 = Drink.new(name: "trà", price: 10000, size: "M")

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

menus = [menu1, menu2, menu3, drink1, drink2] # 多形配列



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

puts "---------------------"
puts "メニューの番号を選択してください"

while true
order = gets.to_i

if order < 0 || order >= menus.length()
puts "存在しません"
puts "---------------------"
puts "メニューの番号を選択してください"
else
selected_menu = menus[order]
puts "選択されたメニュー: #{selected_menu.name}"
puts "お会計は#{selected_menu.price}vndです。"
break
end
end
1 change: 1 addition & 0 deletions new_file_mc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
私はミンコンです。
3 changes: 3 additions & 0 deletions practice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
puts "hello world!"
print "hello world!"
print "hello"
2 changes: 0 additions & 2 deletions practice.txt

This file was deleted.