Skip to content

プログラムの修正課題の提出#1

Open
yokomaru wants to merge 6 commits intomainfrom
debug
Open

プログラムの修正課題の提出#1
yokomaru wants to merge 6 commits intomainfrom
debug

Conversation

@yokomaru
Copy link
Owner

@yokomaru yokomaru commented Jan 31, 2024

概要

プラクティス カレンダーのプログラム(Ruby) | FBCを実装。

対応

必要修正要件

  • 頼んだつもりのメニューが選択できない。
  • 最後の番号のメニューを選択するとエラーとなる。
  • お会計額が異様に高い。
  • 違う番号のドリンク、フードを注文したとき、お会計が正しくない。
    例: (1)コーヒー と (2)アップルパイを頼むと、お会計が意図した金額にならない。
  • 修正の際、表示されるメニューの入力番号は変更しないようにしてください。( (1) から始まる仕様を維持してください。)

追加対応

  • 選択肢の範囲以外の入力がされた場合、再入力を促す

実装詳細

  • 頼んだつもりのメニューが選択できない。

  • 最後の番号のメニューを選択するとエラーとなる。

    • 表示時にeach_index(1) で開始しているため実際のindexより+1になっているため、入力値から-1する
    • 0が入力された時に-1になってしまい、最後の配列の値を選択できてしまうため選択肢の範囲以外の入力がされた場合、再入力を促す処理を念の為追加
  • お会計額が異様に高い。

    • 数値が文字列になっていて文字列結合になっている
      • 数値をto_iしてintegerにする or ハッシュの数字自体を文字列から数値に変更
        • 今回は 数値を変換して表示する
  • 違う番号のドリンク、フードを注文したとき、お会計が正しくない。

    • FOODと1番目に入力したDRINKSにorder1、2番目に入力したFOODにorder2で指定する
    # 現在のコード
    total = FOODS[order1][:price] + DRINKS[order2][:price]

Screenshot

実行結果

  • 同じ番号のドリンク、フードを注文
    • 460 + 410 = 870
スクリーンショット 2024-01-31 21 53 51
  • 違う番号のドリンク、フードを注文
    • 460 + 520 = 980
スクリーンショット 2024-01-31 21 53 13
  • 最初の番号のドリンク、フードを注文
    • 300 + 470 = 770
スクリーンショット 2024-01-31 21 54 09
  • 最後の番号のドリンク、フードを注文
    • 450 + 410 = 860
スクリーンショット 2024-01-31 21 54 28
  • 範囲外の番号を入力した時の表示(ドリンク)
スクリーンショット 2024-01-31 21 54 54
  • 範囲外の番号を入力した時の表示(フード)
スクリーンショット 2024-01-31 21 55 19

Copy link

@JunichiIto JunichiIto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしました!

cafe.rb Outdated
order_number = gets.to_i
order_number = gets.to_i - 1
until order_number.between?(0, menus.size - 1)
print "番号は選択肢の中から入力してください\n>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要件としては表示されている番号をすべて選択可能にする、だけで十分です。
番号の再入力は要件にないのでカットしちゃってください〜。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントありがとうございます。失礼いたしました!
まずはちゃんと用件通り、シンプルに実装することを心がけます!

cafe.rb Outdated
order2 = take_order(FOODS)

total = FOODS[order1][:price] + DRINKS[order2][:price]
total = FOODS[order2][:price].to_i + DRINKS[order1][:price].to_i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもの問題として、価格が文字列になっていて何か嬉しいことがあるのか?から考えてみてください。
あと、変数が連番だとうっかりミスをおこしやすいので、良い変数も検討してみてください。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。

そもそもの問題として、価格が文字列になっていて何か嬉しいことがあるのか?から考えてみてください。

実装した時はここの計算処理以外でpriceは文字列で表示していたので、計算処理の箇所だけto_iするほうが妥当だろうと考えたのですが、そもそも以下のように文字列に埋め込んで表示していたのでpriceを数値にしても何も問題がないことに気づきました。。修正いたします。

#{menus[order_number][:price]}

また、変数名についてもありがとうございます。処理が動いたことで修正完了としてしまっていました!
シンプルにfood_orderdrink_orderが分かりやすいかと思いましたので、合わせて修正いたします。

@yokomaru
Copy link
Owner Author

yokomaru commented Feb 8, 2024

@JunichiIto
レビューありがとうございました!
修正いたしましたので、お手隙でご確認お願いいたします。

  • 要件外の処理をカット
  • ハッシュの価格が文字列になっているのを数値に修正
  • オーダー変数の命名修正

Copy link

@JunichiIto JunichiIto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビュー遅れてすいません!これでOKです〜 🙆‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants