Question

In: Computer Science

Implement an exam application in which a user can give exam. Question will be of three...

Implement an exam application in which a user can give exam. Question will be of three types. MCQ, true false and fill in the blank. Develop a GUI in java using swings.

Solutions

Expert Solution

Answer:

Code :

  1. import java.awt.*;  
  2. import java.awt.event.*;  
  3. import javax.swing.*;  
  4.   
  5. class OnlineTest extends JFrame implements ActionListener  
  6. {  
  7.     JLabel l;  
  8.     JRadioButton jb[]=new JRadioButton[5];  
  9.     JButton b1,b2;  
  10.     ButtonGroup bg;  
  11.     int count=0,current=0,x=1,y=1,now=0;  
  12.     int m[]=new int[10];      
  13.     OnlineTest(String s)  
  14.     {  
  15.         super(s);  
  16.         l=new JLabel();  
  17.         add(l);  
  18.         bg=new ButtonGroup();  
  19.         for(int i=0;i<5;i++)  
  20.         {  
  21.             jb[i]=new JRadioButton();     
  22.             add(jb[i]);  
  23.             bg.add(jb[i]);  
  24.         }  
  25.         b1=new JButton("Next");  
  26.         b2=new JButton("Bookmark");  
  27.         b1.addActionListener(this);  
  28.         b2.addActionListener(this);  
  29.         add(b1);add(b2);  
  30.         set();  
  31.         l.setBounds(30,40,450,20);  
  32.         jb[0].setBounds(50,80,100,20);  
  33.         jb[1].setBounds(50,110,100,20);  
  34.         jb[2].setBounds(50,140,100,20);  
  35.         jb[3].setBounds(50,170,100,20);  
  36.         b1.setBounds(100,240,100,30);  
  37.         b2.setBounds(270,240,100,30);  
  38.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  39.         setLayout(null);  
  40.         setLocation(250,100);  
  41.         setVisible(true);  
  42.         setSize(600,350);  
  43.     }  
  44.     public void actionPerformed(ActionEvent e)  
  45.     {  
  46.         if(e.getSource()==b1)  
  47.         {  
  48.             if(check())  
  49.                 count=count+1;  
  50.             current++;  
  51.             set();    
  52.             if(current==2)  
  53.             {  
  54.                 b1.setEnabled(false);  
  55.                 b2.setText("Result");  
  56.             }  
  57.         }  
  58.         if(e.getActionCommand().equals("Bookmark"))  
  59.         {  
  60.             JButton bk=new JButton("Bookmark"+x);  
  61.             bk.setBounds(480,20+30*x,100,30);  
  62.             add(bk);  
  63.             bk.addActionListener(this);  
  64.             m[x]=current;  
  65.             x++;  
  66.             current++;  
  67.             set();    
  68.             if(current==3)  
  69.                 b2.setText("Result");  
  70.             setVisible(false);  
  71.             setVisible(true);  
  72.         }  
  73.         for(int i=0,y=1;i<x;i++,y++)  
  74.         {  
  75.         if(e.getActionCommand().equals("Bookmark"+y))  
  76.         {  
  77.             if(check())  
  78.                 count=count+1;  
  79.             now=current;  
  80.             current=m[y];  
  81.             set();  
  82.             ((JButton)e.getSource()).setEnabled(false);  
  83.             current=now;  
  84.         }  
  85.         }  
  86.       
  87.         if(e.getActionCommand().equals("Result"))  
  88.         {  
  89.             if(check())  
  90.                 count=count+1;  
  91.             current++;  
  92.             //System.out.println("correct ans="+count);  
  93.             JOptionPane.showMessageDialog(this,"correct ans="+count);  
  94.             System.exit(0);  
  95.         }  
  96.     }  
  97.     void set()  
  98.     {  
  99.         jb[4].setSelected(true);  
  100.         if(current==0)  
  101.         {  
  102.             l.setText("Que1: Which name is not related to programming language ?");  
  103.             jb[0].setText("syntax");jb[1].setText("Error");jb[2].setText("logic");jb[3].setText("animal");   
  104.         }  
  105.         if(current==1)  
  106.         {  
  107.             l.setText("Que2: Is Programming knowledge important to sustain as a software engineer?");  
  108.             jb[0].setText("True");jb[1].setText("False");  
  109.         }  
  110.         if(current==2)  
  111.         {
  112. textField = new JTextField();

        textField.setBounds(128, 28, 86, 20);

        frame.getContentPane().add(textField);

        textField.setColumns(10);

         

  1.         JLabel lblName = new JLabel(“what do you mean by CSE : ");
  2.         lblName.setBounds(65, 31, 46, 14);
  3.         frame.getContentPane().add(lblName);
  4.             
  5.         }  
  6.         l.setBounds(30,40,450,20);  
  7.         for(int i=0,j=0;i<=90;i+=30,j++)  
  8.             jb[j].setBounds(50,80+i,200,20);  
  9.     }  
  10.     boolean check()  
  11.     {  
  12.         if(current==0)  
  13.             return(jb[1].isSelected());  
  14.         if(current==1)  
  15.             return(jb[2].isSelected());  
  16.         if(current==2)  
  17.             return(jb[3].isSelected());  
  18.         return false;  
  19.     }  
  20.     public static void main(String s[])  
  21.     {  
  22.         new OnlineTest("Exam application of Mulitiple choice , Fill in the blank and True or False ");  
  23.     }  
  24. }

Related Solutions

programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
A, B:   Design and Implement a C# windows form application to ask the user for 10...
A, B:   Design and Implement a C# windows form application to ask the user for 10 integer numbers, sort them in ascending order and display the sorted list. Use bubble sort technique to sort the array elements and do not use any built-in sort method to sort the array elements.                                                        [02] C:    Test and evaluate your program by inputting variety of values.
You must implement a simple program that asks the user for three values, a, b, and...
You must implement a simple program that asks the user for three values, a, b, and c, which you should store as double values. Using these numbers, you compute the value of the two solutions to the quadratic equation, assuming that the equation is of the form: ax^2 + bx + c = 0 Complete the description of the program given above so that your output looks as close to the following sample output as possible. In this sample, the...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as:...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as: 1. listnode- for data and link, constructors 2. Singlelinkedlist-for method definition 3. linkedlist-for objects -Insert a node at tail/end in a linked list. -and display all the nodes in the list. -Delete a node at a position in the list Note: Add these methods in the same application which we have done in the class. this is what we've done in the class: class...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Design and implement an application that can compute the weekly pay for different students at a college.
In Java Design and implement an application that can compute the weekly pay for different students at a college. Students (all with a name, major, GPA) can be undergraduate or graduate students. Undergraduate students can be volunteers to be tuto rs or teaching assistants. Graduate students can be teaching assistants or research assistants. Volunteer tuto rs are not paid anything. Undergraduate teaching assistants are paid $15 per hour and can work a maximum of 20 hours per week. Graduate teaching assistants...
Use DevC++ to implement a program that can store and output 5 integers, where the user...
Use DevC++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. 2. Output the content (value) that stored in the array of five elements. 3. Continue to ask the user to store for storing data into another array. c++ ONLY PLEASE NEED IT FAST AS POSSIBLE
Give three ways in which the government can intervene and solve for spillover costs.
Give three ways in which the government can intervene and solve for spillover costs.
Give three ways in which the government can intervene and solve for spillover costs.
Give three ways in which the government can intervene and solve for spillover costs.
Give three ways in which the government can intervene and solve for spillover costs.
Give three ways in which the government can intervene and solve for spillover costs.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT