Concept explainers
Explanation of Solution
Purpose of given code:
Purpose of given code is to display the count value, maximum value, minimum value, sum value, and average value of integer array “numbers”.
Given code:
//Variable definition
int[] numbers = {1, 4, 2, 3, 1};
/*Error #1*/
DoubleSummaryStatistics stats = DoubleStream.of(numbers).summaryStatistics();
/*Print statement with aggregate functions*/
/*Error #2*/
System.out.printf("The summary of the stream is\n%-10s%10d\n" +"%-10s%10.2f\n%-10s%10.2f\n%-10s%10.2f\n%-10s%10.2f\n"," Count:", stats.getCount(), " Max:", stats.getMax()," Min:", stats.getMin(), " Sum:", stats.getSum()," Average:", stats.getAverage());
Error #1:
The values of variable “numbers” are in “int” array. The above program uses “DoubleSummaryStatistics” instead of “IntSummaryStatistics”.
Error #2:
The resultant minimum, maximum, and sum value is integer...
Want to see the full answer?
Check out a sample textbook solutionChapter 30 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- This code gets an error for going out of range in the last for loop. What can I do to fix this? # Lucas Conklin# 5772707import csvimport statistics def readCSVIntoDictionary(f_name): data = [] with open(f_name) as f: reader = csv.reader(f) for row in reader: if not data: for index in range(len(row)): data.append([]) for index in range(len(row)): data[index].append(float(row[index])) f.close() return data features = readCSVIntoDictionary("C:\\Users\\lucas\\Downloads\\pima.csv")print(features) def find_median_and_SD(data, feature): med = statistics.median(data[feature]) rounded_med = round(med, 4) st_dev = statistics.stdev(data[feature]) rounded_st_dev = round(st_dev, 5) return rounded_med, rounded_st_dev for i in range(0, len(features)): (median, st_dev) = find_median_and_SD(features, i) print(f'Feature {i} Median: {median} Standard Deviation: {st_dev}')…arrow_forwardWrite a program that reads a text file and creates an alphabetical index of words and in which lines of this original example. The file name is given as an argument to main (). Ignore the small-capital (all lowercase: k,l,p) and punctuation. Solve with ternary tree using the TST.java class (https://algs4.cs.princeton.edu/52trie/TST.java.html). An execution snapshot is then given. For the file: It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness It will appear Index of file: exercise.txt age 3-4 best 1 foolishness 4 it 1-2-3-4 of 1-2-3-4 the 1-2-3-4 times 1-2 was 1-2-3-4 wisdom 3 worst 2arrow_forwardYou will also have to write Student Tests that test the following in the provided file.i. Adding element(s).ii. Get elements at index – (1) with a valid index and (2) with an invalid indexiii. Test equality of two StringArrayLists (of size 0, 2)iv. Test if a StringArrayList contains a String (test both true and false cases)v.Test removing a String from a StringArrayList.arrow_forward
- I made this code and it works but I get one error, it doesn't give the exact output I need. I get too much spaces, how can I Fix this error: AssertionError: '14 10 12 \n13 11 12 \n10 10 16 \n' != '14 10 12\n13 11 12\n10 10 16\n' class Matrix:def __init__(self, rows):self.list1 = rowsdef __str__(self):res = ""for i in range(len(self.list1)):for j in range(len(self.list1[i])):res = res + "{:2d}".format(self.list1[i][j]) + " "res = res + "\n"return resdef scale(self, w):nl = []for i in range(len(self.list1)):nl.append([])for j in range(len(self.list1[i])):nl[i].append(self.list1[i][j] * w)return Matrix(nl)def transpose(self):nl = [[None for j in range(len(self.list1[i]))] for i in range(len(self.list1))]for i in range(len(self.list1)):for j in range(len(self.list1[i])):nl[j][i] = self.list1[i][j]return Matrix(nl)def multiply(self, b):nl = [[0 for j in range(len(self.list1[i]))] for i in range(len(self.list1))]if len(self.list1[0]) == len(b.list1):for i in range(len(self.list1)):for j…arrow_forwardGiven a Dart stream that produces an unending series of strings that can be either Courses or Subjects: final CoursesStream = takenCourses().stream; // drop courses, enroll courses, drop courses, enroll courses ... Transform the stream so it returns the string Offering Courses only for the first five instances of courses.arrow_forwardThis is a short exercise in using the stream API. Suppose that the class Score is defined as class ScoreInfo { String firstName; String lastName; int score; ScoreInfo( String lName, String fName, int s ) { firstName = fName; lastName = lName; score = s; } } and that scoreData is an array of ScoreInfos containing information about the scores of students on a test. Use the stream API to do each of the following tasks: print the number of students (without using scoreData.length) print the average score for all of the students print the number of students who got an A (score greater than or equal to 90) use the collect() stream operation to create a List<String> that contains the names of students whose score was less than 70; the names should be in the form first name followed by last name print the names from the List that was generated in the previous task print out the student's names and scores, ordered last name print out the…arrow_forward
- Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 import java.util.Scanner; public class CourseGradePrinter {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int NUM_VALS = 4;int [] courseGrades = new int[NUM_VALS];int i; for (i = 0; i < courseGrades.length; ++i) {courseGrades[i] = scnr.nextInt();} /* Your solution goes here */ P.S. The answer came out wrong the first try 7 9 11 10 10 11 9 7Enterarrow_forwardThe following code does not compile. Why not? What is upsetting the compiler? int a = 10; int b = 20; int sum = IntStream.of(1, 2, 3, 4, 5) .map(n -> n + b - (++a)) .sum();arrow_forwardWrite a client that generates arrays of items of varioustypes with random key values, including the following:■ String key (at least ten characters), one double value■ double key, ten String values (all at least ten characters)■ int key, one int[20] valueDevelop and test hypotheses about the effect of such input on the performance of thealgorithms in this section.arrow_forward
- I've attached the question. Below, you will find my python code answer. It doesn't output correctly, as you can see in the image with errors. Code: class Node: def __init__(self, data): self.data = data self.next = None self.prev = None # Empty Doubly Linked Listclass DoublyLinkedList: def __init__(self): self.head = None def append(self, new_data): if self.head == None: self.head = new_data self.tail = new_data else: self.tail.next = new_data new_data.prev = self.tail self.tail = new_data def printList(self): if(self.head == None): print('Empty!') else: node = self.head while(node is not None): print(node.data), node = node.next def remove(self, current_node): successor_node = current_node.next predecessor_node = current_node.prev if successor_node is not None:…arrow_forwardPlease help me code in java: Write a program that reads two files “Data1.txt”, “Data2.txt”; adding their corresponding elements produces an output file “output.txt”. If the number of elements are not equal, fill the elements of the smaller file up with “0” s. Sample output: Elements of the “Data1.txt”: 3 5 7 8 9 Elements of the “Data2.txt”: 45 11 Elements of the “Output.txt”: 48 16 7 8arrow_forwardI am making a program with a CSV file with three columns: names, cities, and heights. In each city, I found the average height. I need to find the two people closest to the average. Most of the time, it works, but there is an error. A person second closest to the average doesn't even appear on the list. Also, the value for their height is way too high. What changes do I need to make? import csvdata = []with open("C:\\Users\\lucas\\Downloads\\sample-data.csv") as f: reader = csv.reader(f) for row in csv.reader(f): data.append(list(row)) f.close()data.pop(0) city_list = []for i in range(len(data)): city_list.append(data[i][1])city_list.sort()unique_cities = []people_count = []for city in city_list: # this if statement analyzes which cities are in unique_cities. If they are not in the list, # then they will be appended into the list if city not in unique_cities: unique_cities.append(city)for city in unique_cities: count = city_list.count(city)…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning