Question

*Java* Given the attached Question class and quiz text, write a driver program to input the...

*Java*

Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results.

Write a Quiz class for the driver, with a main method.

There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of questions.

The constructor should instantiate the Question array, open the file with the Scanner, and input the Question array from the input file. Note that one of the constructors for the Question class takes a Scanner parameter and initializes an entire question from the Scanner. There is a blank line at the end of the file, so hasNextLine() would work for the loop. After the input loop, the count field should be the number of questions.

A give() method should declare and instantiate a Scanner for keyboard input, counters for correct and incorrect answers, an array (or ArrayList) of ints for the numbers that were incorrect, and an array (or ArrayList) of chars for the answers that were incorrect. It should loop through each question and print it out, prompt for the answer, count it if it is right and save the question number and wrong answer in the two arrays (or ArrayLists) if it is wrong. After this loop, it should print out the number correct and the numbers that were wrong, with the wrong answers.

The main method should just instantiate a Quiz and call its give() method.

This is the quiz

Formed on a diskette (or hard drive) during initialization.
source code
images
sectors
storage units
c
The CPU consists of:
Control Unit, Temporary Memory, Output
Control Unit, Arithmetic Logic Unit, Temporary Memory
Input, Process, Storage, Output
Input, Control Unit, Arithmetic Logic Unit, Output
b
OOP stands for:
Observable Object Programming
Object Observed Procedures
Object Oriented Programming
Object Overloading Practices
c
Output printed on paper.
softcopy
hardcopy
source code
software
b
A binary digit (1 or 0) signifying "on" or "off".
bit
byte
megabyte
gigabyte
a
Our decimal number 44, when represented in binary, is:
101100
101010
111000
10100
a
Byte code is the machine language for a hypothetical computer called the:
Java Byte Code Compiler
Java Byte Code Interpreter
Java Virtual Machine
Java Memory Machine
c
Equals 8 bits.
megabyte
gigabyte
sector
byte
d
Java allows for three forms of commenting:
// single line, ** block lines, /*/ documentation
// single line, /*...*/ block lines, /**...*/ documentation
/ single line, /* block lines, ** documentation
// single line, //...// block lines, //*...*// documentation
b
To prepare a diskette (or hard drive) to receive information.
format
track
interpret
boot
a
In Java, the name of the class must be the same as the name of the .java file.
false
true - but case sensitivity does not apply
true - but additional numbers may be added to the name
true
d
The name Java was derived from
a cup of coffee
an acronym for JBuilder Activated Variable Assembly
an acronym for Juxtapositioned Activated Variable Actions
an acronym for John's Answer for Various Accounts
a
Programs that tell a computer what to do.
harware
software
hard copy
projects
b
RAM stands for _________.
Read Anytime Memory
Read Allocated Memory
Random Access Memory
Random Allocated Memory
c
Several computers linked to a server to share programs and storage space.
library
grouping
network
integrated system
c
The four equipment functions of a computer system.
Input, Process, Control Unit, Output
Input, Control Unit, Arithmetic Logic Unit, Output
Input, Process, Storage, Output
Input, Process, Library Linking, Output
c
Translates and executes a program line by line.
compiler
interpreter
linker
control unit
b
The physical components of a computer system.
control unit
hardware
software
ALU
b

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

Program:

import java.util.*;
import java.io.*;

//Question class
class Question
{
   private String q[] = new String[6];
  
   //constructor
   public Question(Scanner sc)
   {
       for(int i=0; i<6; i++)
           q[i] = sc.nextLine();
   }
  
   //return question as a String
   public String toString()
   {
       String s = "";
       for(int i=0; i<5; i++)
           s = s + q[i] + "\n";
      
       return s;
   }
  
   //return answer
   public char getAnswer()
   {
       return q[5].charAt(0);
   }
}


//Quiz class
class Quiz
{
   //give() method to give the quiz
   public static void give(Question q[], int n)
   {
       //create instance of Scanner class
       Scanner sc = new Scanner(System.in);
      
       int count = 0, j = 0;
       int incorrect[] = new int[n];
       char incorrectAns[] = new char[n];
      
       //loop to take the quiz
       for(int i=0; i<n; i++)
       {
           System.out.print(q[i]);
           System.out.print("Answer: ");
           char ans = sc.next().charAt(0);
           if(ans==q[i].getAnswer())
               count++;
           else
           {
               incorrect[j] = i+1;
               incorrectAns[j] = q[i].getAnswer();
               j++;
           }
           System.out.println();
       }
      
       //print the report
       System.out.println("\nNumber of correct answer: " + count);
       System.out.println("Number of wrong answer: " + (n-count));
       for(int i=0; i<j; i++)
       {
           System.out.println("Question number: " + incorrect[i] + "\t" +
               " Correct answer: " + incorrectAns[i]);
       }
      
       //close the Scanner
       sc.close();
   }
  
