Question

In: Computer Science

I need to display the questions that the user answered total, wrong and right as well...

I need to display the questions that the user answered total, wrong and right as well as the average percentage they got correct of the following code please!

public class TestCode {
    public static void main(String[] args) {
        String choice = "Yes";
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        while(!choice.equals("No")){
            int randomInt = 2 * (random.nextInteger(5) + 1);
            System.out.println(randomInteger);
            System.out.print("Want another random number (Yes / No)? ");
            choice = scanner.next();
        }
    }
}

Solutions

Expert Solution

import java.util.Random;
import java.util.Scanner;

//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        String choice = "Yes";
        Random random = new Random();
        Scanner scanner = new Scanner(System.in);
        int correct = 0, wrong = 0, total = 0;
        while(!choice.equals("No")){
            int randomInt1 = 2 * (random.nextInt(5) + 1);
            int randomInt2 = 2 * (random.nextInt(5) + 1);
            System.out.print("What is "+randomInt1+" + "+randomInt2+"? ");
            int res = scanner.nextInt();
            if(res == (randomInt1+randomInt2)){
                correct++;
            }
            else{
                wrong++;
            }
            total++;
            System.out.print("Want another question (Yes / No)? ");
            choice = scanner.next();
        }

        System.out.println("Number of correct answers = "+correct);
        System.out.println("Number of wrong answers = "+wrong);
        System.out.println("Average percentage you got = "+(100.0*correct/total));
    }
}


Related Solutions

4 of these questions are wrong. I need to know which question I got wrong because...
4 of these questions are wrong. I need to know which question I got wrong because I am not sure. During the early and middle twentieth century, there was a sharp increase in human birth rate. a sharp decrease in human death rate. (both) (neither) True/False: If you ask a population ecologist, all the individuals in a population belong to the same species. : True A single population might exist in multiple territories that do not overlap, with no migration...
I just need A2, A3, and B answered. A1 I have the correct Answers, as well...
I just need A2, A3, and B answered. A1 I have the correct Answers, as well as C. AccuBlade Castings Inc. casts blades for turbine engines. Within the Casting Department, alloy is first melted in a crucible, then poured into molds to produce the castings. On May 1, there were 900 pounds of alloy in process, which were 60% complete as to conversion. The Work in Process balance for these 900 pounds was $140,940, determined as follows: Direct materials (900...
For the state of New Mexico and Colorado, I need the following questions answered please: a)...
For the state of New Mexico and Colorado, I need the following questions answered please: a) To what extent does New Mexico and Colorado follow the rulings of the Multistate Tax Commission? b) Does New Mexico and Colorado adopt pertinent changes to the Internal Revenue Code? If so, as of what date? c) Is the tax effectiveness of a passive investment company limited in some way? Has New Mexico and Colorado adopted the Geoffrey approach to the taxation of income...
I posted this question before and the person who answered it answered wrong.........please have someone else...
I posted this question before and the person who answered it answered wrong.........please have someone else try again The following information applies to the questions displayed below.] O’Brien Company manufactures and sells one product. The following information pertains to each of the company’s first three years of operations: Variable costs per unit: Manufacturing: Direct materials $28 Direct labor $15 Variable manufacturing overhead $5 Variable selling and administrative $3 Fixed costs per year: Fixed manufacturing overhead $580,000 Fixed selling and administrative...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND 4. I HAVE FILLED OUT THE PERCENTAGE CHANGE FOR QUESTION 3, AND NEED HELP ON CALCULATING THE OPERATING, INVESTING, AND FINANCIAL SECTIONS. AS WELL AS, THE EQUATIONS FOR QUESTION 4. IF YOU CAN ANSWER QUESTIONS 3 & 4 I WILL AWARD CREDIT. Question 1: Common size for income statement Income Statement (Common Size) :                                                                  Consolidated Income Statement 2011 % 2010 % Revenue $19,176.1...
I have two questions that need to be answered, I can't figure them out: 1) Steve...
I have two questions that need to be answered, I can't figure them out: 1) Steve Coleman has just won the state lottery and has the following three payout options for afterminus?tax prize? money:1. $ 152 comma 000$152,000 per year at the end of each of the next six years2. $ 318 comma 000$318,000 ?(lump sum) now3. $ 500 comma 000$500,000 ?(lump sum) six years from now The annual discount rate is? 9%. Compute the present value of the second...
Give a brief description of yourself. Also I have ten interview questions i need answered for...
Give a brief description of yourself. Also I have ten interview questions i need answered for a sociology paper. What do you do for a living? What made you want to work in this field? How would you describe your social class? Where were you born/what is your neighborhood like? Do you think it’s easier for one to come from a higher class or for one to move up to a higher class? What is your heritage? Do you think...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature...
*I NEED ALL OF THE QUESTIONS ANSWERED* 1.Heat is (a) equal to temperature, (b) the temperature change divided by the mass, (c) the mass divided by specific heat, (d) the flow of energy due to a temperature difference. 2.The human temperature sense is associated with (a) sight, (b) smell, (c) touch, (d) hearing. 3.Temperature is a relative measure of (a) transferred energy, (b) hotness or coldness,                     (c) internal energy, (d) specific heat. 4.The temperature difference between the ice and steam...
I need the following questions answered with an explanation. 1. Which of the following constitutes market...
I need the following questions answered with an explanation. 1. Which of the following constitutes market failure? The inability of markets to _____ a. internalize positive externalities b. internalize negative externalities c. Both a. and b. d. None of the above 2. When is the burden of an excise tax incidence equally shared between producers and consumers? a.The tax burden is always equally shared between producers and consumers. b. When the slope of the supply curve is steeper than the...
Why are my questions not answered? I am waiting and waiting and desperately need it done....
Why are my questions not answered? I am waiting and waiting and desperately need it done. Here: A new business client comes to your office. There are three owners of the business. The three individuals, Alan, Bob, and Carol, are thinking about forming a partnership. Alan is only investing $1 million in cash. He will not have anything to do with the daily activities of the business. Bob has had some experience in the business and will be responsible for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT