Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab7exercise4;
- import java.util.Scanner;
- /**
- *Scanner scan = new Scanner(System.in);
- * @author huanmingan
- */
- public class Lab7exercise4 {
- static final int NUMBER_OF_CHECKOUTS = 6, MAX_TAKING = 1000000;
- public static void main(String[] args)
- {
- double[] checkoutList = new double[NUMBER_OF_CHECKOUTS];
- inputTakings(checkoutList);
- outputTotal(checkoutList);
- }
- private static void inputTakings(double[] checkoutList)
- {
- Scanner scan = new Scanner(System.in);
- for (int index = 0; index < checkoutList.length; index++)
- {
- System.out.print("\tEnter takings for checkout number ");
- System.out.print((index + 1) + ": ");
- checkoutList[index] = scan.nextDouble();
- while (checkoutList[index] < 0 || checkoutList[index] > MAX_TAKING)
- {
- System.out.print("\tImpossible! - enter takings for checkout number ");
- System.out.print((index + 1) + " again: ");
- checkoutList[index] = scan.nextDouble();
- }
- } //To change body of generated methods, choose Tools | Templates.
- }
- private static void outputTotal(double[] checkoutList)
- {
- System.out.println();
- int sum=0;
- for (double i : checkoutList)
- sum+=i;
- System.out.println("\t The total takings for the supermarket is: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement