0

...kindly help me with this..........my code doesn't work....
...create a program that will ask questions and at the end of the session it will display the total number of correct answers and the equivalent grade....

...thanks.....

import javax.swing.JOptionPane;
public class questions {

    public static void main(String[] args) {

    int score=0;
    int score1=0;
    int score2=0;

    String q1=JOptionPane.showInputDialog(null,"one plus one is? ");
        if (q1=="two")
        {
        score1=score+1;
        }
            else if(q1!="two")
            {
                score1=score+0; 
            }   
    String q2=JOptionPane.showInputDialog(null,"four times four is? ");
        if (q2=="sixteen")
        {
        score2=score1+1;
        }
            else if(q1!="sixteen")
            {
                score2=score1+0; 
            }
    int tscore=score1+score2;
    double grade=(tscore/2)* (100);
    JOptionPane.showMessageDialog(null,"Your score is "+ tscore +" over 2!" 
        + "\n" + "Your grade is " + grade);
    System.exit(0);
    }
}

Edited by Dani: Fixed formatting

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by peter_budo
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.