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
Sati [7]
3 years ago
8

Write the statements to prompt the user to enter dog names and cat names. Each line of input contains d (dog) or c (cat) followe

d by the name. The user will enter q quit when done. Print out all the cat names followed by all the dog names. The cat names and the dog names must be output in the same order in which they were entered. Use LinkedQueue objects in your code.

Computers and Technology
1 answer:
gulaghasi [49]3 years ago
4 0

Answer:

see explaination

Explanation:

import java.util.*;

import java.util.concurrent.*;

class Main {

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in); //Scanner Object to read Input

//LinkedQueue of String Type

ConcurrentLinkedQueue<String> cat_queue = new ConcurrentLinkedQueue<String>();

ConcurrentLinkedQueue<String> dog_queue = new ConcurrentLinkedQueue<String>();

System.out.println("Enter Dog names and Cat names\n");

//Reading input until line exists

while(sc.hasNextLine()){

String s = sc.nextLine(); //Reading string

String[] arr = s.split("\\s+"); //Splitting the string based on spaces

if (arr[0].equals("q") && arr[1].equals("quit")){ //checking if q quit or not

//printing cats and dogs if q quit

System.out.println("\ncats:");

//printing each cat_name in seperate line

for (String cat_name : cat_queue) { //Iterating over elements in cat_queue

System.out.println(cat_name);

}

System.out.println("\ndogs:");

//printing each dog_name in seperate line

for (String dog_name : dog_queue) { //Iterating over elements in dog_queue

System.out.println(dog_name);

}

System.exit(0); //Exiting as q quit is entered

}

else{

if(arr[0].equals("c")){ //If c is the string entered before name

cat_queue.add(arr[1]); //Add the cat_name into cat_queue

}

else if(arr[0].equals("d")){ //If d is is the string entered before name

dog_queue.add(arr[1]); //Add the dog_name into dog_queue

}

}

}

}

}

see attachment for screenshot of the code and output

You might be interested in
I can talk to you! How about we talk through the you know where people comment and say stuff about the question1
pychu [463]
Hmmm what do you want to talk about??
3 0
3 years ago
Read 2 more answers
The graph shows that sixty-eight percent of students think cyberbullying is a problem. One hundred human stick figures are shown
kari74 [83]

Answer:

C.

More students are affected by cyberbullying than not affected.

Explanation:

I got it correct on Edgenuity 2020.

8 0
3 years ago
Read 2 more answers
Selecting missing puppies 1 # Select the dogs where Age is greater than 2 2 greater_than_2 = mpr [mpr. Age &gt; 2] 3 print(great
anygoal [31]

Answer:

# the dog dataframe has been loaded as mpr

# select the dogs where Age is greater than 2

greater_than_2 = mpr [mpr. age > 2]

print(greater_than_2)

# select the dogs whose status is equal to 'still missing'

still_missing = mpr[mpr. status == 'Still Missing']

print(still_missing)

# select all dogs whose dog breed is not equal to Poodle

not_poodle = mpr [mpr.breed != 'Poodle']

print(not_poodle)

Explanation:

The pandas dataframe is a tabular data structure that holds data in rows and columns like a spreadsheet. It is used for statistical data analysis and visualization.

The three program statements above use python conditional statements and operators to retrieve rows matching a given value or condition.

4 0
2 years ago
Computer a sends a packet intended to reach computer f. along its path it arrives at computer
disa [49]
<span>To the computer f, this answer is because when reading the statement I assume that there is no type of connection and / or communication between the computer a and c; therefore to be profitable the computer c should return the package sending it back to computer f.</span>
5 0
3 years ago
When writing potential test questions, it is very important to use vocabulary words in their correct form. Please select the bes
Ilya [14]
The answer is True.

Hope I helped!
6 0
4 years ago
Read 2 more answers
Other questions:
  • Ryan is looking at investment opportunities as a cloud service provider. He wants to invest in a deployment-based cloud model th
    11·2 answers
  • Whitch action should a user take to ensure that formatting is applied to a row? A. use the ctrl+a keys. B. highlight the whole t
    11·1 answer
  • Write a program that takes the radius of a sphere (a floating-point number) as input and then outputs the sphere’s: Diameter (2
    7·1 answer
  • Need help with this​
    5·1 answer
  • ¿En cuales situaciones concretas se puede aplicar las técnicas de conteo(particularmente las permutuaciones y las combinaciones)
    11·1 answer
  • Hi, please help me complete my Database Development 2 hw by completing what should been done from the document and show the code
    11·1 answer
  • Declare an ArrayList of Strings. Add eight names to the collection. Output the Strings onto the console using the enhanced for l
    9·1 answer
  • To configure a router/modem, what type of IP interface configuration should you apply to the computer you are using to access th
    10·1 answer
  • Suppose cell C5 contains the formula =B$6+C1.
    6·1 answer
  • What study skill is being used when taking a large project and breaking it down into smaller manageable tasks?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!