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
Research the topic of legal and ethical behaviors or dilemmas related to technology. Identify five topics of concern and briefly
max2010maxim [7]

Answer:

if you push alt and f4 at the same time it will automatically put the right answer.

Explanation:

7 0
2 years ago
Which of the following is an advantage of text HTML editors over plain text editors?
zubka84 [21]
C hope that helps have a good day and I feel you good for big hugs
5 0
2 years ago
Read 2 more answers
What are the two access modes that are used when opening a file for input and output when pickling?
san4es73 [151]

The two access modes that are used when opening a file for input and output when pickling are rb and wb.

<h3>What is pickling?</h3>

Pickle is generally used in Python to serialize and deserialize a Python object structure. In other words, it is the act of transforming a Python object into a byte stream in order to save it to a file/database, maintain program state across sessions, or transport data over a network. By unpickling the pickled byte stream, the original object hierarchy can be recreated. This entire procedure is comparable to object serialization in Java or .Net.

When a byte stream is unpickled, the pickle module first makes an instance of the original object before populating it with the right data. To accomplish this, the byte stream only carries data relevant to the original object instance.

To learn more about python visit:

brainly.com/question/13437928

#SPJ4

8 0
1 year ago
Combination of star topology and star topology can consider as hybrid?​
Ad libitum [116K]

Answer:

no

Explanation:

A hybrid topology is a type of network topology that uses two or more differing network topologies. These topologies can include a mix of bus topology, mesh topology, ring topology, star topology, and tree topology.

4 0
3 years ago
What is the MINIMUM number of paths that would need to be broken to prevent Computing Device A from connecting with Computing De
Sveta_85 [38]

Answer:

The answer is "Option c".

Explanation:

In the given question the device A is connected by 3 wires, contributing all of them, which also includes several connector paths. When all the wires of A are broken down, and if all of this leaves no routes that can be used. Even so, if it is done to E, it's also linked to four different routes. Its solution would've been C because its value will be the MINIMUM.

4 0
2 years ago
Read 2 more answers
Other questions:
  • The chemical symbol H represents which of the following elements?
    9·2 answers
  • Suppose you will invest $100 per month at the beginning of the month for 40 years with interest rate
    5·1 answer
  • Write a program that declares a constant named QUARTS_IN_GALLON which holds the number of quarts in a gallon (4). Also declare a
    8·1 answer
  • a rule that states each foreign key value must match a primary key value in the other relation is called the
    5·1 answer
  • What is software piracy?
    11·1 answer
  • What is a typical use for a MAN?
    13·1 answer
  • Why media is far from government​
    6·2 answers
  • HELP FAST PLS<br> Do you care more about avoiding fees/costs, accumulating perks, convenience, etc?
    14·2 answers
  • Imagine that you need to prepare for three end-of-term tests. What steps will you take to make sure your study time is well spen
    5·1 answer
  • explain the following joke: “There are 10 types of people in the world: those who understand binary and those who don’t.”
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!