-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestion.java
70 lines (68 loc) · 1.37 KB
/
Question.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
public class Question {
private String Ques;
private int marks;
private String[] Options;
private int correct_ans;
Question()
{
Ques="";
marks=0;
Options = new String[4];
correct_ans=0;
}
public void set(String Ques,int marks,String[] Options,int correct_ans)
{
this.Ques=Ques;
this.marks=marks;
this.Options=Options;
this.correct_ans=correct_ans;
}
public void input()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the question");
Ques = s.nextLine();
System.out.println("Enter marks for the question");
marks=s.nextInt();
System.out.println("Enter the options");
for(int i=0;i<4;++i)
{
System.out.print("Enter Option ");
System.out.print(i+1);
System.out.print(": ");
Options[i]=s.next();
}
while(true)
{
System.out.println("\nEnter the correct Option Number");
correct_ans=s.nextInt();
if(correct_ans>4 || correct_ans<1)
{
System.out.println("Choose between 1 to 4");
}
else
break;
}
}
public void display(int no)
{
System.out.println("\n\nQuestion "+no+" is: ");
System.out.println(Ques);
System.out.println("The options are: ");
for(int i=0;i<4;++i)
{
System.out.print("Option ");
System.out.print(i+1);
System.out.println(": "+Options[i]);
}
}
public int correct()
{
return correct_ans;
}
public int marks()
{
return marks;
}
}