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

Create a class named GlobalWarming. In that class, define the following instance

ID: 3678158 • Letter: C

Question

Create a class named GlobalWarming. In that class, define the following instance variables and methods:] Instance Variables name: A String that is the name of the person taking the quiz. Methods GlobalWarming () - A default or no argument constructor that takes no parameters and initializes the instance variable to ‘null’. GlobalWarming (String name) - A constructor that takes one parameter that will be the name of the person taking the quiz, and that will be used to initialize the instance variable. sets/gets – to set and return the value of the instance variable(s) quiz () – a method that administers the 10 question quiz. It will calculate the number of correct answers and return that value to the calling ‘main’ method. 2. Create a test driver class named GlobalWarmingTest. This class will contain the ‘main’ method. The method will create/instantiate an object of type GlobalWarming, passing the name of the person taking the test as a parameter. (No need to read a value, simple write the statement creating the object and calling the constructor with your name as parameter.) Once the object is created, ‘main’ will call the quiz () method of Global Warming. When quiz () returns, use the return value to select and print the appropriate message as follows: 10 correct: “Excellent” 8-9 correct: “Very good” 6 or fewer: “Time to brush up on your knowledge of Global Warming”

Explanation / Answer

import java.util.Random;

/**
* @author Srinivas Palli
*
*/
public class GlobalWarming {

   String personName;

   public GlobalWarming() {
       // TODO Auto-generated constructor stub
       personName = null;
   }

   /**
   * @param personName
   */
   public GlobalWarming(String personName) {

       this.personName = personName;
   }

   /**
   * @return the personName
   */
   public String getPersonName() {
       return personName;
   }

   /**
   * @param personName
   * the personName to set
   */
   public void setPersonName(String personName) {
       this.personName = personName;
   }

   /**
   * @return
   */
   public int quiz() {

       int correctAns = 0;
       Random random = new Random();
       correctAns = random.nextInt(10);
       return correctAns;

   }

}

/**
* @author srinu
*
*/
public class GlobalWarmingTest {
   /**
   * @param args
   */
   public static void main(String[] args) {

       GlobalWarming globalWarming = new GlobalWarming("Srinivas");

       int correctAns = globalWarming.quiz();
       if (correctAns == 10) {
           System.out.println("Excellent");

       } else if (correctAns <= 9 && correctAns >= 8) {
           System.out.println("Very Good");

       } else if (correctAns <= 6) {

           System.out
                   .println("Time to brush up on your knowledge of Global Warming");
       }
   }

}

OUTPUT:

Time to brush up on your knowledge of Global Warming

Note: please define how to implement the quiz(), i dont how to caliculate the correct answers, for that i taken the random

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