Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 2E
Program Plan Intro
1. The following variables are used in the
- num array of integer data type of size 10 is used to store the user-entered numbers.
- max variable of integer data type is used to store the maximum value of the array.
- min variable of integer data type is used to store the minimum value of the array.
- total variable of integer data type is used to store the sum of all the elements of the array.
- avg variable of double data types is used to store the average of all the elements in the array.
2. The following methods are used in the program:
- fill() method to read numbers from console and assign to the array.
- display() method to calculate the statistics and display the statistics of the array.
Program Description:
In this program, user-entered number are assigned to the array and its statistics are displayed to the user.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create a program whose Main() method declares an array of 10 integers. Call a method to interactively fill the array with any number of values up to 10 or until a sentinel value is entered. If an entry is not an integer, re-prompt the user. Call a second method that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and arithmetic average. In the Main() method, display all the statistics.
Create a program whose Main() method declares an array of 10 integers. Call a method to interactively fill the array with any number of values up to 10 or until a sentinel value is entered. If an entry is not an integer, re-prompt the user. Call a second method that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and arithmetic average. In the Main() method, display all the statistics.Java Program
Define an array to be a 121 array if all elements are either 1 or 2 and it begins with one or more 1s followed by a one or more 2s and then ends with the same number of 1s that it begins with. Write a method named is121Array that returns 1 if its array argument is a 121 array, otherwise, it returns 0.
There is one additional requirement. You should return 0 as soon as it is known that the array is not a 121 array; continuing to analyze the array would be a waste of CPU cycles.
If you are programming in Java or C#, the function signature isint is121Array(int[ ] a)
If you are programming in C or C++, the function signature isint is121Array(int a[ ], int len) where len is the number of elements in the array a.
Examples
a is
then function returns
reason
{1, 2, 1}
1
because the same number of 1s are at the beginning and end of the array and there is at least one 2 in between them.
{1, 1, 2, 2, 2, 1, 1}
1
because the same number of 1s are at the beginning and end of…
Chapter 8 Solutions
Microsoft Visual C#
Knowledge Booster
Similar questions
- Create a program whose Main() method declares an array of 10 integers. Call a method to interactively fill the array with any number of values up to 10 or until a sentinel value is entered. If an entry is not an integer, re-prompt the user. Call a second method that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and arithmetic average. In the Main() method, display all the statistics.C# Programarrow_forwardWrite a program called Range_array.java that has a method with one integer array and two integers position1 and position2 as parameters, where 0<=position1<=position2<=a.length-1. The method should construct and return an array that is identical to the given array, but with the values in position1 through position2 deleted. The output should look exactly like what is pictured below please. The code must be editable, and all variables defined within please.arrow_forwardWrite a complete Java program named FindAverage that contains the following: A main method asks the user to provide the number of rows and columns for a 2-dimensional array of integers. A main method calls the getArray() method that creates the 2D array of specified size and populates it with random values from 0 to 100. A main method prints the elements of the 2D array created by getArray(). A main method calls the printAverage method that will: i. Receive the two-dimensional array as input ii. Calculate the average of elements in this array iii. Display the average on the Console. The average of all elements should be formatted as xxx.xx.arrow_forward
- In ArrayUtility class, create a public static method equals that receives two arrays of int's and returns true if they have the same length and equal corresponding elements. In ArrayUtilityTest class, create a public static method equalsTest that prints the results for the following 6 cases: two empty arrays, one empty and one singleton, two singleton with the same element, two singleton with different elements, two arrays with two identical elements, two arrays with two different elements. Call only this class in the main method and check the results. In ArrayUtility and ArrayUtilityTest, design, implement and test a method named isSorted that checks if an array of int-s is already sorted, i.e. all the elements are in increasing order. In ArrayUtility and ArrayUtilityTest, design, implement and test a method named generateIntArray that generates a random array with the provided length having elements randomly generated between a minimum and maximum value, including those values create…arrow_forwardin Java Develop a method called normalizeGrades() in Java following the details below: The method should accept an array of numeric grades as argument. Each grade in the array is a numeric value (of type double) between 0 to 100. The method should create an integer array of grades, following: If a grade in the array is greater than 50, then the method should round the numeric grade to the nearest integer value using Math.round() method, and then again round it to an integer grade to a nearest multiple of 5. If a grade in the array is less than or equal to 50, then the method should round the numeric grade to the nearest integer value using Math.round() method. The method should create a character array of letter grades, using a switch statement by translating the integer grades created in (b) to an array of letter grades of type character, following the grade notation: 100 or 95 or 90 85: A 70, 75, 80: B 55, 60, 65: C…arrow_forwardWrite a program that does the following Declare and create an array named numbers that will hold 6 doublesManually fill the array by assigning values to each indexDeclare an integer array numbers2 that creates and assigns values to indexes in one statementWrite two loops that print each arrayNow, instead of having to write two separate loops that print the arrays create a method and an overloaded method printArray that does the followingAccepts a single parameter of an arrayUses a loop to print the array Sample Output: 23.93 9.4 14.02 1.0 33.333 19.91 47 64 5 100 8 92arrow_forward
- This is the question I am stuck on - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Now, write a program that declares an array of five Purchase objects and prompt a user for their values. As each Purchase object is created, continuously prompt until the user enters an invoice number between 1000 and 8000 inclusive and a non-negative sale amount. Prompt the user for values for each object and then display all the values. This is the code that I am unsure where to fully start - public class Purchase { private int invoiceNumber; private double saleAmount; private double tax; private static final double RATE = 0.05; public void setInvoiceNumber(int num) { invoiceNumber = num; } public void setSaleAmount(double amt) { saleAmount = amt; tax = saleAmount * RATE; } public double getSaleAmount() { return…arrow_forwardWrite a Java program to generate random integer values between 5 and 20 to fill a single dimensional integer array of size 10. Pass the array to a method named computeArray that returns an array. In this method, if a number is odd then multiply it by 5 and if it is even then divide it 3 and place them in another array. Display the two arrays and their total by invoking a method named displayArray. Here is a sample run of this program (with an array of 4 elements): The generated array 12 17 4 20 The output X Y 12 4 17 85 4 1 20 6 ___ ___ Total=53 96arrow_forwardA teacher has three exam grades for all the members of her class, and she worries that the grades are too low. You need to complete the method, named testAverage, in the class named Grades.java. There are two parameters to this method: the first is an integer representing the number of students in the class and, the second is a two-dimensional array of integers. In other words, each row represents the three grades for one student, while the columns represent the three sets of test grades. The return value should be the number of students with an average exam grade below seventy. The grades should be treated as double variables. For example, consider the grades for the four students in the following 2-D array, [88, 84, 89] [76, 64, 67] [85, 76, 79] [95, 90, 91] The first student has an exam average of 87.0 (= (88+84+89)/3 = 261/3), the second student has an exam average of 69.0 (= (77+64+67)/3 = 207/3), the third student has an exam average of 80.0 (= (85+76+79)/3 = 240/3), while the…arrow_forward
- A teacher has three exam grades for all the members of her class, and she worries that the grades are too low. You need to complete the method, named testAverage, in the class named Grades.java. There are two parameters to this method: the first is an integer representing the number of students in the class and, the second is a two-dimensional array of integers. In other words, each row represents the three grades for one student, while the columns represent the three sets of test grades. The return value should be the number of students with an average exam grade below seventy. The grades should be treated as double variables. For example, consider the grades for the four students in the following 2-D array, [ [88, 84, 89] [76, 64, 67] [85, 76, 79] [95, 90, 91] ] The first student has an exam average of 87.0 (= (88+84+89)/3 = 261/3), the second student has an exam average of 69.0 (= (77+64+67)/3 = 207/3), the third student has an exam average of 80.0 (= (85+76+79)/3 = 240/3), while…arrow_forwardJAVA PROGRAM Write a program that asks the user to input two integers a and b. Then create an array that has all integer from a to b. Print out the array. (Don’t forget to consider the situation of a=b, a<b, and a>b.) Example 1: Input two numbers: 6 2 Array is [6, 5, 4, 3, 2] Example 2: Input two numbers: 4 8 Array is [4, 5, 6, 7, 8] Pass the above array as a parameter to a method called average and return the average and print it out in the main method. (Do not use Math library to get the average.)arrow_forwardWrite a class ArrayClass, where the main method asks the user to enter the four numbers. Create a method printArray that prints the array whenever required (use Array.toString method). Make the program run as shown in the Sample Run below. Use Array.sort, Arrach.bianrySearch, Array.equals Sample RunList1, Enter four numbers: 2 3 3 2List2, Enter four numbers: 6 2 5 4List3, Enter four numbers: 5 2 4 6Your original List1: [2, 3, 3, 2]Your original List2: [6, 2, 5, 4]Your original List3: [5, 2, 4, 6]Sorted List1 is: [2, 2, 3, 3]Enter a number from the sorted List1 to search for: 3Value 3 is in index 2 (or position 3)List that are the same when sorted: [2, 4, 5, 6arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage