Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.*; //class public class MultipleChoiceQuiz { //main method char

ID: 3766290 • Letter: I

Question

import java.util.*;

//class public class MultipleChoiceQuiz {

//main method char act_answers[]={'A','B','A','A','A','B','B','A','B','A'};

String questions[]={

"1. SOCCER IS A SPORT",

"2. RUNNING IS DANGEROUS TO YOUR HEALTH",

"3. YOU CAN ONLY USE YOUR FEET IN SOCCER UNLESS YOU ARE THE GOALIE",

"4. YOU NEED CLEATS TO PLAY SOCCER",

"5. THERE ARE RULES IN SOCCER",

"6. SOCCER IS NOT A TEAM SPORT",

"7. SOCCER DOES NOT REQUIRE STAMINA",

"8. THERE ARE 11 PLAYERS ON THE FIELD",

"9. THERE IS NO REFEREE DURING A GAME" ,

"10. ANYONE CAN PLAY SOCCER" } ;

public static void main(String args[]) {

MultipleChoiceQuiz obj=new MultipleChoiceQuiz();

//ten Questions

//variable declarations

int j; obj.calculate(); }

void calculate() {

char answer;

int d=0;

float percentage;

Scanner scan = new Scanner(System.in);

//answer check for(int a=0;a<10;a++) {

//int ch; //System.out.println("Please Enter any integer other than Z to proceed");

//ch=scan.nextInt();

System.out.println(questions[a]);

System.out.println("A.True");

System.out.println("B.False");

System.out.println("C. Can'tSay");

answer=scan.nextLine().charAt(0);

//result check switch(answer){

case 'A': if(answer==act_answers[a]) {

System.out.println("Correct!"); d++; }

else { System.out.println("The correct answer is "+act_answers[a]); }

break; case 'B': if(answer==act_answers[a]) {

System.out.println("Correct!"); d++; } else {

System.out.println("The correct answer is "+act_answers[a]); }

break; case 'C': if(answer==act_answers[a]) {

System.out.println("Correct!"); d++; } else {

System.out.println("The correct answer is "+act_answers[a]); }

break;

default:

System.out.println("Incorrect Input.Please Enter Only A B and C Choices. Thank you!");

break;

}

}

System.out.println("Number of correct answers are "+d);

percentage=(+d/10)*100;

System.out.println("Total Percentage is "+percentage+"%");

}

}

This program will not show the percentage. it only outputs 0.0

how do i fix this problem?

Explanation / Answer

Please change the statement

percentage=(+d/10)*100;

to

percentage=((float)d/10)*100;

Because 'd' is an int variable, (d/10) will produce an int value. So we have to explicitly convert 'd' into float. Then it will give the correct percentage