Write a method named negativeSum that accepts a Scanner as a parameter reading input from a file containing a series of integers, and determine whether the sum starting from the first number is ever negative. The method should print a message indicating whether a negative sum is possible and should return true if a negative sum can be reached and false if not. For example, if the file contains the following text, your method will consider the sum of just one number (38), the sum of the first two numbers (38 + 4), the sum of the first three numbers (38 + 4 + 19), and so on up to the sum of all of the numbers: 38 4 19 -27 -15 -3 4 19 38 None of these sums is negative, so the method would produce the following message and return false: no negative sum If the file instead contains the following numbers, the method finds that a negative sum of -8 is reached after adding 6 numbers together (14 + 7 + -10 + 9 + -18 + -10): 14 7 -10 9 -18 -10 17 42 98 It should output the following and return true, indicating that a negative sum can be reached: -8 after 6 steps

Question

This is using Java. I will apprecitte detalied comments, so I understand better the exercise/code.  

Write a method named negativeSum that accepts a Scanner as a parameter reading input from a file containing a series of integers,
and determine whether the sum starting from the first number is ever negative. The method should print a message indicating whether
a negative sum is possible and should return true if a negative sum can be reached and false if not. For example, if the file contains
the following text, your method will consider the sum of just one number (38), the sum of the first two numbers (38 + 4), the sum of the
first three numbers (38 + 4 + 19), and so on up to the sum of all of the numbers:
38 4 19 -27 -15 -3 4 19 38
None of these sums is negative, so the method would produce the following message and return false:
no negative sum
If the file instead contains the following numbers, the method finds that a negative sum of -8 is reached after adding 6 numbers
together (14 + 7 + -10 + 9 + -18 + -10):
14 7 -10 9 -18 -10 17 42 98
It should output the following and return true, indicating that a negative sum can be reached:
-8 after 6 steps
Expand
Transcribed Image Text

Write a method named negativeSum that accepts a Scanner as a parameter reading input from a file containing a series of integers, and determine whether the sum starting from the first number is ever negative. The method should print a message indicating whether a negative sum is possible and should return true if a negative sum can be reached and false if not. For example, if the file contains the following text, your method will consider the sum of just one number (38), the sum of the first two numbers (38 + 4), the sum of the first three numbers (38 + 4 + 19), and so on up to the sum of all of the numbers: 38 4 19 -27 -15 -3 4 19 38 None of these sums is negative, so the method would produce the following message and return false: no negative sum If the file instead contains the following numbers, the method finds that a negative sum of -8 is reached after adding 6 numbers together (14 + 7 + -10 + 9 + -18 + -10): 14 7 -10 9 -18 -10 17 42 98 It should output the following and return true, indicating that a negative sum can be reached: -8 after 6 steps

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: What does it mean when a Label control’s AutoSize property is set to True?

A: “Label” controls “AutoSize” property: The “AutoSize” property is used to determine whether a label c...

Q: Write down the steps how insertion sort for sorting the following elements in an array in a C++ prog...

A: Algorithm:   Step 1 − If the item is the first one, it is already sorted. Step 2 – Shift to the next...

Q: Answer question using C++ programming language. 1. Construct a circular queue of size 7 containing 4...

A: #include<iostream> using namespace std;    class Queue {     public:    // Initialize front an...

Q: Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your p...

A: Program code: #include <iostream> #include <sstream> #include <string.h> using nam...

Q: clearly distinguish between data and information within the context of computer-based information sy...

A: Distinguish between data and information : Data refers to as "raw or facts" that act as input for t...

Q: Write the application JFrameDisableButton that instantiates a JFrame that contains a JButton. Modify...

A: The below-given java program will obey the following rubrics: Importing necessary data package. Def...

Q: Question 8 Which method is used to set the graphics current color to the specified color in the grap...

A: Answer : setColor(Color c).   Explanation : setColor() is one of the methods in Graphics class in Ja...

Q: North Hills College has decided to implement a new registration system that will allow students to r...

A: JAD session: JAD stands for the production of collaborative applications. It is the session conducte...

Q: Suppose a two-dimensional array of doublewords has three logical rows and four logicalcolumns. If ES...

A: ESI is sometimes uses as a pointer , it's a non-volatile general purpose register. Strictly speaking...

Q: Consider the grammar S - uSbS | bSas | € a) Show that this grammar is ambiguous by constructing two ...

A: Click to see the answer

Q: The four types of IT system maintenance also apply to other industries. Suppose you were in charge o...

A: The four types of system maintenance are as follows: Corrective Maintenance: Corrective maintenance...

Q: What are the required steps to change every "john" into "John" in an opened ?MS Word document

A: To replace a word in Microsoft Word, there is an option to find and replace the text. The text can b...

Q: For each of the following pairs of expressions, give instances of relations thatshow the expressions...

A: Equivalence relation An equivalence relation on a set S is defined as a relation on S which holds ...

Q: Name the family of methods in the .NET Framework that can be used to convert a string to any of the ...

A: Parsing Method: The parsing operation transforms the string representing the class of the. NET base ...

