Running totals to work throughout classes in java? -


I am writing a program that includes a test when the user clicks on submitting it, then it is true or false Prints and then goes to a different class. In addition to doing this, I want that if answer 1 is correct to add it to the variable.

What I can not work on is how to do this in different classes because all questions for 1 or 0 should be added, which are saved in different classes But in the same project.

Is there any reason that each question is a different category? It seems that you may have a single question class that holds the example variable, such as

  public class questions {private string text; // questions own personal string [] option; // Option if this is a multi-option question private answer; // Select the option that is the correct answer / constructor, accessory, mute, public string toastring () {string down = it.Text + "\ n"; For {int x = 0; x & lt; options.length; x ++} {char c = 'a' + x; // it will give characters as alphabetically described as' one + rated + = c + ")" + option [x] + "\ n"; } Return refund; }}   

Then you can do a test class with the main method. Public class test {public static zero (string argument []) {question [] question = {new question ("what is 1 + 1?", New string [] {"2" , "3", "4"}, 0), // other questions here} integer = 0; Scanner input = new scanner (System.in); (Question Q: Question) {System.out.println (q.toString ()); Int ans = input.nextLine () Fourat (0) - 'A'; If (q.getAnswer () == ans) {total ++; }}}}

What kind of things do you want?

Comments