944,014 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2239
  • Java RSS
Nov 3rd, 2007
0

How can i display the score and grade.......?

Expand Post »
...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.....

[code][inlinecode]
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);
}
}

[\inlinecode]
[\code]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cutekola is offline Offline
3 posts
since Oct 2007
Nov 3rd, 2007
0

Re: How can i display the score and grade.......?

if you want to match string agains string you need to use String method equals() or equalsIgnoreCase(String anotherString).
Secondly to store score you need only one variable and not four plus you DO NOT need else if part of statement! String is either what is correct answer and score get increased or it is not and score remain as it was...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: sharing of data between sites
Next Thread in Java Forum Timeline: applet array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC