Created
May 4, 2024 04:06
-
-
Save uvita2399/d1f41dbb5c8f3296ed97a395c3fd1ac7 to your computer and use it in GitHub Desktop.
Bloated code?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Various Messages | |
final String boxMessage = "License Game"; | |
final String welcomeMessage = "Welcome to License Game"; | |
//Questions | |
final String question1 = "What does this mean... A: text B: text C: "; | |
final String question2 = "What does this mean... A: text B: text C: "; | |
final String question3 = "What does this mean... A: text B: text C: "; | |
final String question4 = "What does this mean... A: text B: text C: "; | |
final String question5 = "What does this mean... A: text B: text C: "; | |
//Correct Answers | |
final String answer1= "B"; | |
final String answer3= "B"; | |
final String answer4= "A"; | |
final String answer5= "A"; | |
userName = (String)JOptionPane.showInputDialog(null, welcomeMessage, boxMessage , JOptionPane.DEFAULT_OPTION, new ImageIcon(LicenseGameSample.class.getResource("/img/ExamLogo2.png")), null, null); | |
//Question 2 | |
userAnswer = (String)JOptionPane.showInputDialog(null, question2, boxMessage , JOptionPane.DEFAULT_OPTION, new ImageIcon(LicenseGameSample.class.getResource("/img/b227.jpg")), null, null); | |
if (userAnswer.equalsIgnoreCase(answer2)) { | |
correctAnswers++; | |
} else { | |
wrongAnswers++; | |
} | |
//Question 3 | |
userAnswer = (String)JOptionPane.showInputDialog(null, question3, boxMessage , JOptionPane.DEFAULT_OPTION, new ImageIcon(LicenseGameSample.class.getResource("/img/b231.jpg")), null, null); | |
if (userAnswer.equalsIgnoreCase(answer3)) { | |
correctAnswers++; | |
} else { | |
wrongAnswers++; | |
} | |
//Final Result | |
String failedMessage = "You failed" + userName + "\nYou had " + correctAnswers + " correct answers" + " and " + wrongAnswers + "wrong Answers"; | |
String passedMessage = "You Passed" + userName + "\nYou had " + correctAnswers + "correct answers" + " and " + wrongAnswers + "wrong answers"; | |
if (correctAnswers >= passingMark) { | |
JOptionPane.showMessageDialog(null, passedMessage, boxMessage, JOptionPane.DEFAULT_OPTION, new ImageIcon(LicenseGameSample.class.getResource("/img/Passed.png"))); | |
} else { | |
JOptionPane.showMessageDialog(null, failedMessage, boxMessage, JOptionPane.DEFAULT_OPTION, new ImageIcon(LicenseGameSample.class.getResource("/img/Failed.png"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment