1. Create a class named GlobalWarming . In that class, define the following inst
ID: 671104 • Letter: 1
Question
1. 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 (yes, 10 questions not the 5 of the text). 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”
Question itself is; (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 scientist, the intergovernmental Panel on Climate change, shared the 2007 Nobel Peace Prize in recognition of "their efforts to build up and dissminate 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 ansers (numbered 1-4). Be objective and try to fairly represent both sides of the issue. Next, write an application that administers the quiz, calculates the number of correct answers (zero through five) and returns a message to the user. If the user correctly ansers five questions, print "Excellent"; if four,print "Very good"; if three or fewer points, print "Time to brush up on your knowledge of global warming," and include a list of some of the webssites where you found your facts.
Explanation / Answer
package mani;
import java.util.Scanner;
public class GlobalWarming
{
String name;
public GlobalWarming(){
name=null;
}
public GlobalWarming(String name){
this.name=name;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public int quiz(){
Scanner scan=new Scanner(System.in);
int count=0;
String[] Question=new String[5];
Question[0]="Which gas is responsible for the global warming?";
Question[1]="The 2009 UN climate summit is organized at _____?";
Question[2]="The depletion of which of the following can contribute to stronger UV rays reaching earth?";
Question[3]="Which is the only country who has not ratified the Kyoto Protocol yet?";
Question[4]="Which of the following effect is responsible for Global Warming?";
String[][] options=new String[5][4];
options[4][0]="White House effect ";options[4][1]="Blue House effect ";options[4][2]="Green House Effect";options[4][3]="Red House Effect ";
options[3][0]="Australia ";options[3][1]="United states ";options[3][2]="Japan";options[3][3]="India ";
options[2][0]="Ozone layer ";options[2][1]="Oxygen ";options[2][2]="Carbon dioxide";options[2][3]="clouds";
options[1][0]="Dubai ";options[1][1]="Copenhagen ";options[1][2]="New York";options[1][3]="London ";
options[0][0]="Nitrogen ";options[0][1]="Nobel gases ";options[0][2]="Carbon dioxide";options[0][3]="Sulphates ";
int[] ans=new int[5];
ans[4]=3;ans[3]=2;ans[2]=1;ans[1]=2;ans[0]=3;
System.out.println("Here are your global warming questions: ");
for(int i=0;i<5;i++){
System.out.println(Question[i]);
for(int j=0;j<4;j++){
System.out.println((j+1)+". "+options[i][j]);
}
System.out.print("Your answer(1/2/3/4): ");
int answer=scan.nextInt();
if(answer==ans[i]){
count++;
}
}
return count;
}
}
package mani;
import java.util.Scanner;
public class GlobalWarmingTest
{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
System.out.print("Your name: ");
String name = scn.nextLine();
GlobalWarming g=new GlobalWarming(name);
System.out.println("Your name: "+g.getName());
System.out.println("Here are your questions: ");
int correct=g.quiz();
if(correct==5){
System.out.println("You Are EXCELLENT!!!!!");
}else if(correct==4){
System.out.println("You are very good!!!");
}else{
System.out.println("Time to brush up on your knowledge of global warming," );
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.