/* 9/25/2019 * (1) for loop * used variable for both lower limit and upper limit * used a different update than i++ * printed a table with headings * (2) introduce output files * Must put the following 2 things: * (a) import the java.io pkg * (b) put "throws IOException" * for output files, use class PrintWriter * NOTE: if the file exists, it is destroyed every time you run your prgm */ import java.util.Scanner; import java.io.*; public class Celcius3 { /** main reads in BOTH the lower limit and upper limit * and prints a table of all numbers from lower limit to upper limit * in both celcius and faranheit. Messages about hot/cold are also * printed. */ public static void main(String[] args) throws IOException { int celciusLow, celciusHi; Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter("MyIOFiles\\tempTable.txt"); // notice the parallel between the syntax of creating a Scanner object // to creating a PrintWriter object System.out.println("Enter starting number of degrees celcius: "); celciusLow = sc.nextInt(); System.out.println("Enter starting number of degrees celcius: "); celciusHi = sc.nextInt(); System.out.println("Celcius Faranheit Message"); pw.println("Celcius Faranheit Message"); for (int i=celciusLow; i<=celciusHi; i+=5) { double faran = 9/5.0 * i + 32; System.out.printf("%4d %8.1f ",i,faran); pw.printf("%4d %8.1f ",i,faran); if (faran >= 80) { System.out.print("It is HOT!"); pw.print("It is HOT!"); } boolean isCold = faran <= 32; if (isCold) { System.out.print("It is cold."); pw.print("It is cold."); } System.out.println(); pw.println(); } // end for loop sc.close(); pw.close(); } }