Q: I know the concept of function and programming well so no need to explain all that. I want to know i...

A: Yes, you call a function inside another function in c++.   Example 1:   #include <iostream>usi...

Q: Write a python program that generates a sequence of 20 random values between 0 and 99, stores them i...

A: Declare a variable, n, and initialize to 0.      n = 0   Declare a list, num.     num = []      

Q: Q3: Define a relation prereq depth(course id, prereq id, depth) where the attribute depth indicates ...

A: The CTE name is given as 'prereq depth' with attributes prereq id, course id, and depth, where depth...

Q: Write a program that reads the integers between1 and 50 and counts the occurrences of each. Assume t...

A: Program code: //import the required packages import java.util.Scanner; //Define a class Int_occur p...

Q: Big data applications and techniques allow network operators to make use of large quantities of netw...

A: Improving network performance and needs for customer service The company looks at data related to t...

Q: Write a function that determines who has won a game of tic-tac-toe. The function should receive a ch...

A: Program approach: Including header files. Declaring and defining the int checkWinner(char arr[3][3]...

Q: What is stale data?

A: It is a caching artefact where an item in the cache is not the latest version committed to the data ...

Q: The __________ displays a form on the screen, and it gives that form the focus. a. Show method b. Sh...

A: Opens a window and will only return when the newly opened window is locked. The method ShowDialog sh...

Q: Explain why Microsoft Access is much better in managing data compared to Microsoft Excel?

A: Solution : Microsoft access and Microsoft excel are one of the most powerful tool of microsoft .The...

Q: Chandu and chandni Talk on phone for a long time daily. Being afraid that someone will hear their pr...

A: Program structure Import necessary classes from the util and io package in the program. Create the ...

Q: The __________ operator takes a Boolean expression as its operand and reverses its logical value. a....

A: Operator for taking a Boolean expression A logical NOT operator is used to implement logical negati...

Q: True or False A statement that tries to use the new operator to instantiate an abstract class will n...

A: Purpose of Abstract class: Abstract class is a class which acts as a base class for derived class ...

Q: Write a program that repeatedly prompts the user to entera capital for a state. Upon receiving the u...

A: Program Planning Assume that 10 states and their capitals are stored in a two-dimensional array. Yo...

Q: I want urgent solution to the problem, no need to attach explanation I want direct code.

A: Code: <!DOCTYPE html><html><head>   <title>Registration Form</title>  ...

Q: Declare a char variable named letter and assign the letter 'A' to the variable.

A: char letter = ‘A’;

Q: Assume that a database has a table named Stock, with the following columns:Column Name              ...

A: SQL SELECT statement is used to select data from a database. The data returned is then stored in a r...

Q: Write two functions using the following headers:int generate01()void printMatrix(int n)The first fun...

A: Since here no programming language is specified. So, we are providing the program code in C++. The b...

Q: Consider the grammar S - uSbs | bSas | € a) Show that this grammar is ambiguous by constructing two ...

A: Given: A CFG(context-free) grammar Objective: We need to find the leftmost derivations, rightmost de...

Q: The in-order and pre-order traversals of a binary tree is given as CBEDFHGAJI and HBCDEFAGIJ respect...

A: You have given in-order and pre-order traversals of binary tree like ' CBEDFHGAJI ' and ' HBCDEFAGIJ...

Q: C++: Describe how the following call by reference works. Make a comment for each line.   void pxc(in...

A: Call by Reference: Original value is changed in call by reference, since we transfer reference (addr...

Q: Which class in the .NET Framework provides predefined named constants that are assigned the mathemat...

A: .NET Architecture, which is used to perform complex and advanced mathematical calculations, defines ...

Q: Write a method thatcomputes future investment value at a given interest rate for a specified numbero...

A: Programming instructions: Import necessary header files. Create a class. Create required variables....

Q: 1. Construct a circular queue of size 7 containing 4 elements (10, 4, 12, 20).  Draw the structure o...

A: The first-in-first-out data structure Queue has two fundamental attributes -  1. Rear: where the el...

Q: Array, Array list,  Linked list, Stack, Queue, Binary Table, Hash table Please analyze the learned d...

A: analyze of data structures:- 1. array - Array is a linear data structure which stores item in a cont...

Q: Write a function that will merge the contents of two sorted (ascending order) arrays of type integer...

A: Programming Approach: Declaring a necessary header file. Declaring a function merge. Declaring a fu...

Q: . Do research online to learn about some of the other factors that have impeded Internet access for ...

A: Although network infrastructure has improved a lot in most of the regions of Africa and other part o...

Q: Raghu and Sayan both like to eat (a lot) but since they are also looking after their health, they ca...

A: Program structure Import required packages in the program. Create the Main class  Create static In...

Q: Your data warehousing project group is debating whether to prototype a data warehouse before its imp...

A: Recommendations on data warehousing projects Data warehouse is used to collect data that are used ...

Q: write a system has two entities, Student and Course. The student has the following properties: stude...

A: #include<stdio.h>     #include<iostream>  #include<fstream>  #include<string.h&...