Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package lab7exercise4;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. *Scanner scan = new Scanner(System.in);
  7. * @author huanmingan
  8. */
  9. public class Lab7exercise4 {
  10.  
  11. static final int NUMBER_OF_CHECKOUTS = 6, MAX_TAKING = 1000000;
  12.  
  13. public static void main(String[] args)
  14. {
  15. double[] checkoutList = new double[NUMBER_OF_CHECKOUTS];
  16. inputTakings(checkoutList);
  17. outputTotal(checkoutList);
  18. }
  19.  
  20. private static void inputTakings(double[] checkoutList)
  21. {
  22. Scanner scan = new Scanner(System.in);
  23. for (int index = 0; index < checkoutList.length; index++)
  24. {
  25. System.out.print("\tEnter takings for checkout number ");
  26. System.out.print((index + 1) + ": ");
  27. checkoutList[index] = scan.nextDouble();
  28. while (checkoutList[index] < 0 || checkoutList[index] > MAX_TAKING)
  29. {
  30. System.out.print("\tImpossible! - enter takings for checkout number ");
  31. System.out.print((index + 1) + " again: ");
  32. checkoutList[index] = scan.nextDouble();
  33. }
  34. } //To change body of generated methods, choose Tools | Templates.
  35. }
  36.  
  37. private static void outputTotal(double[] checkoutList)
  38. {
  39. System.out.println();
  40. int sum=0;
  41.  
  42. for (double i : checkoutList)
  43. sum+=i;
  44. System.out.println("\t The total takings for the supermarket is: " + sum);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement