
Concept explainers
Explanation of Solution
Program code:
Test.java
//import the required packages
import java.io.File;
import java.util.Arrays;
import java.util.Scanner;
//define a class inputStats
public class Main
{
//define the main
public static void main(String[] args) throws Exception
{
//create the object of File class
File fileName = new File("file.txt");
//create the object of Scanner class to refer the file
Scanner in = new Scanner(fileName);
//call the method negativeSum()
negativeSum(in);
}
//define a method negativeSum()
public static boolean negativeSum(Scanner in)
{
//declare the integer variables "step" and "sum"
int step =0;
int sum = 0;
//declare a boolean variable flag
boolean flag = false;
//iterate a while loop to get the integers
while (in.hasNextInt())
{
//add the tokens to sum
sum+= in.nextInt();
//increment the step by 1
step++;
//if the value of sum is less than 0
if (sum < 0)
{
//set the value of flag as true
flag = true;
//break the condition
break;
}
}
//if the value of flag is true
if (flag)
{
//print the value of sum and step
System.out.println(sum + " after " + step + " steps");
}
//if the value of flag is false
else
{
//print the statement
System.out.println("no negative sum");
}
//return the value of flag
return flag;
}
}
Explanation:
The above snippet of code is used find the negative sum of the values in the given input file...
Want to see the full answer?
Check out a sample textbook solution
Chapter 6 Solutions
Building Java Programs: A Back To Basics Approach, Loose Leaf Edition (5th Edition)
- What resources are used when a thread is created? How do these differ from those used when a process is created?arrow_forward(c) Consider the following set of processes: Process ID Arrival Time Priority Burst Time A 2 3 100 B 6 C 10 1 (highest) 2 40 80 D 16 4 (lowest) 20arrow_forward(3e) Test-and-Set. The Test-and-Set instruction is used in hardware to achieve synchronization. It can be defined in the following way: function Test-and-Set (var target: boolean): boolean; begin Test-and-Set:= target; target := true; end; Now show how the Test-and-Set instruction can be used to protect a critical region and hence achieve mutual exclusion (do not worry about satisfying the bounded waiting condition). (8 points) repeatarrow_forward
- Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper and matches. One of the smoker processes has paper, another has tobacco and the third has the matches. The agent has an infinite supply of all three materials. The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats. Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized. Write a couple of sentences on why these initial conditions are necessary and sufficient. Solution: var a: array [0..2] of semaphore (initial condition =…arrow_forwardLevel-0 Diagram for this: A customer sends in an order form containing details of their order and their membership number. A check is made to verify that they are a member. When their order is verified, a check is made to validate that the items ordered are produced by the company. Next, the valid order is used to update the daily order file, and then used to create a shipping list and invoice, which are sent on to the Order Fulfilment System.arrow_forwardIn this assignment, you will use all of the graphics commands you have learned to create an animated scene. Your program should have a clear theme and tell a story. You may pick any school-appropriate theme that you like. The program must include a minimum of: 5 circles 5 polygons 5 line commands 2 for loops 1 global variable You may wish to use the standard code for simplegui graphics below: import simplegui def draw_handler(canvas): frame = simplegui.create_frame('Testing', 600, 600) frame.set_canvas_background("Black") frame.set_draw_handler(draw_handler) frame.start() Submit Your Code After you write your code here in the programming environment, you will check it and submit it as usual. However, the grader will only perform basic checks against some requirements. If your code passes, you should submit your work, and your teacher will manually grade your submitted work using a rubric.arrow_forward
- 1. What is the difference between a relative cell reference and an absolute cell reference and give an example of when you would use each.arrow_forwardWhat is the goal of using a chart in excel, and how is a chart useful and what is the goal of using sparklines in excel, and how are sparklines useful?arrow_forwardProve for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). Use limits to find these. For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forward
- Need this expression solved for mu. This can be done using a symbolic toolbox, however it needs to end up being mu = function (theta, m, L, g). If using MATLAB or something similar, run the code to make sure it works.arrow_forwardA business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution. will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem. mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally, must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment. CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…arrow_forwardA business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution. will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem. mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally, must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment. CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





