Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- class Averaging {
- private static Scanner scanner = new Scanner(System.in);
- private static int pin = 0000;
- private static ArrayList<Integer> integer = new ArrayList<Integer>();
- private static int totalSum = 0;
- private static int entries = 0;
- public static void main(String[] args) {
- System.out.print("Welcome to the Averaging Program.");
- System.out.print("To verify you made this program, please enter a 4-digit pin: ");
- int passcode = scanner.nextInt();
- verify(passcode);
- }
- private static void verify(int pass) {
- if(pass == pin) {
- System.out.printf("Password accepted.\n\nI will be asking you to input values\n");
- loopInsert();
- }
- }
- private static void loopInsert() {
- for(int i = 0; i <= 25 ; i++) {
- System.out.print("Please insert a number, or to stop, type !stop.");
- String next = scanner.next();
- if(next == "!stop") {
- System.out.print("Good. I am currently calculating right now..");
- calculate();
- } else {
- integer.add(Integer.parseInt(next));
- }
- }
- }
- private static void calculate() {
- Iterator<Integer> iter = integer.iterator();
- while(iter.hasNext()) {
- entries++;
- totalSum += iter.next();
- }
- if(!iter.hasNext()) {
- int average = (totalSum/entries);
- System.out.printf("Your average is: " + average + ". I will show you what you have input.\n");
- System.out.print(integer.toString());
- System.out.print("To start a new session, please reboot me.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement