Question: I am having trouble getting the following code to pass the error checks. It runs smoothly but when I run checks on it I get

I am having trouble getting the following code to pass the error checks. It runs smoothly but when I run checks on it I get the following error messages. Any help with resolving this issue is greatly appreciated. Thanks in advance!

Error Message when running Checks:

Custom TestIncomplete

Fix the string interpolation

Test Output

AssertionError: The program contains an incorrect output message. This is the result of incorrect string interpolation.

Test Contents

import re import sys sys.tracebacklimit = 0 with open('/root/sandbox/DebugNine3.java', 'r') as f: contents = "" for line in f.readlines(): contents += line matches = re.findall("\"\s*\+\s*QUIT\s*\+\s*\"", contents) assert len(matches) == 2, "The program contains an incorrect output message. This is the result of incorrect string interpolation."

Code I am working with:

// Application contains a starting list of three products for sale

// The user is prompted for additional items

// After each new entry, the alphabetically sorted list is displayed

import java.util.*;

public class DebugNine3

{

public static void main(String[] args)

{

ArrayList products = new ArrayList();

products.add("shampoo");

products.add("moisturizer");

products.add("conditioner");

Collections.sort(products);

display(products);

final String QUIT = "quit";

String entry;

Scanner input = new Scanner(System.in);

System.out.print(" Enter a product or + QUIT + to quit >> ");

entry = input.nextLine();

while(!entry.equals("quit"))

{

products.add(entry);

Collections.sort(products);

display(products);

System.out.print(" Enter a product or " + QUIT + " to quit >> ");

entry = input.nextLine();

}

}

public static void display(ArrayList products)

{

System.out.println(" The size of the list is " + products.size());

for(int x = 0; x < products.size(); ++x)

System.out.println(products.get(x));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!