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
Discuss the challenges of not using the five elements of multimedia in a positive manner<br>​
EastWind [94]

hi buddy

here is your answer

<em>♡</em>Challenges for Multimedia Systems♡

  • Sequencing within the media -- playing frames in correct order/time frame in video.
  • Sequencing within the media -- playing frames in correct order/time frame in video.Synchronisation -- inter-media scheduling (e.g. Video and Audio).
  • Lip synchronisation is clearly important for humans to watch playback of video and audio and even animation and audio.

hope it helps

please mark me pls

#sibi❤

6 0
3 years ago
Jill uses Word to create an order form. She starts out by creating a table that has three columns and ten rows. She would like h
noname [10]

Answer: Jill will have to b) merge the top three cells so that her first heading can span the width of the entire table.

Explanation: If Jill merges the top two cells, one of the cells will still remain and therefore she will not be able to span the width of the entire table. She cannot merge the top ten cells because the problem states the has 3 columns. The 10 rows occupy the entire table and are not located at the top of the table. Jill could widen the first cell, however, it will limit her table to one large column and 10 rows. The problem states that only the first heading or row should be occupying the entire width, therefore b) merges the top three cells is the correct answer.

3 0
3 years ago
Discuss the causes ,symptoms, preventive measures and treatment of AIDS​
Svetlanka [38]

Answer:

AIDS can be caused by having sexual intercourse with an AIDS-infected partner. It can only be spread through the contact of infected blood or fluid from a mother to child during childbirth.

There are many symptoms of AIDS. However, these are the most common symptoms of AIDS:

  1. Swollen lymph glands
  • Most of the white blood cells are produced there.

2. Weight loss

3. Diarrhea

There are many measures that can be put in placed to prevent AIDS.

  1. To use a condom during sexual intercourse.
  2. Making sure that needles are not shared with others (e.g. when piercing your ear). The needles may be contaminated by an AIDS-infected user. Use a clean needle.
8 0
3 years ago
Read 2 more answers
A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that
Reptile [31]

Answer:

  1. with(open("numbers.txt")) as file:
  2.    data = file.readlines()  
  3.    runsum = 0
  4.    largest = 0
  5.    
  6.    for x in data:
  7.        if(int(x) > largest):
  8.            largest = int(x)
  9.            runsum += largest  
  10.    
  11.    print(runsum)

Explanation:

The solution code is written in Python 3.

Firstly, open a filestream for numbers.txt (Line 1) and then use readlines method to get every row of data from the text files (Line 2).

Create a variable runsum to hold the running sum of number bigger than the maximum value read up to that iteration in a for loop (Line 3).

Use a for loop to traverse through the read data and then check if the current row of integer is bigger than the maximum value up to that point, set the current integer to largest variable and then add the largest to runsum (Line 6 - 9).

At last display the runsum to console terminal (Line 11).

8 0
4 years ago
Progressive places its messages on local radio stations and in the yellow pages of the phone book. These communications are dire
Alexandra [31]

Answer: Receiver

Explanation:  

The receiver basically is used in the communication channel where the person decode its output and message in the form of useful data or information.

The main function of the receiver is to provide the path between the transmitter as an output and receiver as an input. The receiver basically process the received signal for recovering the proper message signal. It basically receive the input signal and covert it into useful data.

7 0
3 years ago
Other questions:
  • An Information Technology worker who follows the Programming and Software development pathway most likely enjoys
    15·2 answers
  • _____ software is used to play, create, and modify audio and video files.
    6·1 answer
  • As you move the click and type pointer around the document, the icon changes to represent ____________________ that will be appl
    10·2 answers
  • After a break, always review your work to
    12·2 answers
  • What engine component is shown in the above Figure?
    14·2 answers
  • If you need to set up direct deposit, which information from your check would you likely need?
    7·2 answers
  • Original list:0,0,0,0,0,0,0,0
    10·1 answer
  • How to do “Pseudocode” and “FlowChart” in this question ? <br><br> Please Help mee
    9·1 answer
  • Please help me the program c++
    15·1 answer
  • Suppose you are developing a cricket game in which you are asked to enter score of every ball and can score maximum 6 on each ba
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!