Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have the Winter Class and need help writing the code for the main class: The winter class: public class Winter { private int[] nums;
I have the Winter Class and need help writing the code for the main class:
The winter class:
public class Winter { private int[] nums; static int Index=0; //to keep track of number of integers public Winter(int n)//constructor { nums=new int[n]; } //whenever int is added //increase Index public void add(int num) { nums[Index]=num; Index++; } public int sum() { int SUM=0; for(int I=0;IMAX)//if any elemnt higher than MAX { MAX=nums[I]; } } return MAX; } public int low() { int MIN=nums[0]; for(int I=0;I thresh) { SUM=SUM+nums[I]; Count++; } } AVG=(double)SUM/Count; return AVG; } public int count() { //return Index return Index; }
the main class: (the instructions are written as comments) but i need help getting the single integer from scanner and writing the loop.
main class:
package bw import java.util.Scanner; public class MainClars { public static void main (String[] ended { Scanner input = new Scanner(System.in); //Some notes and hints for Task 2: /* Declare and create two objects of type Winter and for the parameter to the constructor use 30... meaning each Winter object can deal with up to 30 sent to it */ /*Your code here */ /* Now get a single integer from the scanner lets refer to that int as N we will use N as an upper limit in a for loop */ /*Your code here */ // Now loop N times. /* In each loop iteration do these things: -- -- -- -- get an integer from the input scanner decide if that int is even or odd if its even, send it to the even Winter obj "add" method by calling the if that int is odd, send it to the odd Winter obj by calling its "add" method The loop ends when all N integers have been obtained from input */ // That loop has now "loaded" each of the two Winter objects // with data from input // one Winter obj is full of even in // the other Winter obj is full of odd inte /*Your code here */ /* Now do the requested output as shown in the samples and we are done. Hint: This is easier with the prints method. /*Your code here */ } static void printStats (Winter evenwinter, Winter oddWinter) { //This is a helper method you can use for Task 2. /*Hint: Pay careful attention to whether or not your inserted code prints output on the same line or a new line. */ System.out.print ("Number of evens: "); /*Your code here */ System.out.println(); System.out.print("Sum of evens: ");
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started