83.5k views
2 votes
Sally wants to write a program to help with her keeping track of her Girl Scout cookie sales. The types of cookies Sally is selling are: Thin Mints, Do-Si-Dos, Samoas, and Adventurefuls. Using a do while, write the code to print a menu, ask for the type of cookie being sold (T, D, S, or A) and validate for the input. The code should keep printing the menu and asking for the type of cookie until a valid code has been entered. Menu: M - Mints, D - Do-Si-Dos, S - Samoas, A - Adventurefuls.

1 Answer

5 votes

Final answer:

You can write a program using a do-while loop in Java to help Sally keep track of her Girl Scout cookie sales.

Step-by-step explanation:

Code Explanation:

We can write a program to help Sally keep track of her Girl Scout cookie sales using a do-while loop in a programming language like Java. Here's the code:

import java.util.Scanner;

public class CookieSales {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String cookieType;

do {
System.out.println("Menu: M - Mints, D - Do-Si-Dos, S - Samoas, A - Adventurefuls");
System.out.print("Enter the code of the cookie being sold: ");
cookieType = scanner.nextLine().toUpperCase();
} while (!(cookieType.equals("M") || cookieType.equals("D") || cookieType.equals("S") || cookieType.equals("A")));

System.out.println("Valid cookie type: " + cookieType);
}
}

This program will keep printing the menu and asking for the type of cookie being sold until a valid code (T, D, S, or A) has been entered.

User Naveen Nelamali
by
7.8k points