Where did you place this code?: double[] arr = Arrays.stream(aList).asDoubleStream().toArray(); Java code: import java.util.Scanner; public class Main { /*I can't find how to turn the aList[] array values into double values. Should I do this in the method definitions or main method? */ public void toFahr(int[] array){ } // how do I write a mutator method using the values from the aList[i] array? public static double toCelsius(int[] array){ double fahr; //fahrenheit value double celsius; return celsius = (fahr - 32)/1.8; } // Can I use the fahr variable from toCelsius method & apply to toKelvin method? public double toKelvin( ){ double kelv; return kelv=(fahr -32)/1.8 + 273.15; } //use selectionSort(numbers) later on in main method to call this public static void selectionSort(int [] numbers) { int i; int j; int indexSmallest; int temp; for (i = 0; i < numbers.length - 1; ++i) { // Find index of smallest remaining element indexSmallest = i; for (j = i + 1; j < numbers.length; ++j) { if (numbers[j] < numbers[indexSmallest]) { indexSmallest = j; } } // Swap numbers[i] and numbers[indexSmallest] temp = numbers[i]; numbers[i] = numbers[indexSmallest]; numbers[indexSmallest] = temp; } /* fill out the rest once I get the above public void avg() { } public void high () { } public void low() { } public void aboveAvg( ) { } public void equalAvg() { } public void belowAvg() { } public void stdDev() { } */ public static void main(String[] args) { // write your code here Scanner scnr = new Scanner(System.in); int i = 0; int j = 0; int num,numTemp; System.out.print("How many numbers do you want to enter? : "); num = scnr.nextInt(); int aList[] = new int[num]; //store array from user's input System.out.println("Please enter " + num + " integer from 1 to 35."); for(i=0;i35) { System.out.println(aList[j]+" is not correct!"); while(true) { System.out.println("Please enter within the range of 1-35 or this cycle will loop forever"); numTemp = scnr.nextInt(); if(numTemp>0 && numTemp<36) { aList[j] = numTemp; break; } } } } for(j = 0;j

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

My issue:

Where did you place this code?:

double[] arr = Arrays.stream(aList).asDoubleStream().toArray();

Java code:

import java.util.Scanner;

public class Main {

/*I can't find how to turn the aList[] array values into double values.
Should I do this in the method definitions or main method? */
public void toFahr(int[] array){

}
// how do I write a mutator method using the values from the aList[i] array?
public static double toCelsius(int[] array){
double fahr; //fahrenheit value
double celsius;
return celsius = (fahr - 32)/1.8;
}

// Can I use the fahr variable from toCelsius method & apply to toKelvin method?
public double toKelvin( ){
double kelv;
return kelv=(fahr -32)/1.8 + 273.15;
}
//use selectionSort(numbers) later on in main method to call this
public static void selectionSort(int [] numbers) {
int i;
int j;
int indexSmallest;
int temp;

for (i = 0; i < numbers.length - 1; ++i) {

// Find index of smallest remaining element
indexSmallest = i;
for (j = i + 1; j < numbers.length; ++j) {

if (numbers[j] < numbers[indexSmallest]) {
indexSmallest = j;
}
}

// Swap numbers[i] and numbers[indexSmallest]
temp = numbers[i];
numbers[i] = numbers[indexSmallest];
numbers[indexSmallest] = temp;
}

/* fill out the rest once I get the above
public void avg() {

}

public void high () {

}

public void low() {

}

public void aboveAvg( ) {

}

public void equalAvg() {

}

public void belowAvg() {

}

public void stdDev() {

}
*/

public static void main(String[] args) {
// write your code here
Scanner scnr = new Scanner(System.in);
int i = 0;
int j = 0;
int num,numTemp;

System.out.print("How many numbers do you want to enter? : ");
num = scnr.nextInt();
int aList[] = new int[num]; //store array from user's input
System.out.println("Please enter " + num + " integer from 1 to 35.");
for(i=0;i<num;i++) {
aList[i] = scnr.nextInt();
}
for(j = 0;j<num;j++) {
if(aList[j]<1 || aList[j]>35) {
System.out.println(aList[j]+" is not correct!");
while(true) {
System.out.println("Please enter within the range of 1-35 or this cycle will loop forever");
numTemp = scnr.nextInt();
if(numTemp>0 && numTemp<36) {
aList[j] = numTemp;
break;
}
}
}
}
for(j = 0;j<num;j++) {
System.out.print(aList[j]+" ");
}

}
}


Expert Answer

 
Step 1

We can convert the array of integers into double values in the main method. This helps to reduce the need of toFahr() method that was not static as well. 

Step 2

1) Here, the array is given and you need their double values in different scales. We can simply create a double variable for that scale and store that in the new array.

Also, toFahr() is not necessary to use. We can simply convert the given int array into a double array in the main program and then we can use that double array for other methods as well. The code to convert the given int array into double in the main function is as:

double[] arr = Arrays.stream(aList).asDoubleStream().toArray();

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY