Question: Use the template to implement this function import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; import static org.junit.Assert.*; public class Q2 { // Return all sums that

Use the template to implement this functionUse the template to implement this function import java.io.BufferedReader; import java.io.FileReader; import

import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList;

import static org.junit.Assert.*;

public class Q2 {

// Return all sums that can be formed from subsets of elements in arr public static ArrayList allSums( ArrayList arr ) { return null; } public static void main(String[] args) { //https://www.baeldung.com/java-file-to-arraylist ArrayList result = new ArrayList();//= Files.readAllLines(Paths.get("nums.txt")); try { BufferedReader br = new BufferedReader(new FileReader("nums.txt")); while (br.ready()) { result.add(Integer.getInteger(br.readLine())); } } catch (Exception e) { System.out.println(e.getMessage()); } ArrayList sums = allSums(result); System.out.println("Testing..."); assertEquals(sums.size(), 8); assertEquals(sums.contains(0), true); assertEquals(sums.contains(1), true); assertEquals(sums.contains(2), true); assertEquals(sums.contains(4), true); assertEquals(sums.contains(3), true); assertEquals(sums.contains(5), true); assertEquals(sums.contains(6), true); assertEquals(sums.contains(7), true); System.out.println("Success!"); } }

Implement a function that reads numbers in from a file with one number per line and outputs all the possible sums that can be formed by subsets of the numbers. For instance, if the numbers in the file are 124, then the output would be 0, 1, 2,4,3,5,6,7. Note that is in the output because it uses none of the numbers, while 7 is the sum of all of the numbers. // Return all sums that can be formed from subsets of elements in arr public static ArrayList allsums( ArrayList arr) {...} Implement a function that reads numbers in from a file with one number per line and outputs all the possible sums that can be formed by subsets of the numbers. For instance, if the numbers in the file are 124, then the output would be 0, 1, 2,4,3,5,6,7. Note that is in the output because it uses none of the numbers, while 7 is the sum of all of the numbers. // Return all sums that can be formed from subsets of elements in arr public static ArrayList allsums( ArrayList arr) {...}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!