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...
Trending nowThis is a popular solution!
- 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…arrow_forwardThe 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 an ordered list contains 1, 2, 3, 4, 5, 6, 10, 11, and 12, then the mean is 6, and their median is 5. Write an application that allows you to enter nine integers and displays the values, their mean, and their median.arrow_forwardYou have a list of student ID’s followed by the course number (separated by a space) that the student is enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list might look like this:1 CS1002 MATH2102 CS1051 CS200Write a program that reads data in this format from the console. If the ID is −1 then stop inputting data. Use the HashMap class to map from an Integer (the student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this:HashMap<Integer, ArrayList<String>> students =new HashMap<Integer, ArrayList<String>>();After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student ID.arrow_forward
- *python coding Driver’s License ExamThe local driver’s license office has asked you to create an application that grades the written portion of thedriver’s license exam. The exam has 20 multiple-choice questions. Hereare the correct answers:1. B 6. A 11. B 16. C2. D 7. B 12. C 17. C3. A 8. A 13. D 18. B4. A 9. C 14. A 19. D5. C 10. D 15. D 20. AYour program should store these correct answers in a list. The program should read thestudent’s answers for each of the 20 questions from a text file and store the answers inanother list. (Create your own text file to test the application.) After the student’s answershave been read from the file, the program should display a message indicating whether thestudent passed or failed the exam. (A student must correctly answer 15 of the 20 questionsto 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 question numbers of the incorrectly…arrow_forwardThis is a Python program Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space:ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist contains the information for one employee.The birthDate and hireDate in file are strings, but should be stored as objects of type Date.Example of EmpRoster list with 2 employees:[ [111,”Joe”, “Jones”, “09-01-1980”,”10-19-1999”, 95000], \ [222, “Sam”, “Smith”, “07-10-1956”,, “01-01-2000”, 50000] ] Print a report that shows the following: Employee RosterID First Name Last Name Birth Date Age Hire Date YrsWorked Salary WRITE the following information out to a text file – ask the…arrow_forwardThis question comes from the textbook:Starting out with Visual C# 5th Edition - Chapter 14 Programming Problem 2 Create an application that reads the contents of two text files and uses LINQ extension methods to perform the following: • It should display a list of all the unique words contained in both files.• It should display a list of the words that appear in both files.• It should display a list of the words that appear in the first file but not the second.• It should display a list of the words that appear in the second file but not the first.• It should display a list of the words that appear in either the first or second file but not both. Hint: Use set operations to perform these analyses. Also, see Chapter 8 for a discussion of string tokenizing.arrow_forward
- Choose all of the options that apply. In which of the following cases is it more efficient to use a vector rather than a list? O A program that frequently accesses elements throughout the container O A program that needs to add a large number of elements to the container's beginning O A program that adds a fixed number of elements and then removes the first element repeatedly O A program that frequently adds elements, but only to the container's endarrow_forwardGiven the "Document" class below, you will write a basic version of Google Drive. Your program will store two lists of documents, one for documents the user has created and one for created documents the user has shared with a friend. The user will have a few options which you will need to implement (note: the menu will only be displayed once at the beginning of the program): Add a document to the user's list: Allow the user to enter the document name, document extension, and document contents and then add that Document to the list of documents Rename one of the user's documents Allow the user to enter the index of the document in their list they want to rename Allow the user to enter the updated name of that document Set the name of the document to be the updated name they enter Share one of the user's documents with a friend Allow the user to enter the index of their document they want to share with their friend Display all the documents in both the user's and the friend's…arrow_forwardHello. I'm having some trouble with a visual basic program. I'm reading a text file and outputting to a list box, but my output isn't coming out correctly. Can you help me figure out the issue? Code: Public Class Form1Structure Members Public Id As StringPublic LastName As StringPublic FirstName As StringPublic MiddleIntial As StringPublic Grade As StringPublic ClassString As String End StructurePrivate Member(250) As Members Dim Students As StringDim Record As StringDim newLineIndex As IntegerDim newIndex As IntegerDim commaIndex As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim file As New IO.FileInfo("StudentList.txt")ListBox.Items.Clear()If file.Exists() Then LoadList() ElseMessageBox.Show("File not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)End If End Sub Private Sub LoadList()Dim Id(10) As MembersDim Index As Integer = 0Students = My.Computer.FileSystem.ReadAllText("StudentList.txt") For…arrow_forward
- The python function first_words takes one parameter, fname, the name of a text file, and returns a list containing the first word from each line of the file. For example, if the file contents are: apples are red bananas are yellow limes are green then the list ["apples", "bananas", "limes"] should be returned.NOTE: You may assume the file will contain no blank lines.BIG HINT: If line is a string representing a line of text (inside of a for loop!), then L = line.split() creates a list of the words in the line.arrow_forwardIf you have downloaded the source code from this book’s companion Web site, you will find a file named USPopulation.txt in the Chapter 07 folder. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth.Write a program that reads the file’s contents into a list. The program should display the following data:• The average annual change in population during the time period• The year with the greatest increase in population during the time period• The year with the smallest increase in population during the time period(You can access the book’s companion Web site at www.pearsonglobaleditions.com/gaddis.)arrow_forwardwrite a c++ code uisng linked list for quiz. In quiz game, questions are chosen in such a a way that they cover all fields of a typical quiz contest. The user’s general knowledge is tested with quiz questions regarding science, technology, movies, sports, general health, geography and many more. • Edit score• Help-- menu • Show record• Show score• Reset score The game ends when the user’s cash prize piles up to 100RS. For each question there are 4 options A, B, C and D and no negative markings. so money would not be deducted for wrong answersto the questions.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT