Skip to main content

Practice Code Structure

Section 1.47 Fill-in-the-blank

Checkpoint 1.47.1.

Improve the style of printProductStatus(). The original function is below, followed by a version with two blanks. Fill in the blanks so that the original functionality is preserved, but the code is easier to maintain.
public static void printProductStatus(int quantity) {
	String status = "";
   
	if (quantity > 100) {
   	    status = "High Stock";
   	    System.out.println("Status: " + status);
	} else if (quantity > 0) {
   	    status = "In Stock";
   	    System.out.println("Status: " + status);
	} else {
   	    status = "Out of Stock";
   	    System.out.println("Status: " + status);
	}
}
public static void printProductStatus(int quantity) {
    String status = "-----Blank1-----"; // Default value

    if (quantity > 100) {
        status = "High Stock";
    } else if (quantity > 0) {
        status = "In Stock";
    } 

    System.out.println(------Blank2-----);
}
Put your responses here:
Blank 1:
Blank 2:
You have attempted 1 of 2 activities on this page.