1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rudiy27
3 years ago
8

1 // Application contains a starting list of three products for sale2 // The user is prompted for additional items3 // After eac

h new entry, the alphabetically sorted list is displayed4 import java.util.*;5 public class DebugNine36 {7 public static void main(String[] args)8 {9 ArrayListproducts = new ArrayList();10 products.add(shampoo);11 products.add(moisturizer);12 products.add(conditioner);13 Collections.sort(products);14 display(products);15 final String QUIT = "quit";16 String entry;17 Scanner input = new Scanner(System.in);18 System.out.print("\nEnter a product or " + QUIT + " to quit >> ");19 entry = input.nextLine();20 while(entry.equals("quit"))21 {22 products.add(entry);23 Collections.sort(products);24 display()25 System.out.print("\nEnter a product or " + QUIT + " to quit >> ");26 entry = input.nextLine();27 }28 public static void display(ArrayList products)29 {30 System.out.println("\nThe size of the list is " + products.size());31 for(int x = 0; x == products.size(); ++x)32 System.out.println(products.get(x));33 }34 }35//Debugging Exercises, Chapter 9;Java Programming, Joyce Farraell, 8th

Computers and Technology
1 answer:
madam [21]3 years ago
3 0

Answer:

Here is the corrected code:

import java.util.*;

public class DebugNine36 {  //class name

  public static void main(String[] args)    {  //start of main method

     ArrayList<String>products = new ArrayList<String>();  //creates an ArrayList of type String names products

     products.add("shampoo");  //add shampoo to product array list

     products.add("moisturizer");  //add moisturizer product array list

     products.add("conditioner");  //add conditioner product array list

     Collections.sort(products);  //sort the elements in products array list

     display(products);  //calls display method by passing products array list

     final String QUIT = "quit";  //declares a variable to quit the program

     String entry;  //declares a variable to hold product/element or quit

     Scanner input = new Scanner(System.in);  //creates Scanner object

     System.out.print("\nEnter a product or " + QUIT + " to quit >> ");  //prompts user to enter a product or enter quit to exit

     entry = input.nextLine();  //reads the entry value from user

     while(!entry.equals("quit"))       {  //loops until user enters quit

        products.add(entry);  //adds entry (product) to products array list

        Collections.sort(products);  //sorts the elements in products array list

        display(products);  //calls display method by passing products arraylist

        System.out.print("\nEnter a product or " + QUIT + " to quit >> ");  //keeps prompting user to enter a product or enter quit to exit

        entry = input.nextLine();        }    }  //reads the entry value from user

  public static void display(ArrayList products)    {  // method to display the list of products

     System.out.println("\nThe size of the list is " + products.size());  //displays the size of the array list named products

     for(int x = 0; x < products.size(); ++x)  //iterates through the arraylist products

        System.out.println(products.get(x));    }  } //displays each item/element in products array list

Explanation:

In the code the following statement are corrected:

1.

ArrayListproducts = new ArrayList();

This gave an error: cannot find symbol

This is corrected to :

 ArrayList<String>products = new ArrayList<String>();

2.

         products.add(shampoo);

         products.add(moisturizer);

         products.add(conditioner);

Here shampoo moisturizer and conditioner are String type items that are to be added to the products so these strings have to be enclosed in quotation marks.

This is corrected to :

     products.add("shampoo");

     products.add("moisturizer");

     products.add("conditioner");

3.

display();

This method is called without giving any arguments to this method. The method display takes an ArrayList as argument so it should be passed the arraylist products to avoid error that actual and formal argument lists differ in length .

This is corrected to :

display(products);

The screenshot of output is attached.

You might be interested in
Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The fi
Snezhnost [94]

Answer:

Go to explaination for the program code.

Explanation:

Before running the program you need to have these files created like below in your unix box.

Unix Terminal> cat nouns.txt

BOY

GIRL

BAT

BALL

Unix Terminal> cat articles.txt

A

THE

Unix Terminal> cat verbs.txt

HIT

SAW

LIKED

Unix Terminal> cat prepositions.txt

WITH

BY

Unix Terminal>

Code:

#!/usr/local/bin/python3

import random

def getWords(filename):

fp = open(filename)

temp_list = list()

for each_line in fp:

each_line = each_line.strip()

temp_list.append(each_line)

words = tuple(temp_list)

fp.close()

return words

articles = getWords('articles.txt')

nouns = getWords('nouns.txt')

verbs = getWords('verbs.txt')

prepositions = getWords('prepositions.txt')

def sentence():

return nounPhrase() + " " + verbPhrase()

def nounPhrase():

return random.choice(articles) + " " + random.choice(nouns)

def verbPhrase():

return random.choice(verbs) + " " + nounPhrase() + " " + prepositionalPhrase()

def prepositionalPhrase():

return random.choice(prepositions) + " " + nounPhrase()

def main():

number = int(input('Enter number of sentences: '))

for count in range(number):

print(sentence())

if __name__=='__main__':

main()

kindly check attachment for code output and onscreen code.

6 0
3 years ago
Which situation is an example of? "relational context" in the transactional model of? communication?
Jlenok [28]
An example I believe of relational context is when I was out with my son on the weekend (he has a developmental disability) and we had agree I would buy him a 1/2 sub sandwich the day before but then he said I would like a McFlurry so I said okay and then he said so you mean I can have a McFlurry and a sub and I thought oh oh I stuck my foot in it so I said but it must be only a 1/2 sub so he said no I want a full sub then and no mcflurry so I agreed so from the original 1/2 sub idea the idea evolved to a full sub which was affected by the warm sunny summery weather in the afternoon and seeing people lined up at ice cream shops so the idea developed in relation to the weather, how hungry he was and the social aspect people buying ice cream.
8 0
2 years ago
What is the viewport?
Shtirlitz [24]
C. The viewing area of a web browser.

The viewport is the user's visible area of a web page.
5 0
2 years ago
Rows within a spreadsheet are identified by:
EleoNora [17]

Answer:

Option C: Numbers.

Explanation:

By default, rows within a spreadsheet are identified by Numbers i.e. 1,2,3,............

Total rows are 1048575 in one spreadsheet.

7 0
3 years ago
In an ipv4 address, what are the maximum number of bits that can be used to identify the network address
Solnce55 [7]
Up to 24 bits can be used to identify unique <span>networks.</span>
5 0
3 years ago
Other questions:
  • While browsing through the mall, you are given samples of the latest perfumes from different designers. This is an example of wh
    14·1 answer
  • ___ is a career discipline focusing on helping companies use computer technology effectively.
    12·1 answer
  • why is wrong timing, poor technology, bad implementation and politics in business affected the OSI model as a standard
    5·1 answer
  • In a paragraph of no less than 125 words, describe how technology helps business professionals to be more efficient. Include exa
    12·2 answers
  • Write an examples of Output device, storage devices and inputs device 10 each excluding the common ones​
    5·1 answer
  • Secure Wi-Fi networks and VPNs use _____ to secure data transferred over a network.
    13·1 answer
  • Who ever likes Pokemon an wants to help me please comment and I will Give the room for My Assignment
    9·1 answer
  • A(n) ____________________ is hardware or software that blocks or allows transmission of information packets based on criteria su
    13·1 answer
  • Does anyone know 7.1.3: Firework karel?
    5·1 answer
  • You have a filtered dataset for Customer Sales with some null value rows. You want to remove these rows completely. How will you
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!