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
What is the difference between a software engineer and a system analyst?
cricket20 [7]

Answer:

A software engineer make things to be perfect. A system analyst researches about things. That is the difference.

Explanation:

Hope this helps!

6 0
3 years ago
Program a substitution cipher in Python. Create 2 functions one for encryption and the other for decryption ( get the text as th
raketka [301]

alphabet = "abcdefghijklmnopqrstuvwxyz"

def encrypt(txt):

   shift = int(input("Enter the shift: "))

   new_txt = ""

   for x in txt:

       if x in alphabet:

           if alphabet.index(x)+shift >= len(alphabet):

               new_txt += alphabet[(alphabet.index(x)+shift - len(alphabet))]

           else:

               new_txt += alphabet[alphabet.index(x)+shift]

       else:

           new_txt += x

   return new_txt

def decrpyt(txt):

   shift = int(input("Enter the known shift: "))

   new_txt = ""

   for x in txt:

       if x in alphabet:

           new_txt += alphabet[alphabet.index(x) - shift]

       else:

           new_txt += x

   return new_txt

print(encrypt("yellow dog."))

print(decrpyt("lryybj qbt."))

My code works with lowercase text only. If you need me to modify the code, I can do that. I tested my code with a shift of 13 in both the encryption and decryption. I hope this helps!

7 0
2 years ago
You are managing an FTP server installed in Ubuntu Server. The server has created a very large log le, vsftpd.log. Which command
kirill115 [55]

Answer:

c. sudo grep "charlie" /var/log/vsftpd.log

Explanation:

  • sudo is used to access /var/log files since it requires superuser access
  • grep command is used to search for a string of characters in a specified file
  • "charlie" is the string searched in the log files
  • /var/log/ is where the log files are in linux systems
5 0
3 years ago
For a loop counter, the appropriate data type would be:
BigorU [14]

Answer:a) int

Explanation: Loop counter is the kind of program that has the major function of counting the start value to the destination value in the form of integer.The integer is used for counting the values in a particular loop is known as the loop control variable.Therefore the accurate datatype for the loop counter to count the values should be of int type.

8 0
3 years ago
You're an administrator for a large corporation and you are responsible for deploying computers often and quickly. What server d
fomenos

Answer: it used the keyboard and apps

6 0
3 years ago
Other questions:
  • Which functions are performed by server-side code??​
    10·1 answer
  • I need someone who knows HTML to finish the code.
    12·2 answers
  • What is the simplest way to permanently get rid of a unwanted file
    12·1 answer
  • What do you believe are the motives of a cyber criminal? Why?
    15·1 answer
  • PLEASE HELP!!!!
    6·2 answers
  • What correctly describes the features of the service called kickstarter?
    14·2 answers
  • What is the difference between electrical and electronic devices?
    5·2 answers
  • Which of the following IS an operating system? *<br> Reddit<br> Ubuntu<br> Office 365<br> Mac Pro
    9·1 answer
  • Is iphone battery being draned if plugged into car charger when listening to podcasts
    6·1 answer
  • How do you modify WordArt? Give specific details and steps<br><br> NEED THIS ASAP
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!