Please help me to solve this Computer Science Assignment2.java. The 3rd-6th phot
ID: 3875180 • Letter: P
Question
Please help me to solve this Computer Science Assignment2.java. The 3rd-6th photos are Input1.txt to Input4.txt. The 7th-10th photos are Output1.txt to Output4.txt. Thank you very much!
Program Description Assignment #2 will be the construction of a program that reads in an unspecified number of integers rom standard input, per or ns some calculations on the inputted numbers and outputs the results of those calculations to standard output. The numbers could be delimited by any kind of whitespace, i.e. tabs, spaces, and lines (Note that if you use the Scanner class, you do not have to worry about these delimiters. They will be taken care of). 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 integer is 0 The largest integer that is divisible by 2 is 0 The count of even integers in the sequence is 1 The sum of positive integers is 0 This means that using all numbers your program reads (including the last number 0), you need to compute the minimum, compute the largest integer that is divisible by 2, count how many even integers are in the sequence can be divided by 2 num%2 =:0), ana compute the sum of positive integers (ne greate an Note that the above is an output for the first test case. For other test cases, you will have different numbers. Do not prompt to query for the numbers. The number 0 is included in the sequence of integers and should be included in all of your calculations Input The following files are the test cases that will be used as input for your program (Right-click and use "Save As"): Test Case #1 st Case #3 Test Case #4Explanation / Answer
Replace the public class name 'problem1' with the name of your file/public class and change the name of package from 'current' to the name of your package.
OR
Save your file as 'problem1.java' and change the name of package from 'current' to the name of your package.
package current;
import java.util.Scanner; // import package Scanner for Standard input
import java.util.ArrayList; // import package ArrayList for unspecified sized input
public class problem1 {
//program to compute the required values
public static void compute(ArrayList<Integer> arr){
int n=arr.size(); //length of the input sequence
int minimum=0; //minimum integer in the sequence initialized to 0
int largestDiv=0; //largest number in the sequence divisible by 2 initialized to 0
int even=0; //count of even integers initialized to 0
int sumPositive=0; //sum of positive integers initialized to 0
//iterate through the input sequence
for(int i=0; i<n; i++){
int num=arr.get(i); //store the ith element of the sequence in a variable 'num'
if(num<minimum){
minimum=arr.get(i); //check if ith element is smaller than minimum
}
if(num%2==0 && num>largestDiv){
largestDiv=arr.get(i); //check if ith element is divisible by 2 and largest divisor of 2 so far in the sequence
}
if(num%2==0){
even=even+1; //increment the count of even integers if ith element is even
}
if(num>=0){
sumPositive=sumPositive+num; //add ith element to sum of positive integers if it is greater than or equal to 0
}
}
//display results as standard output
System.out.println("The minimum integer is " + minimum);
System.out.println("The largest integer that is divisible by 2 is " + largestDiv);
System.out.println("The count of even integers in the sequence is " + even);
System.out.println("The sum of positive integers is " + sumPositive);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in); //initialize scanner with predefined standard input object
ArrayList<Integer> arrList=new ArrayList<Integer>(); //initialize an Array list of integer type to input a variable sized sequence of integers
// take integer inputs while the input is not 0
while(true){
int input=sc.nextInt(); //take an integer as input
//check if input is 0
if(input!=0){
arrList.add(input); //add to the list if input is not 0 and continue
}
else{
arrList.add(input); //add input to list even if it is 0
break; //break if input is 0, end of sequence is reached
}
}
//call the public static function 'compute' defined outside main to compute the required values
//pass the input sequence as argument
compute(arrList);
sc.close(); //close the scanner
}
}