
You should create an object of type Average. In a loop the user will enter a value. The tester class should then check to determine if the value is even or odd. If the data is even the tester class should call an Even method and pass the data to that method. The Even method should then add the data to a sum and update a count. The same thing should happen if the value is odd. You should also have an Odd method which does the same thing as the Even method. The data should be read in a loop and continue until the user enters the sentinel value -1. After all data has been read, the tester class should then call a method in the Average class that will calculate and return the average of the even input values and another method that will calculate and return the average of the odd input values. Be sure and not include the -1. Display the even and odd averages.

Hi Friend,
Try the following code:
import java.util.*;
public class Average{
public int evenMethod(ArrayList list){
int sum=0,count=0;
for(int i=0;i<list.size();i++){
sum+=Integer.valueOf(list.get(i).toString());
count++;
}
int avg=sum/count;
return avg;
}
public int oddMethod(ArrayList list){
int sum=0,count=0;
for(int i=0;i<list.size();i++){
sum+=Integer.valueOf(list.get(i).toString());
count++;
}
int avg=sum/count;
return avg;
}
public static void main(String[]args){
Scanner input=new Scanner(System.in);
ArrayList list1=new ArrayList();
ArrayList list2=new ArrayList();
while(input.hasNext()){
int num=input.nextInt();
if(num!=-1){
if(num%2==0){
list1.add(num);
}
else{
list2.add(num);
}
}
else{
break;
}
}
Average avg=new Average();
int avg1=avg.evenMethod(list1);
int avg2=avg.oddMethod(list2);
System.out.println("Average of Even Numbers: "+avg1);
System.out.println("Average of Odd Numbers: "+avg2);
}
}
Thanks

Hi, Thank you so much friend. But it is not working, it keeps executing.I can't figure out whats wrong, Can you? If so can you please Fix it? And this is all in one class, have to make a tester too.
Thank You so much.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.