/* * Testing input reading */ package t1q4; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * @author jcmtiernan */ public class T1Q4 { /** * @param args the command line arguments */ public static void main(String[] args) { //Thursday 1 October 2015 32.77 is the expected high temperature in Celcius today String dayOfWeek; String month; String message; int day; int year; double temperature; File tempDate = new File("DateTempB.txt"); Scanner input; boolean end = false; try { input = new Scanner(tempDate); end = true; } catch (FileNotFoundException fnf) { input = new Scanner(System.in); System.out.println("Please enter the following information on one line - "); System.out.println("day_of_week day_of_month month year temperature then any other info."); System.out.println("Example: \"Thursday 1 October 2015 32.77 is the expected high temperature in Celcius today\" "); System.out.println("Your input is: "); } do { dayOfWeek = input.next(); day = input.nextInt(); month = input.next(); year = input.nextInt(); temperature = input.nextDouble(); message = input.nextLine(); String moAbbrev = month.substring(0,3); System.out.println(); System.out.println("You entered "+dayOfWeek+", "+month+" ("+moAbbrev+") "+day+", "+year); System.out.println("and "+temperature+" degrees and "+message); } while((input.hasNextLine()) && end ); } }