Assignment #125
///Name: Sam Wilson
///Period: 6
///Program Name: Summoning Three Numbers From Any File
///File Name: summonany3.java
///Date Finished: 5/31/16
import java.io.File;
import java.util.Scanner;
public class summonany3
{
public static void main (String[] args) throws Exception
{
Scanner keyboard = new Scanner(System.in);
int a, b, c, sum;
String again;
System.out.println();
do
{
System.out.print( "Which file would you like to read numbers from: " );
String answer = keyboard.next();
if ( answer.equals("3nums1.txt"))
{
Scanner fileIn = new Scanner(new File("3nums1.txt"));
System.out.println( "Retrieving information from \"3nums1.txt\" ... " );
a = fileIn.nextInt();
b = fileIn.nextInt();
c = fileIn.nextInt();
fileIn.close();
sum = a + b + c;
System.out.println( a + " + " + b + " + + " + c + " = " + sum );
}
if ( answer.equals("3nums2.txt"))
{
Scanner fileIn = new Scanner(new File("3nums2.txt"));
System.out.println( "Retrieving information from \"3nums2.txt\" ... " );
a = fileIn.nextInt();
b = fileIn.nextInt();
c = fileIn.nextInt();
fileIn.close();
sum = a + b + c;
System.out.println( a + " + " + b + " + + " + c + " = " + sum );
}
if ( answer.equals("3nums3.txt"))
{
Scanner fileIn = new Scanner(new File("3nums3.txt"));
System.out.println( "Retrieving information from \"3nums3.txt\" ... " );
a = fileIn.nextInt();
b = fileIn.nextInt();
c = fileIn.nextInt();
fileIn.close();
sum = a + b + c;
System.out.println( a + " + " + b + " + + " + c + " = " + sum );
}
System.out.println();
System.out.print( "Would you like to read numbers from another file? " );
again = keyboard.next();
} while ( again.equals("yes"));
if ( again.equals("no"))
System.out.println( "goodbye" );
}
}