import java.util.*; import java.io.*; public class Inputenator { private Scanner console; private Scanner fin; private int [] nums; private int offset, max, answer; Inputenator(String a) { console = new Scanner(System.in); fin = new Scanner(new File(a)); System.out.println("How many elements do you want in the array?"); max = console.nextInt(); console.nextLine(); nums = new int[max]; } private void menu() { System.out.println("Press 1 to read a number from the keyboard"); System.out.println("Press 2 to read a number from the file"); System.out.println("Once the array is full you can sum the numbers!"); } public void theMenu() { int choice = 0; do{ menu(); switch(choice) { case 1: keyboardInput(); break; case 2: fileInput(); break; } }while(choice != -1 || offset < max); calculate(); } public void keyboardInput() { System.out.println("Give the number to input:"); int a = console.nextInt(); console.next(); nums[offset] = a; offset++; } public void fileInput() { int a = fin.nextInt(); System.out.println("The next number put in the array is: " + a); nums[offset] = a; offset++; } public void calculate() { for(int i = 0; i