Please help me with my homework on my Java coding on line 84 for public static void main(String[] args)} I am sending you my coding in Java and I can't seem to pull up the dialog box for it. import javax.swing.JOptionPane; public class Quiz {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help me with my homework on my Java coding on line 84 for 

public static void main(String[] args)}   

I am sending you my coding in Java and I can't seem to pull up the dialog box for it.

 

import javax.swing.JOptionPane;
public class Quiz
{
/**
* the function isValid accepts a string and checks to see if it is A,B,C,D
* and returns a boolean value of true or false if it matches
*/
private static boolean isValid(Sting a)
{
a=a.toLowerCase();
if(a.equals("a")||a.equals("b")||a.equals("c")||a.equals("d"))
{
return true;
}
else
{
JOptionPane.showMessageDialog(null,"Please pick A,B,C,D");
return false;
}
}
/**
* askQuestion function receives an array containing the question and all the
* answers. The function return the user input as a String
*/
private static String askQuestion(String[]q)
{
String fmtQuestion ="";//String to hold the formatted question
String answer = "";

for (int i = 0; i <q.length;i++)
fmtQuestion+=q[i]+"\n";

do
{
answer=JOptionPane.showInputDialog(null,fmtQuestion);
if(answer==null)
{
int quit=JOptionPane.showConfirmDialog(null,"Would you like to quit?","Quit",JOptionPane.YES_NO_OPTION);
if(quit==0)
return"CANCEL";
else
continue;
}
}while(answer==null||!(isValid(answer)));

return answer;
}
/**
* Function isCorrect receives two values a (correct answer) and r (incorrect
* answer). Returning boolean value if the answer is correct or not
*/
private static boolean isCorrect(String a, String r)//a=correct answer, r=user response
{
r=r.toUpperCase();
if(a.equals(r))
{
JOptionPane.showMessageDialog(null,"Correct!");
return true;
}
else
{
JOptionPane.showMessageDialog(null,"The correct answer is:\n" +a);
return false;
}
}
/**
* showGrade accepts two values c(total correct answers) and total
* incorrect answers). A message dialog is displayed stating the total
* correct, incorrect, and the grade for the quiz result
*/
public static void showGrade(int c, int i)
{
int numberQuestions=c+i;
String fmtGrade="";
int pontsPerQuestion = 100/numberQuestions;
int grade c*pointsPerQuestion;

fmtGrade+="You answered"+c+"correctly and"+i+"incorrectly";
fmtGrade+="\nYour grade is:"+grade+"%";

JOptionPane.showMessageDialog(null, fmtGrade);
}

public static void main(String[] args)}
{
int i=0;//iterator to be used later for the askQuestion loop
int correct=0;
int incorrect=0;
String response="";

String[][] question=new String[6][5];//Array to store questions
String[] correctAnswer=new String[6];//Array to store correct answers

question[0][0]= "What is not a part of a handbag?";
question[0][1]= "A) Strap";
question[0][2]= "B) Buckle";
question[0][3]= "C) Clutch";
question[0][4]= "D) Lipstick";
correctAnswer[0]="D";

question[1][0]="What is not a gym equipment";
question[1][1]="A) Eggie";
question[1][2]="B) Elipticle";
question[1][3]="C) Treadmill";
question[1][4]="D) Weights";
correctAnswer[1]="A";

question[2][0]="Who is not a Disney Character?";
question[2][1]="A)Donald Duck";
question[2][2]="B)Mickey Mouse";
question[2][3]="C)Goofey";
question[2][4]="D)Sponge Bob";
correctAnswer[2]="D";

question[3][0]="Which is not a Font Class?";
question[3][1]="A)Helvetica";
question[3][2]="B)Graphic";
question[3][3]="C)Arial";
question[3][4]="D)Times New Roman";
correctAnswer[3]="B";

question[4][0]="Whis is not a primitive Data Type keyword?";
question[4][1]="A) Double";
question[4][2]="B) Char";
question[4][3]="C) Java";
question[4][4]="D) Int";
correctAnswer[4]="C";

question[5][0]="Which are not the Flower Names?";
question[5][1]="A) Tulips";
question[5][2]="B) Cabbage";
question[5][3]="C) Lilies";
question[5][4]="D) Roses";
correctAnswer[5]="B";

//loop through the question array asking each one
do
{
response=askQuestion(question[i]);
if(response.equals("CANCEL"))
return;
if(isCorrect(correctAnswer[i],response))
correct +=1;
else
incorrect +=1;

i++;
}while(i<question.length);

showGrade(correct,incorrect);
}
}
}

 

 




 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education