using java Arrays Create a Class to practice with Arrays Cal
using java
(Arrays) Create a Class to practice with Arrays. Call your class “Convert”, and store it in a file called “Convert.java”. In this class you will create the 2 arrays of data. One array to store Fahrenheit temperatures and one to store Celsius temperatures. The first array will store the Fahrenheit temps from 0 to 500, in increments of 25. That is 0, 25, 50, 75…etc. The second array will store the equivalent celsius temp. Use a loop to fill the 2 arrays and a second loop to print out the 2 arrays in a table format. You can do all this code in main() if you want.
Solution
import java.util.*;
public class Program1
{
public static void main(String[] args)
{
// Obtain user input for the Location
Scanner input = new Scanner(System.in);
String location = input.nextLine();
System.out.println(\"Temperatures in \" + location);
// Create an array for the temperatures
System.out.println(\"Enter Temperatures in Fahrenheit\");
double temp1 = input.nextDouble();
double temp2 = input.nextDouble();
double temp3 = input.nextDouble();
double temp4 = input.nextDouble();
double temp5 = input.nextDouble();
double temp6 = input.nextDouble();
double temp7 = input.nextDouble();
double temp8 = input.nextDouble();
double temp9 = input.nextDouble();
double temp10 = input.nextDouble();
double [] tempsList;
tempsList = new double [] {temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10};
System.out.printf(\"%s\ \", \" Fahrenheit\");
{
// Print the user defined fahrenheit temperatures
for (int i = 0; i < tempsList.length; i++)
System.out.printf(\"%10.1f\ \", tempsList[i]);
}
//Method to print the user defined celsius temperatures
double celsius = convertToCelsius(tempsList);
System.out.print(\"Celsius \" + celsius);
}
public static double convertToCelsius(double[] tempsList)
{
double[] result;
result = new double [10];
for (int i = 0; i < tempsList.length; i++)
{
result = celsius;
}
}
}
