You are not allowed to use the Scanner class in this assignm
You are not allowed to use the Scanner class in this assignment and any assignment after this one. You will need to use InputStreamReader and BufferedReader (they are in java.io package) to process input and also take care of IOException.
New Skills to be Applied
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Recursion
One-dimensional arrays
Program Description
Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers.
Then compute the minimum number, compute the sum of odd numbers, count negative numbers, and compute the sum of numbers in the array are less than the last number entered right before 0. (You can assume that a user will enter at least one non-zero number before 0 is entered.) using recursion. Thus you will create recursive methods findMin, computeSumOfOdd, countNagative, and sumLessThanLast in Assignment9 class and they will be called by a main method.
Specifically, the following recursive methods must be implemented (These methods should not contain any loop):
public static int findMin(int[] numbers, int startIndex, int endIndex)
public static int computeSumOfOdd(int[] numbers, int startIndex, int endIndex)
public static int countNegative(int[] numbers, int startIndex, int endIndex)
public static int sumLessThanLast(int[] numbers, int startIndex, int endIndex, int lastNumber)
If these methods are implemented using a Loop or any Static Variable, points will be deducted (from the test cases) even if your program passes test cases. DO NOT use any Static Variables.
The program should output the results of those calculations to standard output. Your program will continue to read in numbers until the number 0 is entered. At this point, the calculations will be outputted in the following format:
The minimum number is 0
The sum of odd numbers is 0
The count of negative numbers is 0
The sum of numbers that are less than the last is 0
Note that the result values will be different depending on test cases (not always 0).
Do not output a prompt to query for the numbers. The number 0 is included in the sequence of numbers and should be included in all of your calculations.
Solution
import java.io.*;
import java.text.*;
public class Assignment9
{
public static void main (String args[]) throws IOException
{
int i = 0;
double[] NumArray;
NumArray = new double[100];
InputStreamReader inRead = new InputStreamReader(System.in);
BufferedReader buffRead = new BufferedReader(inRead);
String line = buffRead.readLine();
try{
while (line.equals(\"0\") == false && i<100)
{
i++;
line = buffRead.readLine();
NumArray[i]=Double.parseDouble(line);
}
}
catch(IOException e)
{
System.out.println(\"Array index out of bound\");
}
double min = findMin(NumArray, 0, NumArray.length);
double posSum = computePositiveSum(NumArray, 0, NumArray.length);
double negSum = computeSumAtOdd(NumArray, 0, NumArray.length);
int negCount = countNegative(NumArray, 0, NumArray.length);
System.out.print (\"The minimum number is \" + min + (\'\ \'));
System.out.print (\"The sum of the positive numbers is \" + posSum + (\'\ \'));
System.out.print (\"The sum of the numbers at odd indexes is \" + negSum + (\'\ \'));
System.out.print (\"The total count of negative numbers is \" + negCount);
}
public static double findMin(double[] NumArray, int startIndex, int endIndex)
{
if (startIndex == endIndex)
{
return NumArray[startIndex];
}
else if(findMin(NumArray, startIndex, endIndex - 1) < NumArray[endIndex])
{
return findMin(NumArray, startIndex, endIndex - 1);
}
else
{
return NumArray[endIndex];
}
}
public static double computePositiveSum(double[] NumArray, int startIndex, int endIndex)
{
if (startIndex == endIndex)
{
if (NumArray[startIndex] < 0)
{
return 0;
}
else
return NumArray[startIndex];
}
else if (NumArray[endIndex] > 0)
{
else if ... < NumArray[endIndex])}
else
{
return computePositiveSum(NumArray, startIndex, endIndex - 1);
}
}
public static double computeSumAtOdd(double[] NumArray, int startIndex, int endIndex)
{
if (startIndex == endIndex)
{
if (startIndex %2 == 1)
{
return NumArray[startIndex];
}
else
return 0;
}
else
{
if (endIndex %2 == 1)
{
return computeSumAtOdd(NumArray, startIndex, endIndex - 1) + NumArray[endIndex];
}
else
return computeSumAtOdd(NumArray, startIndex, endIndex - 1);
}
}
public static int countNegative(double[] NumArray, int startIndex, int endIndex)
{
if (startIndex == endIndex)
{
if (NumArray[startIndex] < 0)
{
return 1;
}
else
return 0;
}
else{
if (NumArray[startIndex] < 0)
{
return 1 + countNegative(NumArray, startIndex +1, endIndex
}
else
return countNegative(NumArray, startIndex +1, endIndex);
}
}
}




