Question: Hello, so I am creating a program in netbeans that gives a 10 question quiz and calculates how many are right or wrong and tells

Hello, so I am creating a program in netbeans that gives a 10 question quiz and calculates how many are right or wrong and tells the student what his or her grade is afterwards. I've figured out most of it except the variable for the number of correct answers being printed in the output correctly. When I tried to make the variable numCorrect add one whenever the user gets it right, I print the variable afterwards and it still says zero

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package assignment4;

import static java.lang.System.out;

import java.util.Random;

import java.util.Scanner;

/**

*

* @author Harper

*/

public class Assignment4 {

// standard final static variables that all methods can share

final static Scanner cin = new Scanner(System.in);

final static Random rand = new Random();

public static void main(String[] args) {

// output identification

int x=1, numProbs=10, numCorrect=0, probNum=1;

out.print("CPS 150 Assignment 4 by Harper Miller ");

out.println();

out.println("Welcome to the Addition tutor program");

out.print("Enter your Given name (no spaces):");

String name=cin.nextLine();

out.println();

out.println("Greetings, " +name + "!");

out.println("I will ask you 10 Problems");

out.println("Ready, set, go!");

while (10>=x){

oneProblem(numCorrect , probNum);

probNum+=1;

x+=1;}

// NEED TO ADD THINGS HERE (THE DEFINITE LOOP SHOULD BE HERE!)

out.print(numCorrect);

out.print(" Assignment 4 complete ");

} // end main

// function to present one problem to the learner

static int oneProblem(int numCorrect, int probNum) {

int z , y , answer;

z=10+rand.nextInt(90);

y=10+rand.nextInt(90);

out.print("Problem " + probNum + ": " + z + " + " + y + "= ? ");

answer=cin.nextInt();

if (z+y == answer){

numCorrect++;

out.println("Your answer is correct!");}

else{

answer= z+y;

out.println("your answer is wrong. The correct answer is:" + answer);}

return numCorrect ; // to let the program compile

} // end oneproblem

static void report(String name, int numProbs, int numCorrect) {

// NEED TO ADD THINGS HERE

} // end report

static char getLetterGrade(int numProbs, int numCorrect) {

// NEED TO ADD THINGS HERE

return 'X'; // to let the program compile

} // end getLetterGrade

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!