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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Hi there! Welcome to AWS Cloud9!
To get started, create some files, play with the terminal,
or visit https://docs.aws.amazon.com/console/cloud9/ for our documentation.

Happy coding!
Hello world!
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
10 changes: 7 additions & 3 deletions kadai2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
{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]}大会"
puts "豆知識: #{olympic[:note]}" if olympic[:note]
end

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

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




return "#{self.name} #{total_price}vnd"
def get_total_price count
total_price = count * self.price
if count >= 3
total_price = total_price - 10000
end
puts "#{self.name} #{total_price}vnd"
#return "#{self.name} #{total_price}vnd"
end
end

menu1 = Menu.new
menu1.name = "Phở"
menu1.price = 30000

menu1.get_total_price 3
#puts menu1.get_total_price 3
# menu1に対してget_total_priceメソッドを呼び出してください
10 changes: 7 additions & 3 deletions kadai4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ 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.each do |menu|
puts menu.info
end
# menusに対して繰り返し処理を実行してください
24 changes: 19 additions & 5 deletions kadai5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ 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}サイズ)"
end
Expand All @@ -29,10 +33,20 @@ def info

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


drink1 = Drink.new(name: "Trà", price: 5000, size: "Sサイズ")
drink2 = Drink.new(name: "Trà Sữa", price: 35000, size: "Mサイズ")
# 変数menusを定義して配列を代入してください

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

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

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

menus.each do |menu|
puts "#{menu.info}"
end
order = gets.to_i
selected_order = Menu.new name: menus[order].name, price: menus[order].price
puts "選択されたメニュー: #{selected_order.name}"
puts "お会計は#{selected_order.price}vndです。"
1 change: 1 addition & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts 1+1;