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
Case Project 2-1: The Differences Between IPv4 and IPv6 You are a network engineer for an IT consulting firm named F1IT. One of
Nadusha1986 [10]

Answer:

Following are the difference to this question:

Explanation:

IPv4:

The IPv_4 is uses the packet changed method, that is a Link Layer networks(like Ethernet).  It has 4.3 billion addresses capacity. It uses the 32-bit logical device address, that written in decimal language. It is divided by 4 bytes E.g. 192.168.1.1  

The host part and network part are 2 parts. For a network, the host part may vary, while for the entire subnet, the network part remains equal. The scheme of 232 addresses is available on application depends on security.

IPv6:

The IPv6 is used in the internet protocoland it is higher than IPv4. It can provide endless number Opf addresses, and use to solves the problem of IPv4 exhaustion and satisfies  the demand for rising networking.

IPv4 Substitutor Built to meet more IP address requirements. In the Logical address of 128-bit Written hexadecimally and with colons divided, and the Space of 128 addresses are required. IPsec is an integrated security feature.

5 0
3 years ago
Why doesnt brainly let me skip by watching video?
oksian1 [2.3K]

What do you want to skip in brainly? There isn't anything to skip that I can think of.

4 0
3 years ago
Provide a brief, high-level description of how the Internet’s connection-oriented service provides reliable transport.
mario62 [17]

Answer:

  Connection-oriented is the method which is implemented in the transport and data link layer. It is basically depend upon the physical connection in the network system.

Transmission control protocol (TCP) is the connection oriented and user datagram protocol (UDP) is the connection less network transport layer. The TCP and UDP both are operate in the internet protocol (IP).

It basically require connection and it can be establish before sending data. This is also known as reliable network connection service. The connection oriented service establish connection between the different connection terminal before sending any data or information. It can easily handle traffic efficiently.

7 0
3 years ago
How did Avery and Garth most likely create their
hram777 [196]
Avery used smartart and added shake
6 0
3 years ago
Which subject line for this informational e-mail would be most suitable? a.Important Announcement About Nutrition! b. The Upcomi
Lady_Fox [76]

Answer:

b. The Upcoming Lunch & Learn Program Is in March.

Explanation:

A subject line identifies the e-mail intent. The subject line displayed the user or recipient when they look at the list of messages.

For informational e-mail, some points take into consideration.

  • Write a subject line
  • keep it short
  • place important words
  • eliminate filler words
  • clear and specify the topic
  • keep the subject line simple
  • Set a deadline in the subject line
  • Highlight the value that offered

I think option b is suitable for the informational subject line in an e-mail.

4 0
3 years ago
Other questions:
  • Your computer has gradually slowed down. What's the most likely reason?
    8·1 answer
  • Structured walk-throughs take place throughout the SDLC and are called _____ reviews, depending on the phase in which they occur
    9·1 answer
  • Along with an ip address, a subnet mask, and a name server, the other thing required for a computer to operate on a network is a
    15·1 answer
  • A(n) __________ DHCPv6 server relies on router advertisements to give some information to individual hosts, making small changes
    8·1 answer
  • A circuit rated at 6600 watts and 240 volts will draw what ampers.
    6·1 answer
  • Why do people on Brainly verify answers that are wrong. I got 90% and 80% percent on my tests because of it
    6·2 answers
  • Keli is unable to find a shape that meets her needs. Which feature in Power Point should she use to create shapes that are compl
    6·1 answer
  • What is one disadvantage people face without a checking account?
    12·1 answer
  • LAB: Phone number breakdown Given a long long integer representing a 10-digit phone number, output the area code, prefix, and li
    8·1 answer
  • Select one Layer 2 or wireless WAN technology presented in Lesson 3. Elaborate on its characteristics, pros and cons, and common
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!