For my program, I'm trying to use data from a file that will take the numbers(which stand for Celsius) and use them to calculate standard deviation/convert to Fahrenheit. I've already created the methods for the calculation but I'm not sure what is the right way of outputting the information from those methods to the user when I run the code.
I've tried:
sDeviation(celsius);
double fDeviation = sDeviation(celsius);
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ProceduralReview { public static void main(String[] args) { //making the arrays int[] year = new int[165]; double[] celsius = new double[165]; File file = new File("tempsLA.txt"); Scanner input = null; try { input = new Scanner(file); }//end try catch (FileNotFoundException e) { //In case file isn't found System.out.println("File not found."); e.printStackTrace(); System.exit(0); }//end catch int index = 0; while(input.hasNextLine()) { year[index] = input.nextInt(); celsius[index] = input.nextDouble(); index++; }//end while //Print table System.out.println("Year\tCelsius"); printTable(year,celsius); System.out.println(""); //Print Final Table System.out.println("Showing all of the years where the temp is at least 1 standard deviation of the mean:" + "\n"); System.out.println("Year \t Celsius\tFahrenheit"); }//end main private static void printTable(int[] year, double[] celsius) { //for loop for(int i = 0; i < year.length; i++) { System.out.println(year[i] + "\t" + celsius[i]); } }//end printTable //Celsius to Fahrenheit conversion public static double cfahrenheit(double celsius) { double fahrenheit = (celsius*1.8)+32; return fahrenheit; } //Deviation formula public static double sDeviation (double celsius) { double mean = celsius/165; double subtractSquared = Math.pow(celsius - mean, 2); double deviation = Math.sqrt((1/165)*subtractSquared); return deviation; } }//end class
Input File:
1849 8.819 1850 7.087 1851 7.549 1852 8.236 1853 8.159 1854 7.849 1855 7.836 1856 7.994 1857 8.437 1858 9.045 1859 8.03 1860 7.709 1861 7.809 1862 8.897 1863 8.384 1864 9.535 1865 8.959 1866 8.428 1867 9.338 1868 8.063 1869 9.362 1870 9.384 1871 8.815 1872 8.818 1873 10.568 1874 8.311 1875 8.375 1876 7.728 1877 9.938 1878 9.284 1879 7.396 1880 7.606 1881 8.618 1882 6.33 1883 7.263 1884 8.336 1885 8.756 1886 9.057 1887 9.055 1888 6.222 1889 8.008 1890 6.042 1891 8.851 1892 9.398 1893 9.818 1894 6.605 1895 7.968 1896 10.485 1897 8.826 1898 6.652 1899 9.593 1900 10.292 1901 9.339 1902 8.793 1903 9.664 1904 9.047 1905 10.932 1906 9.567 1907 7.686 1908 9.791 1909 9.737 1910 7.654 1911 9.742 1912 9.767 1913 7.178 1914 9.549 1915 8.715 1916 6.825 1917 6.502 1918 8.821 1919 9.998 1920 9.648 1921 8.14 1922 6.756 1923 9.389 1924 8.914 1925 9.199 1926 9.309 1927 9.242 1928 10.072 1929 7.568 1930 8.516 1931 9.858 1932 6.38 1933 6.98 1934 10.589 1935 8.869 1936 10.372 1937 4.016 1938 10.532 1939 9.064 1940 10.396 1941 10.018 1942 9.78 1943 9.631 1944 9.051 1945 8.913 1946 9.076 1947 8.066 1948 10.912 1949 4.463 1950 6.463 1951 8.987 1952 7.125 1953 11.592 1954 8.716 1955 6.942 1956 9.755 1957 7.027 1958 10.225 1959 10.934 1960 7.533 1961 10.846 1962 9.274 1963 8.111 1964 8.293 1965 9.838 1966 7.919 1967 9.493 1968 8.795 1969 9.637 1970 9.581 1971 8.99 1972 7.915 1973 7.562 1974 8.081 1975 9.223 1976 10.462 1977 8.989 1978 9.901 1979 7.271 1980 10.684 1981 10.788 1982 7.891 1983 10.333 1984 10.851 1985 8.371 1986 12.113 1987 7.957 1988 8.97 1989 8.158 1990 9.464 1991 9.281 1992 9.292 1993 8.568 1994 10.553 1995 9.119 1996 10.328 1997 9.437 1998 9.699 1999 10.527 2000 10.772 2001 8.398 2002 9.022 2003 13.492 2004 9.588 2005 9.87 2006 9.846 2007 8.391 2008 8.196 2009 11.882 2010 10.09 2011 10.432 2012 11.581 2013 8.813
Output:
Year Celsius 1849 8.819 1850 7.087 1851 7.549 1852 8.236 1853 8.159 1854 7.849 1855 7.836 1856 7.994 1857 8.437 1858 9.045 1859 8.03 1860 7.709 1861 7.809 1862 8.897 1863 8.384 1864 9.535 1865 8.959 1866 8.428 1867 9.338 1868 8.063 1869 9.362 1870 9.384 1871 8.815 1872 8.818 1873 10.568 1874 8.311 1875 8.375 1876 7.728 1877 9.938 1878 9.284 1879 7.396 1880 7.606 1881 8.618 1882 6.33 1883 7.263 1884 8.336 1885 8.756 1886 9.057 1887 9.055 1888 6.222 1889 8.008 1890 6.042 1891 8.851 1892 9.398 1893 9.818 1894 6.605 1895 7.968 1896 10.485 1897 8.826 1898 6.652 1899 9.593 1900 10.292 1901 9.339 1902 8.793 1903 9.664 1904 9.047 1905 10.932 1906 9.567 1907 7.686 1908 9.791 1909 9.737 1910 7.654 1911 9.742 1912 9.767 1913 7.178 1914 9.549 1915 8.715 1916 6.825 1917 6.502 1918 8.821 1919 9.998 1920 9.648 1921 8.14 1922 6.756 1923 9.389 1924 8.914 1925 9.199 1926 9.309 1927 9.242 1928 10.072 1929 7.568 1930 8.516 1931 9.858 1932 6.38 1933 6.98 1934 10.589 1935 8.869 1936 10.372 1937 4.016 1938 10.532 1939 9.064 1940 10.396 1941 10.018 1942 9.78 1943 9.631 1944 9.051 1945 8.913 1946 9.076 1947 8.066 1948 10.912 1949 4.463 1950 6.463 1951 8.987 1952 7.125 1953 11.592 1954 8.716 1955 6.942 1956 9.755 1957 7.027 1958 10.225 1959 10.934 1960 7.533 1961 10.846 1962 9.274 1963 8.111 1964 8.293 1965 9.838 1966 7.919 1967 9.493 1968 8.795 1969 9.637 1970 9.581 1971 8.99 1972 7.915 1973 7.562 1974 8.081 1975 9.223 1976 10.462 1977 8.989 1978 9.901 1979 7.271 1980 10.684 1981 10.788 1982 7.891 1983 10.333 1984 10.851 1985 8.371 1986 12.113 1987 7.957 1988 8.97 1989 8.158 1990 9.464 1991 9.281 1992 9.292 1993 8.568 1994 10.553 1995 9.119 1996 10.328 1997 9.437 1998 9.699 1999 10.527 2000 10.772 2001 8.398 2002 9.022 2003 13.492 2004 9.588 2005 9.87 2006 9.846 2007 8.391 2008 8.196 2009 11.882 2010 10.09 2011 10.432 2012 11.581 2013 8.813 Showing all of the years where the temp is at least 1 standard deviation of the mean: Year Celsius Fahrenheit
Desired Output:
(Here I'd like to have it output the Fahrenheit as well which would come from the Fahrenheit method)
Showing all of the years where the temp is at least 1 standard deviation of the mean: 8.904157575757573 Year Celsius Fahrenheit 1849 8.819 50.0 1850 7.087 50.0 1851 7.549 50.0 1852 8.236 50.0 1853 8.159 50.0 1854 7.849 50.0 1855 7.836 50.0 1856 7.994 50.0 1857 8.437 50.0 1858 9.045 50.0 1859 8.03 50.0 1860 7.709 50.0 1861 7.809 50.0 1862 8.897 50.0 1863 8.384 50.0 1864 9.535 50.0 1865 8.959 50.0 1866 8.428 50.0 1867 9.338 50.0 1868 8.063 50.0 1869 9.362 50.0 1870 9.384 50.0 1871 8.815 50.0 1872 8.818 50.0 1873 10.568 51.022 1874 8.311 50.0 1875 8.375 50.0 1876 7.728 50.0 1877 9.938 50.0 1878 9.284 50.0 1879 7.396 50.0 1880 7.606 50.0 1881 8.618 50.0 1882 6.33 50.0 1883 7.263 50.0 1884 8.336 50.0 1885 8.756 50.0 1886 9.057 50.0 1887 9.055 50.0 1888 6.222 50.0 1889 8.008 50.0 1890 6.042 50.0 1891 8.851 50.0 1892 9.398 50.0 1893 9.818 50.0 1894 6.605 50.0 1895 7.968 50.0 1896 10.485 50.0 1897 8.826 50.0 1898 6.652 50.0 1899 9.593 50.0 1900 10.292 50.0 1901 9.339 50.0 1902 8.793 50.0 1903 9.664 50.0 1904 9.047 50.0 1905 10.932 50.0 1906 9.567 50.0 1907 7.686 50.0 1908 9.791 50.0 1909 9.737 50.0 1910 7.654 50.0 1911 9.742 50.0 1912 9.767 50.0 1913 7.178 50.0 1914 9.549 50.0 1915 8.715 50.0 1916 6.825 50.0 1917 6.502 50.0 1918 8.821 50.0 1919 9.998 50.0 1920 9.648 50.0 1921 8.14 50.0 1922 6.756 50.0 1923 9.389 50.0 1924 8.914 50.0 1925 9.199 50.0 1926 9.309 50.0 1927 9.242 50.0 1928 10.072 50.0 1929 7.568 50.0 1930 8.516 50.0 1931 9.858 50.0 1932 6.38 50.0 1933 6.98 50.0 1934 10.589 50.0 1935 8.869 50.0 1936 10.372 50.0 1937 4.016 50.0 1938 10.532 50.0 1939 9.064 50.0 1940 10.396 50.0 1941 10.018 50.0 1942 9.78 50.0 1943 9.631 50.0 1944 9.051 50.0 1945 8.913 50.0 1946 9.076 50.0 1947 8.066 50.0 1948 10.912 50.0 1949 4.463 50.0 1950 6.463 50.0 1951 8.987 50.0 1952 7.125 50.0 1953 11.592 50.0 1954 8.716 50.0 1955 6.942 50.0 1956 9.755 50.0 1957 7.027 50.0 1958 10.225 50.0 1959 10.934 50.0 1960 7.533 50.0 1961 10.846 50.0 1962 9.274 50.0 1963 8.111 50.0 1964 8.293 50.0 1965 9.838 50.0 1966 7.919 50.0 1967 9.493 50.0 1968 8.795 50.0 1969 9.637 50.0 1970 9.581 50.0 1971 8.99 50.0 1972 7.915 50.0 1973 7.562 50.0 1974 8.081 50.0 1975 9.223 50.0 1976 10.462 50.0 1977 8.989 50.0 1978 9.901 50.0 1979 7.271 50.0 1980 10.684 50.0 1981 10.788 50.0 1982 7.891 50.0 1983 10.333 50.0 1984 10.851 50.0 1985 8.371 50.0 1986 12.113 50.0 1987 7.957 50.0 1988 8.97 50.0 1989 8.158 50.0 1990 9.464 50.0 1991 9.281 50.0 1992 9.292 50.0 1993 8.568 50.0 1994 10.553 50.0 1995 9.119 50.0 1996 10.328 50.0 1997 9.437 50.0 1998 9.699 50.0 1999 10.527 50.0 2000 10.772 50.0 2001 8.398 50.0 2002 9.022 50.0 2003 13.492 50.0 2004 9.588 50.0 2005 9.87 50.0 2006 9.846 50.0 2007 8.391 50.0 2008 8.196 50.0 2009 11.882 50.0 2010 10.09 50.0 2011 10.432 50.0 2012 11.581 50.0 2013 8.813 50.0
Here is where the value for Fahrenheit is computed:
//Celsius to Fahrenheit conversion public static double cfahrenheit(double celsius) { double fahrenheit = (celsius*1.8)+32; return fahrenheit; }
Here is where the lines should be printing out on the report:
//Print table System.out.println("Year\tCelsius"); printTable(year,celsius); System.out.println(""); //Print Final Table System.out.println("Showing all of the years where the temp is at least 1 standard deviation of the mean:" + "\n"); for(int i = 1; i < year.length; i++) { } System.out.println("Year \t Celsius\tFahrenheit"); }//end main