Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE CODE IN JAVA NEED IT ASAP Programming Challenge Descriptiorn IBM is imple

ID: 3596943 • Letter: P

Question

PLEASE CODE IN JAVA NEED IT ASAP

Programming Challenge Descriptiorn IBM is implementing an online pharmacy application for a major drug store chain. As part of the application, customers can start to type in the name of a drug and the system will allow them to choose from among the list of drugs which begins with the letters that they have typed. For example, if they type the letters "ASP", the system could offer "ASPRIN" as a possible match, along with other drugs that begin with "ASP". If there's no match, the system will show NONE> Assumptions . The list may be very long, hundreds of thousands of drugs . The call will be made very often, so search speed is crucial. ·Assume that in the production version, whatever preprocessing you do on the list of drugs is only done once, and the search is the only part that is called repeatedly Input: The entire list of drugs in alphabetical order, followed by a blank line, and then a partial sequence to search for Output The first 2 matching drugs, one per line, or if there's no match Test 1 Test Input B ACETAMINOPHEN ASPERGEL ASPRIN ASPERTAME ATAVAN

Explanation / Answer

VecorDemo.java

import java.util.Enumeration;

import java.util.Scanner;

import java.util.Vector;

public class VecorDemo {

public static void main(String[] args) {

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Creating an Vector

Vector<String> vec = new Vector<String>();

/* Adding elements to a vector*/

vec.addElement("ACETAMINOPHEN");

vec.addElement("ASPERGEL");

vec.addElement("ASPRIN");

vec.addElement("ASPERTAME");

vec.addElement("ATAVAN");

  

System.out.println("Dispaying all the Drugs :");

Enumeration enu = vec.elements();

//Displaying the Elements in the Vector

while(enu.hasMoreElements())

System.out.println(enu.nextElement() + " ");

  

System.out.println();

//Prompting the user to search for an Elements

System.out.print("Enter the Drug to search for :");

String search=sc.next();

enu=vec.elements();

int flag=0;

//Displaying the Elements

while(enu.hasMoreElements())

{

String str=(String)enu.nextElement();

if(str.startsWith(search))

{

System.out.println(str);

flag=1;

}

}

if(flag==0)

{

System.out.println("<NONE>");

}

}

}

__________________

Output:

Dispaying all the Drugs :
ACETAMINOPHEN
ASPERGEL
ASPRIN
ASPERTAME
ATAVAN

Enter the Drug to search for :ASP
ASPERGEL
ASPRIN
ASPERTAME

________________

Output2:

Dispaying all the Drugs :
ACETAMINOPHEN
ASPERGEL
ASPRIN
ASPERTAME
ATAVAN

Enter the Drug to search for :BES
<NONE>

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote