Question
Hello, I am working on a computer science lab with many parts, however I am stuck on the 80 point part.... Here are instructions to
Hello, I am working on a computer science lab with many parts, however I am stuck on the 80 point part.... Here are instructions to the lab:
For each lab version, you MUST have a runner class called Runner and a class called ArrayLab. The method signatures shown below represent methods in the ArrayLab class.
***I have already done the 70 point part of the lab, but I need help with the 80 point part of the lab.
70 Point Lab
Ask the user how many numbers will be read in from the keyboard.
Use a loop and a Scanner class method to read int values from the keyboard and then put these values into an array.
Use the how many numbers value to end the loop.
If 3, 2, 5 and 5 were the numbers entered in that order, your code would print the following:
The numbers entered were: [3, 2, 5, 5] note: the Arrays class has a method that will format the list this way for you.
The minimum number in the list is 2. public static int minInList(int[] list) must be used and located in the ArrayLab class.
The maximum number in the list is 5. public static int maxInList(int[] list) must be used and located in the ArrayLab class.
The average of the values in the list is 3.75. public static double avgOfList(int[] list) must be used and located in the ArrayLab class.
80 Point Lab
Includes the requirements from the 70 Point Lab plus:
The value 6 was not in the list. public int valueInList(int[] list, int value) must be used and located in the ArrayLab class.
The value 5 is in spot 3 in the list. public int valueInList(int[] list, int value) must be used and located in the ArrayLab class.
Yes, both of these use the same method that returns an int value.
Here is my program so far:
import java.util.Scanner;
public class Runner {
public static void main (String args[]) {
Scanner input = new Scanner (System.in);
System.out.print("Enter how many numbers : " );
int size = input.nextInt();
int arr [] = new int [size] ;
System.out.println("Enter values : ");
for (int i=0; i
arr [i] =input.nextInt () ;
}
ArrayLab arrlab = new ArrayLab ();
System.out.println("The numbers entered were : " +arrlab.printList(arr)) ;
System.out.println("The minimum number in the list is " +arrlab.minInList(arr));
System.out.println("The maximum number in the list is " +arrlab.maxInList(arr));
System.out.println("The average of the values in the list is " +arrlab.avgOfList(arr));
input.close();
}
}
public class ArrayLab {
public static String printList(int[] list){
String res= "[" ;
for(int i=0; i
res+=list[i];
res+= ',' ;
}
res= res.substring(0, res.length()-1) + "]";
return res;
}
public static int minInList (int[] list)
{
int min=list[0];
for(int i=0; i
if(min>list[i])
min=list[i];
}
return min;
}
public static int maxInList(int[] list)
{
int max= list[0];
for(int i=0; i
if(max
max=list[i];
}
return max;
}
public static double avgOfList (int [] list) {
double sum=0;
for(int i=0; i
sum+=list[i];
return sum/list.length;
}
}
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