EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 9, Problem 2PE

a.

Explanation of Solution

Program:

File name: “MeanMedian.java

//Import necessary header files

import javax.swing.*;

//Define a class named MeanMedian

class MeanMedian

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare an array of nine integers

        int[] nums = new int[9];

        //Declare the variables and initialize the values

        String entry;

        String list = "You entered: ";

        int a, b;

        int temp;

        int midPos;

        int total = 0;

        double mean;

        //For loop to be executed until a exceeds 9

        for(a = 0; a < nums.length; ++a)

        {

            //Prompt the user to enter a number

            entry = JOptionPane.showInputDialog(null,

           "Enter number " + (a + 1));

            nums[a] = Integer.parseInt(entry);

            //Compute the total

            total += nums[a];

            //If a equals zero

            if(a == 0)

                //Find the list

                list += nums[a];

            //Else a not equals zero

            else

                //Find the list

                list += ",  " + nums[a];

        }

        //Print the result

        System...

b.

Explanation of Solution

Program:

File name: “MeanMedian2.java

//Import necessary header files

import javax.swing.*;

//Define a class named MeanMedian2

class MeanMedian2

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare an array of 20 integers

        int[] nums = new int[20];

        //Declare the variables and initialize the values

        int num = 0;

        String entry;

        String list = "You entered: ";

        int a, b;

        int temp;

        double median;

        int total = 0;

        double mean = 0;

        final int QUIT = 9999;

        int size = 0;

        /*For loop to be executed until a exceeds 20 and does not enter QUIT*/

        for(a = 0; num != QUIT && a < nums.length; ++a)

        {

            //Prompt the user to enter a number or QUIT

            entry = JOptionPane.showInputDialog(null,

"Enter number " + (a + 1) + " or " + QUIT + " to quit");

            num = Integer.parseInt(entry);

            //If the user does not enter QUIT

            if(num != QUIT)

            {

                //Assign the value

                nums[a] = num;

                //Find the total

                total += nums[a];

                //If a equals zero

                if(a == 0)

                    //Find the list

                    list += nums[a];

                //Else

                else

                    //Find the list

                    list += ",  " + nums[a];

            }

        }

        //Print the result

        System.out.println("size is " + a);

        //If the user does not enter QUIT

        if(num != QUIT)

            //Find the size

            size = nums...

Blurred answer
Students have asked these similar questions
a. The mean of a list of numbers is its arithmetic average. The median of a list is its middle value when the values are placed in order. For example, if a list contains 1, 4, 7, 8, and 10, then the mean is 6 and the median is 7. Write an application that allows you to enter five integers and displays the values, their mean, and their median. Save the files as MeanMedian.java. b. Revise the MeanMedian class so that the user can enter any number of values up to 20. If the list has an even number of values, the median is the numeric average of the values in the two middle positions. Save the file as MeanMedian2.java.
For this interactive assignment, you will create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the correct answers: B  2. D    3. A     4. A     5. B      6. A      7. B       8. A      9. C     10. D      B  12. C  13. D  14. A   15. D   16. C    17. C    18. B    19. D   20. A Your program should store these correct answers in a list. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another list. (Create your own answer text file to test the application.) After the student’s answers have been read from the text file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the…
For this interactive assignment, you will create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the correct answers: B  2. D    3. A     4. A     5. B      6. A      7. B       8. A      9. C     10. D      B  12. C  13. D  14. A   15. D   16. C    17. C    18. B    19. D   20. A Your program should store these correct answers in a list. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another list. (Create your own answer text file to test the application.) After the student’s answers have been read from the text file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Graphical User Interfaces: Crash Course Computer Science #26; Author: CrashCourse;https://www.youtube.com/watch?v=XIGSJshYb90;License: Standard YouTube License, CC-BY
Python GUI | How To Make A GUI In Python | Best GUI Framework In Python | Edureka; Author: edureka!;https://www.youtube.com/watch?v=_PHJvjQJa3w;License: Standard Youtube License