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

In JAVA , using Object-Oriented Design , can someone please answer this program.

ID: 3724129 • Letter: I

Question

In JAVA, using Object-Oriented Design, can someone please answer this program. (Global Warming Facts Quiz) The controversial issue of global warming has been widely publicized by the film "An Inconvenient Truth", featuring former Vice President Al Gore. Mr. Gore and a U. N. network of scientists, the Intergovernmental Panel on Climate Change, shared the 2007 Nobel Peace Prize in recognition of "their efforts to build up and disseminate greater knowledge about man-made climate change." Research both sides of the global warming issue online (you might want to search for phrases like "global warming skeptics"). Create a five-question multiple choice quiz on global warming, each question having four possible answers(numbered 1-4). Be objective and try to fairly represent both sides of the issue. Next write an application that administers the quiz, calculate the number of correct answers (zero through five) and returns a message to the user. If the user correctly answers five questions, print "Excellent"; if four, print "Very good"; if three or fewer, print "Time to brush up your knowledge of global warming,". Include a list of websites where you found your facts.

Java How to Program Early Objects 11th Edition. Chapter 5 Exercise 31

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

// GolbalWarmingQuiz.java

import java.util.Scanner;

public class GolbalWarmingQuiz {

            static Question[] questions;

            static int score;

            static Scanner scanner;

            /**

            * method to initialize the questions array and fill with 5 questions

            */

            static void initQuestions() {

                        questions = new Question[5];

                        questions[0] = new Question(

                                                "Which country currently emits the most greenhouse gases?",

                                                new String[] { "UK", "US", "China", "India" }, 3);

                        questions[1] = new Question(

                                                "Which of the following lightbulb types uses the least energy,"

                                                                        + " and therefore results in fewer greenhouse gas emissions?",

                                                new String[] { "Incandescent", "Halogen", "Metal Halide",

                                                                        "Compact Flourescent" }, 4);

                        questions[2] = new Question(

                                                "How long does it take for carbon dioxide in the atmosphere to disperse?",

                                                new String[] { "1 year", "100 years", "10 years", "50 years" },

                                                2);

                        questions[3] = new Question(

                                                "Which Arctic animal do many scientists consider most vulnerable"

                                                                        + " to extinction due to global warming?",

                                                new String[] { "Polar bears", "Narwhals", "Toucans",

                                                                        "Tropical frogs" }, 2);

                        questions[4] = new Question(

                                                "As air pollution continues to be released into the atmosphere,"

                                                                        + " what becomes more depleted, resulting in an increase"

                                                                        + " of ultraviolet radiation on earth?", new String[] {

                                                                        "Oceans", "Rain forests", "Ozone layer",

                                                                        "Carbon dioxide" }, 3);

                        /**

                        * Setting score to 0

                        */

                        score = 0;

            }

            public static void main(String[] args) {

                        /**

                        * Initializing scanner to read user input

                        */

                        scanner = new Scanner(System.in);

                        /**

                        * Initializing the questions

                        */

                        initQuestions();

                        /**

                        * Looping through all questions, displaying it, getting the user

                        * answer, checking if its a right choice

                        */

                        int i = 0;

                        while (i < questions.length) {

                                    /**

                                    * Displaying the question, with question number

                                    */

                                    System.out.println("Question (" + (i + 1) + "): "

                                                            + questions[i].getQuestion());

                                    /**

                                    * Getting all the options for this question

                                    */

                                    String[] options = questions[i].getOptions();

                                    /**

                                    * Displaying all options

                                    */

                                    for (int j = 0; j < options.length; j++) {

                                                System.out.println(" " + (j + 1) + ": " + options[j]);

                                    }

                                    System.out.println("## Enter your choice: ");

                                    /**

                                    * getting the user choice

                                    */

                                    int choice = Integer.parseInt(scanner.nextLine());

                                    if (choice < 1 || choice > options.length) {

                                                /**

                                                * not a valid choice

                                                */

                                                System.out.println("Invalid choice, try again");

                                    } else {

                                                /**

                                                * Checking if it is the right choice

                                                */

                                                if (questions[i].isCorrect(choice)) {

                                                            /**

                                                            * Right answer, incrementing the score

                                                            */

                                                            score++;

                                                            System.out.println("Right answer!");

                                                } else {

                                                            /**

                                                            * Wrong answer, displaying the right option

                                                            */

                                                            System.out.println("Wrong answer!, the right option was "

                                                                                    + questions[i].getRightOption());

                                                }

                                                i++; //moving to next question

                                    }

                        }

                        /**

                        * checking the final score

                        */

                        if (score == 5) {

                                    /**

                                    * Full score

                                    */

                                    System.out.println("Excellent, you have scored " + score

                                                            + " out of " + questions.length);

                        } else if (score == 4) {

                                    /**

                                    * score is 4

                                    */

                                    System.out.println("Very good, you have scored " + score

                                                            + " out of " + questions.length);

                        } else {

                                    /**

                                    * less than 4

                                    */

                                    System.out

                                                            .println("Time to brush up your knowledge of global warming, you have scored "

                                                                                    + score + " out of " + questions.length);

                        }

            }

}

/**

* An inner class defined to represent a Question.

* This should be placed within the same java file

*/

class Question {

            /**

            * variable to store the question

            */

            private String question;

            /**

            * a string array to store all options

            */

            private String[] options;

            /**

            * an int variable denoting the right option

            */

            private int rightOption;

            public Question(String question, String[] options, int rightOption) {

                        /**

                        * Initialzes an option

                        */

                        this.question = question;

                        this.options = options;

                        this.rightOption = rightOption;

            }

            /*useful getters*/

            public String getQuestion() {

                        return question;

            }

            public String[] getOptions() {

                        return options;

            }

           

            public int getRightOption() {

                        return rightOption;

            }

            /**

            * method to check if an option is correct

            */

            public boolean isCorrect(int option) {

                        if (rightOption == option) {

                                    return true;

                        }

                        return false;

            }

}

/*OUTPUT*/

Question (1): Which country currently emits the most greenhouse gases?

1: UK

2: US

3: China

4: India

## Enter your choice:

3

Right answer!

Question (2): Which of the following lightbulb types uses the least energy, and therefore results in fewer greenhouse gas emissions?

1: Incandescent

2: Halogen

3: Metal Halide

4: Compact Flourescent

## Enter your choice:

4

Right answer!

Question (3): How long does it take for carbon dioxide in the atmosphere to disperse?

1: 1 year

2: 100 years

3: 10 years

4: 50 years

## Enter your choice:

4

Wrong answer!, the right option was 2

Question (4): Which Arctic animal do many scientists consider most vulnerable to extinction due to global warming?

1: Polar bears

2: Narwhals

3: Toucans

4: Tropical frogs

## Enter your choice:

2

Right answer!

Question (5): As air pollution continues to be released into the atmosphere, what becomes more depleted, resulting in an increase of ultraviolet radiation on earth?

1: Oceans

2: Rain forests

3: Ozone layer

4: Carbon dioxide

## Enter your choice:

3

Right answer!

Very good, you have scored 4 out of 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote