Problem to solve: 1) You must create an array to hold your (double) temperature values. 2) Display all floating-point (double) numbers to one decimal place. 3) Each static method should only handle one primary task My issues: 1) I can't find how to turn the int[] array (i.e., aList[]) into a double value. Should I do this in the method definitions or main method? 2) in the method definitions, how do I write a mutator method using the values from the aList[i] array? 3) Can I use the fahr variable from toCelsius method & apply to toKelvin method? 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
Problem to solve:
1) You must create an array to hold your (double) temperature values.
2) Display all floating-point (double) numbers to one decimal place.
3)
Each static method should only handle one primary task
My issues:
1) I can't find how to turn the int[] array (i.e., aList[]) into a double value. Should I do this in the method definitions or main method?
2) in the method definitions, how do I write a mutator method using the values from the aList[i] array?
3) Can I use the fahr variable from toCelsius method & apply to toKelvin method?
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]+" ");
}
}
}
Step by step
Solved in 2 steps with 1 images