Question: So i have answered it but it has errors, if anyone knows what im missing please lmk This is the Question: For the first task,

So i have answered it but it has errors, if anyone knows what im missing please lmk

This is the Question:

For the first task, we're going to fill out a simple program by adding suitable methods to complete the functionality. The code will be spread over two classes, but some of the basics have already been provided.

The program consists of two classes, NumberSequence and Runner. The program starts by reading some simple numerical data (integers) in from a file (this part is provided) and storing this inside an array in an object of type NumberSequence. From this starting point, your task is to add methods and code to NumberSequence and Runner so that the program prints out the following (in this order, each on a separate line):

"There are nn numbers." where nn is the number of numbers in the sequence.

"The maximum is xx." where xx is the greatest number in the sequence.

"The minimum is yy." where yy is the least number in the sequence.

"The mean is aa." where aa is the arithmetic mean (what we normally call the average). Note that the mean may not be an integer (use double for decimals in this case).

One of the following three:

"The sequence is increasing." if each number is strictly larger than the previous.

"The sequence is decreasing." if each number is strictly smaller than the previous.

"The sequence is wobbly or short." if it has less than two numbers or neither of the other two apply.

You are given some example test data, but you should not assume that all test data will follow this exact pattern (but you are guaranteed there is at least one number, and all numbers are integers).

You should not alter any of the existing code given in the scaffold, just add to it. You may need to add code to both classes.

===========

This was my answer:

NumberSequence.java

import java.util.List; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.io.FileNotFoundException; import java.util.stream.Collectors;

public class NumberSequence {

/** * The following section of code does not need to * be modified. The section to complete is indicated * below. **/

// The array the data will be stored in private final int[] sequence;

// The constructor for the class public NumberSequence(String filename) { this.sequence = NumberSequence.readFile(filename); }

// A helper method to read the data in from the file. // See the example file for the format if you want to // write your own tests. private static int[] readFile(String filename) {

try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {

List rawData = reader.lines().collect(Collectors.toList()); int[] sequence = new int[rawData.size()];

for (int i = 0; i

return sequence; } catch (FileNotFoundException e) { System.err.println("There is no file with the name: " + filename); System.err.println(e.getMessage()); } catch (IOException e) { System.err.println("Something went wrong reading data from the the file " + filename + "."); System.err.println(e.getMessage()); } return null; }

/** * Write your code below here. **/ // Print Stats About Numbers public void analyze() { // Print The Count Of Numbers System.out.printf("There are %d numbers. ", sequence.length);

// Find Min, Max, Total int total = 0; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE;

for (int i = 0; i

// Update Max if (sequence[i] > max) { max = sequence[i]; }

// Update Min if (sequence[i]

// Print Min, Max, Average System.out.printf("The maximum is %d. ", max); System.out.printf("The minimum is %d. ", min); System.out.printf("The mean is %.1f. ", ((double)total / sequence.length));

// Find If The Sequence is Incresing, Decreasing Or Wobbly/Short if (sequence.length

for (int i = 1; i

if (sequence[i - 1] > sequence[i]) { countDecreasing++; } }

// Print Result if (countIncreasing == sequence.length - 1) { System.out.println("The sequence is increasing."); } else if (countDecreasing == sequence.length - 1) { System.out.println("The sequence is decreasing."); } else { System.out.println("The sequence is wobbly or short."); } } } }

=========

Runner.java

public class Runner { public static void main(String[] args) { NumberSequence numbers = new NumberSequence(args[0]); numbers.analyze(); } } ==============

This is the error showing up: Does anyone know what i need to fix?

So i have answered it but it has errors, if anyone knows

Description Dexample.data NumberSequence.j... A. Runner.java

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!