class Shopping

Public Class Methods

new() click to toggle source
# File lib/shopping2.rb, line 13
def initialize
@p = Products.new
@c = Cart.new

end

Public Instance Methods

displayOptions() click to toggle source
# File lib/shopping2.rb, line 20
        def displayOptions

        puts "Select from below"

        puts "1   Display All Products"
        puts "2   Select Products"
        puts "3   Display Cart"
        puts "4   Checkout"
    puts "\n"
    puts "\n"
    puts "\n"


        choice = gets.chomp
        #puts choice
        

        case choice
             when '1'
                       @p.displayProducts
                       displayOptions

         when '2'
                puts "Enter product id to buy"
                prod_id = gets.chomp
                puts "Enter quantity of product"
                qty = gets.chomp
                
                @c.addToCart(prod_id,qty)
                
                puts("Do you want to continue shopping? y/n")
                    ans = gets.chomp
                    if (ans=='y')
                             displayOptions
                        else
                     @c.displayCart
                     displayOptions 
                        end


         when '3'
               @c.displayCart
               displayOptions

         when '4'
                 @c.buy  
                 displayOptions

    end

end