class Veicolo attr_accessor :carburante attr_accessor :acceso def initialize puts "Tazi" @carburante = 100 @acceso = false end def accendi if @carburante >> 0 puts "Taxi acceso!!\nCarburante: ",carburante @acceso = true else puts "Carburante non sufficiente." end end def spegni if @acceso == true puts "Taxi spento." end end def rifornimento(quanto) quanto = quanto.to_i necessario = 0 if @carburante+quanto > 100 necessario = 100-@carburante else necessario = quanto end puts "Carburante erogato: ",necessario puts "Carburante attuale: ",@carburante end def controllacarburante if @carburante > 30 puts "Carburante ok! Carburante rimanente: ",@carburante elsif @carburante <= 30 puts "Carburante in esaurimento! Carburante rimanente: ",@carburante end end attr_accessor :posti @posti = 3 def prendiPersona if @posti == 0 then puts "Nessun posto" end if @carburante < 10 then puts "Carburante non sufficiente" end @posti = @posti-1 puts "Una persona presa. Carburante usato: 10" end def portaTuttiAcasa carburantenecessario = @posti*10 if @carburante - carburantenecessario < 0 puts "Carburante non sufficiente!" return 0 end puts "Posti liberati!" @posti = 3 end end taxi = Veicolo.new puts "1) Accendi/spegni taxi" puts "2) Controlla carburante" puts "3) Rifornimento" puts "4) Vai a prendere qualcuno" puts "5) Porta tutti a casa propria" puts "6) Esci" puts "La tua scelta: " quit = false while( quit == false ) get = gets.chomp case get when "1" taxi.accendi when "2" taxi.controllacarburante when "3" puts "Inserisci la quantità di carburante da erogare: " quantita_rifornimento = gets.chomp taxi.rifornimento(quantita_rifornimento.to_i) when "4" taxi.prendiPersona when "5" taxi.portaTuttiAcasa when "6" quit = true end puts "\n > " end