Class: Examen

Inherits:
Object
  • Object
show all
Defined in:
lib/exam1/examen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lista_preguntas) ⇒ Examen

Returns a new instance of Examen.



8
9
10
11
12
13
# File 'lib/exam1/examen.rb', line 8

def initialize (lista_preguntas)
	@exam = lista_preguntas	
	@respuesta_usuario=[nil,nil,nil,nil,nil]
	@rcorrecta = ['b','a','c','a','a']
	@correctaP=0
end

Instance Attribute Details

#correctaPObject

Returns the value of attribute correctaP.



6
7
8
# File 'lib/exam1/examen.rb', line 6

def correctaP
  @correctaP
end

#examObject

Returns the value of attribute exam.



6
7
8
# File 'lib/exam1/examen.rb', line 6

def exam
  @exam
end

#rcorrectaObject

Returns the value of attribute rcorrecta.



6
7
8
# File 'lib/exam1/examen.rb', line 6

def rcorrecta
  @rcorrecta
end

#respuesta_usuarioObject

Returns the value of attribute respuesta_usuario.



6
7
8
# File 'lib/exam1/examen.rb', line 6

def respuesta_usuario
  @respuesta_usuario
end

Instance Method Details

#calificacionObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/exam1/examen.rb', line 54

def calificacion

	if @correctaP >= 3 then
		puts "Calificación: Aprobado"
		true
	else
		puts "Calificación: Suspendido"
		false
	end

end

#correcta(ans_usuario, numero_preg) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/exam1/examen.rb', line 38

def correcta(ans_usuario,numero_preg)

	if ans_usuario == @rcorrecta[numero_preg] then
	
		puts "Pregunta #{numero_preg+1}: Respuesta correcta"
		@correctaP+=1
		true
	
	else
		puts "Pregunta #{numero_preg+1}: Respuesta incorrecta"
		false
	
	end
	
end

#invertObject



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/exam1/examen.rb', line 84

def invert

	
	@s = List.new(@exam.tail)
	
	puts @s.print
	
	#@exam.each { |x| @s.insert_tail(x) }
	
	
	return true
		
end

#respuesta_userObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/exam1/examen.rb', line 15

def respuesta_user 

puts "Introduce las opciones de respuesta: "

=begin
 puts "1): " + r1=gets.chomp
 puts "2): " + r2=gets.chomp
 puts "3): " + r3=gets.chomp
 puts "4): " + r4=gets.chomp
 puts "5): " + r5=gets.chomp
=end

#	@respuesta_usuario = [r1,r2,r3,r4,r5]
@respuesta_usuario = [gets.chomp,gets.chomp,gets.chomp,gets.chomp,gets.chomp]

end

#to_sObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/exam1/examen.rb', line 66

def to_s
	actual = @exam.tail
	
	i=1
	while actual != nil && i < 6
	
	

		puts "#{i} #{actual.value}\n"
		actual = actual.siguiente
		
	i+=1
	
	end
	
end

#vresp_userObject



34
35
36
# File 'lib/exam1/examen.rb', line 34

def vresp_user
	return @respuesta_usuario
end