USE THE PROGRAM CODE BELOW TO CODE 1. COMMAND LINE ARGS CODE IN JAVA 1.  Command Line Args    Modify problem # 1 from Lab 8 to accept the values for the key as command line arguments. Your program may assume the arguments given at the command line are integers. If there are no arguments, print a message. If there is at least one argument, compute and print the average of the arguments.    Note that you will need to use the parseInt method of the Integer class to extract integer values from the strings that are passed in. If any non-integer values are passed in, your program will produce an error, which is unavoidable at this point.   Test your program in NetBeans using the data for problem # 1 Lab 8 as command line arguments. import java.util.Scanner; import java.text.NumberFormat; public class Quizzes {     //----------------------------------------------     // Read in the number of questions followed by      // the key, then read in each student's answers     // and calculate the number and percent correct.     //----------------------------------------------      public static void main(String[] args)     {     int numQuestions;     int numCorrect;     String anotherQuiz;     int answer;     NumberFormat percent = NumberFormat.getPercentInstance();     Scanner scan = new Scanner (System.in);     System.out.println ("Quiz Grading");     System.out.println ();          System.out.println("Enter the number of questions on the quiz: ");     numQuestions = scan.nextInt();          //CREATE THE ARRAY FOR THE KEY     int[] key = new int[numQuestions];        System.out.println("Enter the answer key: ");     //LOAD THE ARRAY FOR THE ANSWER KEY WITH INPUT FROM THE USER     for (int i = 0; i < numQuestions; i++)      {         key[i] = scan.nextInt();     }         //OUTER LOOP TO ALLOW THE USER TO ENTER GRADES      // FOR ANY NUMBER OF QUIZZES     do     {             //INNER LOOP TO GET ANSWERS FROM THE USER AND COUNT THE NUMBER OF         // CORRECT ANSWERS         System.out.println("Enter the student answers: ");         numCorrect = 0;         for (int i = 0; i < numQuestions; i++)          {             answer = scan.nextInt();             if (answer == key[i])              {                 numCorrect++;             }                       }                //DISPLAY THE NUMBER OF CORRECT ANSWERS AND PERCENT         System.out.println("Number of correct answers: " + numCorrect +                " | Percent: " + percent.format((double)numCorrect/numQuestions));         System.out.println();                  //ASK USER IF THEY WISH TO GRADE ANOTHER QUIZ         System.out.println("Grade another quiz? (y/n): ");         anotherQuiz = scan.next();         if (anotherQuiz.equalsIgnoreCase("y"))          {                      }         else         {             System.out.println("Good-bye");             break;         }          } while (true);              } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

USE THE PROGRAM CODE BELOW TO CODE 1. COMMAND LINE ARGS

CODE IN JAVA

1.  Command Line Args 

 

Modify problem # 1 from Lab 8 to accept the values for the key as command line arguments.

Your program may assume the arguments given at the command line are integers. If there are no

arguments, print a message. If there is at least one argument, compute and print the average of the arguments. 

 

Note that you will need to use the parseInt method of the Integer class to extract integer values from the strings that are passed in. If any non-integer values are passed in, your program will produce an error, which is unavoidable at this point.

 

Test your program in NetBeans using the data for problem # 1 Lab 8 as command line arguments.

import java.util.Scanner;
import java.text.NumberFormat;

public class Quizzes
{
    //----------------------------------------------
    // Read in the number of questions followed by 
    // the key, then read in each student's answers
    // and calculate the number and percent correct.
    //----------------------------------------------
  
  public static void main(String[] args)
    {
    int numQuestions;
    int numCorrect;
    String anotherQuiz;
    int answer;
    NumberFormat percent = NumberFormat.getPercentInstance();
    Scanner scan = new Scanner (System.in);

    System.out.println ("Quiz Grading");
    System.out.println ();
    
    System.out.println("Enter the number of questions on the quiz: ");
    numQuestions = scan.nextInt();
    
    //CREATE THE ARRAY FOR THE KEY
    int[] key = new int[numQuestions];
  
    System.out.println("Enter the answer key: ");

    //LOAD THE ARRAY FOR THE ANSWER KEY WITH INPUT FROM THE USER
    for (int i = 0; i < numQuestions; i++) 
    {
        key[i] = scan.nextInt();
    }
   
    //OUTER LOOP TO ALLOW THE USER TO ENTER GRADES 
    // FOR ANY NUMBER OF QUIZZES
    do
    {
   
        //INNER LOOP TO GET ANSWERS FROM THE USER AND COUNT THE NUMBER OF
        // CORRECT ANSWERS
        System.out.println("Enter the student answers: ");
        numCorrect = 0;
        for (int i = 0; i < numQuestions; i++) 
        {
            answer = scan.nextInt();
            if (answer == key[i]) 
            {
                numCorrect++;
            }
             
        }
      

        //DISPLAY THE NUMBER OF CORRECT ANSWERS AND PERCENT
        System.out.println("Number of correct answers: " + numCorrect +
               " | Percent: " + percent.format((double)numCorrect/numQuestions));
        System.out.println();
        
        //ASK USER IF THEY WISH TO GRADE ANOTHER QUIZ
        System.out.println("Grade another quiz? (y/n): ");
        anotherQuiz = scan.next();
        if (anotherQuiz.equalsIgnoreCase("y")) 
        {
            
        }
        else
        {
            System.out.println("Good-bye");
            break;
        }
    
    } while (true);
        
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY