Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * LoopsExercise1: A class in which the first exercise may be completed by students
- * Course: ADEV-1003
- * Section: Section_number
- * Date Created: May 1, 2017
- * Last Updated: May 1, 2017
- */
- public class LoopsExercise1
- {
- public static void main(String[] args)
- {
- int counter = 0;
- String answer;
- double price;
- int quantity;
- String item;
- double cost = 0;
- do
- {
- Scanner k = new Scanner(System.in);
- System.out.print("Enter the grocery item description: ");
- item = k.nextLine();
- System.out.printf("Enter the quantity of %s(s) being purchased: ", item);
- quantity = Integer.parseInt(k.nextLine());
- System.out.printf("Enter the price of %s: ", item);
- price = Double.parseDouble(k.nextLine());
- System.out.print("Would you like to enter another item? (Y/N): ");
- answer = k.nextLine();
- counter = counter + quantity;
- cost = cost + price;
- }while(answer.equalsIgnoreCase("y"));
- System.out.println("GROCERY TOTAL");
- System.out.println("=============");
- System.out.printf("Total items purchased: %d%n", counter);
- System.out.printf("Total cost: $%.2f", cost);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement