Tutorial 2 Lecturer: Craig MacDonald Tutorial: Mon@10:10am 970922 ========== CSC 108, Fall 1997 Tutorial notes, T2 ========================================================================== Tutorial Notes from Instructor Craig MacDonald: Encourage questions and ask them questions. Cover as much as you can without rushing. Continue with system introduction: How to create a data file using an editor, how to run an application. How to change your password using Terence's suggestion Cntrl-Alt-Del creating a pop-up menu with "the change of password" option. How to use the "Print Java Assignment" class to redirect from input files to output files. Discuss Text Questions 2.6 2.11 2.13 2.16 Introduce line oriented IO using this approach. /* Program to convert a number Fahr to Celsius*/ import java.io.*; class FahrToCelsius { public static void main (String[] args) { double num; // defines the type of num DataInputStream stdin = new DataInputStream(System.in); System.out.println ("Please enter temperature in Fahrenheit."); try { String line = stdin.readLine(); // the Double constructor takes a String object this instance of class // then invokes the doubleValue method which returns double double fahrenheit = new Double(line).doubleValue(); double celsius = (fahrenheit-32)*5/9.; System.out.println (fahrenheit + " fahrenheit is " + celsius + " celsius"); } catch (IOException e) { System.out.println ("Input error: " + e); } } } /* Please enter temperature in Fahrenheit. 212 212.0 fahrenheit is 100.0 celsius */ If you have time extend this program further by changing the prompt and adding if ("F".equals(line)) [convert F to C]; else [convert C to F]; to convert either way depending on another input line containing F or C. Keep it simple. Introduce enough html to create an embedded applet, add a title to this if you like. Discuss tags in HTML, and tag attributes and the location of MyCode.class in the same directory as this html document. Craig