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: 3677974 • 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.Scanner;
public class GlobalWarming
{
private String userName;
public GlobalWarming()
{
userName = null;
}
public GlobalWarming(String name)
{
userName = name;
}
void setUserName(String name)
{
userName = name;
}
public String getUserName()
{
return userName;
}
public int quiz()
{
Scanner input = new Scanner(System.in);
int totalCorrect = 0;
String correctAnswer;
String userAnswer;
System.out.println("1)The depletion of which of the following can contribute to stronger UV rays reaching earth?");
System.out.println("a)Ozone layer ");
System.out.println("b)Oxygen ");
System.out.println("c)Co2 ");
System.out.println("d)clouds ");
correctAnswer = "a";
System.out.print("Please enter your selection: ");
userAnswer = input.nextLine();
if (userAnswer == correctAnswer)
{
totalCorrect = totalCorrect + 1;
}
return totalCorrect;
}

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