Question
// (Your Name) // Lab6 // CS 1113 // This program will read in from a file a series of numbers in degree Celsius //
// (Your Name) // Lab6 // CS 1113 // This program will read in from a file a series of numbers in degree Celsius // until it reads sentinel values, convert them to degree Fahrenheit and // print out a table of those values. // The file input is handled using the command line's redirection mechanism. import java.util.Scanner; public class Lab6 { public static void main(String[] args) { // Declare variables Scanner scan = new Scanner(System.in); final double SENT = -999.99; double degreeCelsius; double degreeFahrenheit; // Read the first value from the file using defensive programming. // If the read value is not double type, display error message // and exit the program. // Otherwise store the value in degreeCelsius. // [Add code here] // Print to the screen the header of the output table // as seen in the sample run below. // There are two words, (Celsius and Fahrenheit) in the header. // use \t to generate tab space between Celsius and Fahrenheit while printing the header. [Add code here] // Write your loop here // We want to loop until there are no more input to be read. // We don't care what type of input. while( /*[Add code here]*/ ) { // Convert input degrees Celsius to degrees Fahrenheit // and store in degreeFahrenheit. // degreeFahrenheit = degreeCelsius * (9.0/5.0) + 32.0 // [Add code here] // Display to the screen the output as shown in the // sample run below. Use System.out.println. Make sure // that everything lines up properly. System.out.println( /* [Add code here */ ); // Read next value from the file. // Check to see if the input is a double. // If a double read in and store in degreeCelsius. // If not a double print an error message and quit. // [Add code here] } // End of loop } // End of main method } // End class 2) Type in or copy the following set of temperature data (of degrees Celsius) to a text file called "Lab6.txt". 5.5 15.2 25.4 35.8 45.1 55.9 65.3 75.7 85.6 95.0 -999.99 Note: If you want to display the output with certain digits after the decimal, then you can use decimal format. You can consult Lab6 to see how to use decimal format. 3) Then, compile and run the program from the command line using following command: javac Lab6.java java Lab6 < Lab6.txt 4) A Sample run with the given input can be seen below. Celsius Fahrenheit 5.50 41.90 15.20 59.36 25.40 77.72 35.80 96.44 45.10 113.18 55.90 132.62 65.30 149.54 75.70 168.26 85.60 186.08 95.00 203.00 5) You can output the result to a file Lab6_out.txt by issuing the following command: java Lab6 < Lab6.txt > Lab6_out.txt You should not see any output on the command line, but the file "Lab6_out.txt" should have been created with the output that was formerly on the command line. please use java(NetbeanIDE)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started