Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.util.Scanner;
  2. /**
  3. * LoopsExercise1: A class in which the first exercise may be completed by students
  4. * Course: ADEV-1003
  5. * Section: Section_number
  6. * Date Created: May 1, 2017
  7. * Last Updated: May 1, 2017
  8. */
  9. public class LoopsExercise1
  10. {
  11. public static void main(String[] args)
  12. {
  13. int counter = 0;
  14. String answer;
  15. double price;
  16. int quantity;
  17. String item;
  18. double cost = 0;
  19. do
  20. {
  21. Scanner k = new Scanner(System.in);
  22.  
  23. System.out.print("Enter the grocery item description: ");
  24.  
  25. item = k.nextLine();
  26.  
  27.  
  28. System.out.printf("Enter the quantity of %s(s) being purchased: ", item);
  29. quantity = Integer.parseInt(k.nextLine());
  30.  
  31. System.out.printf("Enter the price of %s: ", item);
  32. price = Double.parseDouble(k.nextLine());
  33.  
  34. System.out.print("Would you like to enter another item? (Y/N): ");
  35. answer = k.nextLine();
  36.  
  37. counter = counter + quantity;
  38. cost = cost + price;
  39.  
  40. }while(answer.equalsIgnoreCase("y"));
  41. System.out.println("GROCERY TOTAL");
  42. System.out.println("=============");
  43. System.out.printf("Total items purchased: %d%n", counter);
  44. System.out.printf("Total cost: $%.2f", cost);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement