| | |
How can i display the score and grade.......?
Thread Solved |
...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]
...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]
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...
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...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Need help with Arrays (Visual Basic 4 / 5 / 6)
- c++ scores (C++)
- correct my algorithm for average problem (C++)
- First time using JLabel and JTextArea. Please help!!! (Java)
- Help With Java programming (Java)
- Help with an Array GRading assignment (Java)
Other Threads in the Java Forum
- Previous Thread: sharing of data between sites
- Next Thread: applet array
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