   //main method
   public static void main (String[] args) throws IOException
   {
       //create instance of Scanner class anf open the file
       Scanner sc = new Scanner(new File("quiz.txt"));
      
       //array of questions
       Question q[] = new Question[100];
       //number of questions
       int nq = 0;
      
       //read the quiz file
       while(sc.hasNextLine())
       {
           q[nq] = new Question(sc);
           nq++;
       }
      
       give(q, nq);
      
       //close the Scanner
       sc.close();
   }
}

Output:


Formed on a diskette (or hard drive) during initialization.
source code
images
sectors
storage units
Answer: c

The CPU consists of:
Control Unit, Temporary Memory, Output
Control Unit, Arithmetic Logic Unit, Temporary Memory
Input, Process, Storage, Output
Input, Control Unit, Arithmetic Logic Unit, Output
Answer: b

OOP stands for:
Observable Object Programming
Object Observed Procedures
Object Oriented Programming
Object Overloading Practices
Answer: c

Output printed on paper.
softcopy
hardcopy
source code
software
Answer: b

A binary digit (1 or 0) signifying "on" or "off".
bit
byte
megabyte
gigabyte
Answer: c

Our decimal number 44, when represented in binary, is:
101100
101010
111000
10100
Answer: b

Byte code is the machine language for a hypothetical computer called the:
Java Byte Code Compiler
Java Byte Code Interpreter
Java Virtual Machine
Java Memory Machine
Answer: c

Equals 8 bits.
megabyte
gigabyte
sector
byte
Answer: b

Java allows for three forms of commenting:
// single line, ** block lines, /*/ documentation
// single line, /*...*/ block lines, /**...*/ documentation
/ single line, /* block lines, ** documentation
// single line, //...// block lines, //*...*// documentation
Answer: c

To prepare a diskette (or hard drive) to receive information.
format
track
interpret
boot
Answer: b

In Java, the name of the class must be the same as the name of the .java file.
false
true - but case sensitivity does not apply
true - but additional numbers may be added to the name
true
Answer: c

The name Java was derived from
a cup of coffee
an acronym for JBuilder Activated Variable Assembly
an acronym for Juxtapositioned Activated Variable Actions
an acronym for John's Answer for Various Accounts
Answer: b

Programs that tell a computer what to do.
harware
software
hard copy
projects
Answer: c

RAM stands for _________.
Read Anytime Memory
Read Allocated Memory
Random Access Memory
Random Allocated Memory
Answer: b

Several computers linked to a server to share programs and storage space.
library
grouping
network
integrated system
Answer: c

The four equipment functions of a computer system.
Input, Process, Control Unit, Output
Input, Control Unit, Arithmetic Logic Unit, Output
Input, Process, Storage, Output
Input, Process, Library Linking, Output
Answer: b

Translates and executes a program line by line.
compiler
interpreter
linker
control unit
Answer: c

The physical components of a computer system.
control unit
hardware
software
ALU
Answer: b


Number of correct answer: 7
Number of wrong answer: 11
Question number: 5 Correct answer: a
Question number: 6 Correct answer: a
Question number: 8 Correct answer: d
Question number: 9 Correct answer: b
Question number: 10 Correct answer: a
Question number: 11 Correct answer: d
Question number: 12 Correct answer: a
Question number: 13 Correct answer: b
Question number: 14 Correct answer: c
Question number: 16 Correct answer: c
Question number: 17 Correct answer: b

Add a comment
Know the answer?
Add Answer to:
*Java* Given the attached Question class and quiz text, write a driver program to input the...
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
  • Write a Java method that will take an array of integers of size n and shift...

    Write a Java method that will take an array of integers of size n and shift right by m places, where n > m. You should read your inputs from a file and write your outputs to another file. Create at least 3 test cases and report their output. I've created a program to read and write to separate files but i don't know how to store the numbers from the input file into an array and then store the...

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • FOR JAVA Write a program that takes two command line arguments: an input file and an...

    FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type...

    *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type in 50 words, one word per line, all words of the SAME catagory, max chars per word is 8. Example: 50 words of some names in the periodic table, or Flowers, or cars or.... 3) Save the file as myWordFile.txt Part 2 Write a program the reads the myWordFile.txt 1) Create an array of 'strings' called myWordArray 2) Write code that opens the file...

  • *Java* You will write a program to do the following: 1. Read an input file with...

    *Java* You will write a program to do the following: 1. Read an input file with a single line of text. Create a method named load_data. 2. Determine the frequency distribution of every symbol in the line of text. Create a method named 3. Construct the Huffman tree. 4. Create a mapping between every symbol and its corresponding Huffman code. 5. Encode the line of text using the corresponding code for every symbol. 6. Display the results on the screen....

  • What to submit: your answers to exercises 2. Write a Java program to perform the following...

    What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...

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