Question

import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {...

import java.util.Scanner;
import java.util.ArrayList;

public class P3A2_BRANDT_4005916
{
   public static void main(String[] args)
   {
       String name;
       String answer;
       int correct = 0;
       int incorrect = 0;
       Scanner phantom = new Scanner(System.in);

       System.out.println("Hello, What is your name?");
       name = phantom.nextLine();

       System.out.println("Welcome " + name + "!\n");

       System.out.println("My name is Danielle Brandt. "
           +"This is a quiz program that will test your JAVA knowledge"
           +"with multiple choice questions!\n\n");
       System.out.println("Lets start the quiz!\n\n");

       ArrayList<String> questions = new ArrayList<String>();

       questions.add("Which of the following is considered an input device?\n"
           + "(a)Speakers\n(b)Printer\n(c)Central Processing Unit\n(d)Keyboard");

       questions.add("What variable is Legal in Java?\n"
           + "(a)dayOfWeek\n(b)3dGraph\n(c)mixture#3\n(d)week day\n");
       questions.add("What is the purpose of the binary logical operators, && and ||,"
           +"that java provides?\n"
           +"(a)marks beginning of a comment\n(b)combines two boolean expressions into a single expression\n"
           +"(c)indicates end of a statement\n(d)causes a backslash to be printed");

       ArrayList<String> answers = new ArrayList<String>();
       answers.add("d");
       answers.add("a");
       answers.add("b");

       for(int i = 0; i < questions.size(); i++)
       {
           System.out.println(questions.get(i));
           String ans = answers.get(i);
           String user = phantom.nextLine();
           if(user.equalsIgnoreCase(ans))
           {
               System.out.println("That is correct!");
               correct++;
           }
           else
           {
               System.out.println("Sorry, that's incorrect!");
               incorrect++;
           }
       }
       System.out.println("The total you got correct is: " + correct);
       System.out.println("The total you got incorrect is: " + incorrect);
   }
}

how do i make another class that contains the questions, a constructor, accessor methods, and anything else needed to make program run?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

QuestionGenerator.java

package classes5;

import java.util.ArrayList;

public class QuestionGenerator {

ArrayList<String> questions;

ArrayList<String> answers;

QuestionGenerator(){

questions = new ArrayList<String>();

questions.add("Which of the following is considered an input device?\n"

+ "(a)Speakers\n(b)Printer\n(c)Central Processing Unit\n(d)Keyboard");

questions.add("What variable is Legal in Java?\n"

+ "(a)dayOfWeek\n(b)3dGraph\n(c)mixture#3\n(d)week day\n");

questions.add("What is the purpose of the binary logical operators, && and ||,"

+"that java provides?\n"

+"(a)marks beginning of a comment\n(b)combines two boolean expressions into a single expression\n"

+"(c)indicates end of a statement\n(d)causes a backslash to be printed");

answers = new ArrayList<String>();

answers.add("d");

answers.add("a");

answers.add("b");

}

void welcomeMessage(){

System.out.println("My name is Danielle Brandt. "

+"This is a quiz program that will test your JAVA knowledge"

+"with multiple choice questions!\n\n");

System.out.println("Lets start the quiz!\n\n");

}

String getQuestionNumber(int i){

return questions.get(i);

}

int getQuestionSize(){

return questions.size();

}

String getAnswerNumber(int i){

return answers.get(i);

}

}

P3A2_BRANDT_4005916.java

package classes5;

import java.util.Scanner;

import java.util.ArrayList;

public class P3A2_BRANDT_4005916

{

public static void main(String[] args)

{

String name;

int correct = 0;

int incorrect = 0;

Scanner phantom = new Scanner(System.in);

System.out.println("Hello, What is your name?");

name = phantom.nextLine();

System.out.println("Welcome " + name + "!\n");

QuestionGenerator tester = new QuestionGenerator();

for(int i = 0; i < tester.getQuestionSize(); i++)

{

System.out.println(tester.getQuestionNumber(i));

String ans = tester.getAnswerNumber(i);

String user = phantom.nextLine();

if(user.equalsIgnoreCase(ans))

{

System.out.println("That is correct!");

correct++;

}

else

{

System.out.println("Sorry, that's incorrect!");

incorrect++;

}

}

System.out.println("The total you got correct is: " + correct);

System.out.println("The total you got incorrect is: " + incorrect);

}

}

output:

Quick AccessJava EE Java Debu e Console X <terminated> P3A2_BRANDT_4005916 Java Application] C:Program Files\Javajre7\bin\javaw.exe (Dec 7, 2018, 10:24:0 Hello, What is your name? srk Welcome srk! Which of the following is considered an input device? (a) Speakers (b) Printer (c)Central Processing Unit (d) Keyboard em. 11 Sorry, thats incorrect! What variable is Legal in Java? (a) dayOfWeek (b) 3dGraph (c) mixture#3 me + stio(d) week day ionS uest umbe That is correct! e What is the purpose of the binary logical operators, &&and 11, tha (a)marks beginning of a comment (b) combines two boolean expressions into a single expression (c)indicates end of a statement s co(d) causes a backslash to be printed Sorry, thats incorrect The total you got correct is: 1 The total you got incorrect is: 2 that got got

Add a comment
Know the answer?
Add Answer to:
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 {    public static void main(String[] args)    {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args)...

    Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn);    else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25);...

    import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5);    Scanner keyboard = new Scanner(System.in);    int i = 0; int total = 0;    while(true){    i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue();    dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables...

    import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables int creditScore; double loanAmount,interestRate,interestAmount; final double I_a = 5.56,I_b = 6.38,I_c = 7.12,I_d = 9.34,I_e = 12.45,I_f = 0; String instructions = "This program calculates annual interest\n"+"based on a credit score.\n\n"; String output; Scanner input = new Scanner(System.in);// for receiving input from keyboard // get input from user System.out.println(instructions ); System.out.println("Enter the loan amount: $"); loanAmount = input.nextDouble(); System.out.println("Enter the credit score: "); creditScore...

  • make this program run import java.util.Scanner; public class PetDemo { public static void main (String []...

    make this program run import java.util.Scanner; public class PetDemo { public static void main (String [] args) { Pet yourPet = new Pet ("Jane Doe"); System.out.println ("My records on your pet are inaccurate."); System.out.println ("Here is what they currently say:"); yourPet.writeOutput (); Scanner keyboard = new Scanner (System.in); System.out.println ("Please enter the correct pet name:"); String correctName = keyboard.nextLine (); yourPet.setName (correctName); System.out.println ("Please enter the correct pet age:"); int correctAge = keyboard.nextInt (); yourPet.setAge (correctAge); System.out.println ("Please enter the...

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT