Question

In: Computer Science

Okay so I already completed steps A - C listapi is now a library for project...

Okay so I already completed steps A - C listapi is now a library for project 4 the trouble I am having is how to do part D.

Use ListAPI as a library.

a) Create a Intellij project and name it “p4_2_your-id”.

b) Create a JAR file of “ListAPI”.

Download “ListAPI.zip” from Moodle and extract the NetBeans project folder “ListAPI” from the archive file.

In NetBeans, open “ListAPI”. Under the Project tab, right click on ListAPI and select Clean. Under the Project tab, right click on ListAPI and select Build. The created jar file is in “dist” folder.

Move the JAR file to the folder that contains your project folder. Navigate to the “ListAPI” NetBeans project folder and open it. Open the folder “dist”. Copy the file “ListAPI.jar” and paste it in the same folder that contains the “p5_2_your-id” project folder.

c) Attach the “ListAPI.jar” to your project.

Under the NetBeans Project tab, open the project created in step (a).

Right click on Libraries and select “Add JAR/Folder...”, and then navigate to “ListAPI.jar”. In the Add JAR/Folder dialog box, select “ListAPI.jar”, select Relative Path (which, if you have followed the preceding instructions, will be “../ListAPI.jar”) and click OK.

The classes in the JAR file are now available either by adding the following import statement to classes in your project

import listapi.*;

or by entering the full name of a class as in the following example.

        listapi.TestGenericQueue tgq
        = new listapi.TestGenericQueue();

d) In your project “p4_2_your-id”, add code to enqueue 5 integer values in a listapi.GenericQueue, displaying the queue as each value is added. Then, dequeue each element in the queue, adding each value to a listapi.GenericStack, displaying the queue and stack as each value is moved from the stack to the queue. Finally, pop all values of the stack and add them to a listapi.MyArrayList, displaying the stack and the list as each value is moved from the stack to the list.

Solutions

Expert Solution

Solution:

The main idea behind the question is how to use the classes from this ListAPI..

At first, complete till this: "Attach the “ListAPI.jar” to your project."

In this step you will right-click on the project, then go in its properties ,.... if you follow the steps written, you will have a jar file ListAPI.jar reference in your project and you can see it by reloading the project. This is done then the jar file will be displayed along with the libraries defined in-built in your project.

Now comes the last part. How you will access the class from that library you just included...

The simplest way is to write this :

import listapi.*;

This is mentioned in above question. But, ideally, you should not use this approach because this needs to add all the class definitions from listapi.jar. Suppose that it contains 1000s of classes, then using ' * ' over here means import each and every class definition in this program, irrespective of whether it will be used or not. This increases the size of byte code and also it is not necessary.

So, instead of that you should use the following approach:

(1).

For example, as mentioned, you are supposed to use the class GenericQueue. In your main() method, write this :

GenericQueue gq1 = new GenericQueue();

So, this will give an error in which as you are using NetBeans, you will get a red underline below GenericQueue. Place your cursor in between this word, just move the cursor in this word, then press Alt + Enter.

It will give you the suggestions to correct the error. If you have inserted the Jar file and if it is successfully inserted, it will give the first suggestion as : Add import for import listapi.GenericQueue.

Click on that and the error is gone. Now, if you see the import section, NetBeans has automatically added the import listapi.GenericQueue; statement.

So, whenever you use some class for the first time, import it using this way. This helps in reducing the number of classes required to import and does the required task also.

(2).

There is 1 alternative as well.. Use all your classes you need from listapi.jar like GenericStack, GenericQueue and MyArrayList ... etc. Don't worry about the red underlines. Now,if you have used all the classes at least once, press Ctrl + Shift + i . This will display all the required class imports to be done in a dialog box. From here, you can easily import them.

Once they are imported in your class, you can code them as you require. So, you can access them to fulfill the task after importing.

Please comment if there is any query. Thank you. :)


Related Solutions

So I did the Milestone 1 already and it seems to be correct. But now i...
So I did the Milestone 1 already and it seems to be correct. But now i need to do the Milestone 2 Please help. Street Sweep MILESTONE 1 - Variable & Fixed Cost Exercise INSTRUCTIONS: Determine the per unit cost for each dog. Fill in the blanks to get the per unit cost and fixed cost of each service. Based on 5 grooms per day GROOMING Item Variable Costs Item Fixed Costs Shampoo $                      1.04 Groomer $              2,080.01 Clipper(s)                          ...
I'm having trouble understanding this concept. I already completed the first part now I need to...
I'm having trouble understanding this concept. I already completed the first part now I need to convert the Second Part into a Control Structure. Please help answering the Problem. The first part will be below. (Second Part) Continuing with Control Structures Control Structures are called such because they control the execution flow during the running of a program. There are 3 basic control structures: Sequence, Selection and Loop. This week let's work with the structures we already know - Sequence...
okay so I took this quiz and these are the answers I put. there are 13...
okay so I took this quiz and these are the answers I put. there are 13 questions but I am not sure what I am getting wrong. all I know is I got 9 out of 13 right. A population's dispersion pattern is related to the likelihood of competition between individuals. individuals' chance of finding a mate. Both neither A population has the greatest number of individuals when numbers are near (or at) the carrying capacity. when numbers are near...
I NEED PART 2 COMPLETED I ALREADY COMPLETED 1A-D COURSE PROJECT 1 INSTRUCTIONS You have just...
I NEED PART 2 COMPLETED I ALREADY COMPLETED 1A-D COURSE PROJECT 1 INSTRUCTIONS You have just been contracted as a new management trainee by Earrings Unlimited, a distributor of earrings to various retail outlets across the country. In the past, the company has done very little in the way of budgeting and at certain times of the year has experienced a shortage of cash. Since you are well trained in budgeting, you have decided to prepare a master budget for...
okay so i am working on a physic review quetion that i seem not to know...
okay so i am working on a physic review quetion that i seem not to know where to start.. It states as follow A magnetic field of .250T points straight up in a lab, a circular coil of wire with 10 turns, a radius of 12 cm and a resistance of 1.6 ohms, sits on a slanted surface, tilted at 30 degress from horizontal. Then the magnetic field is turn off and it decays exponentially to 0. (B=Boe-t/T) At the...
I HAVE ALREADY CORRECTLY COMPLETED PART A AND B PLEASE COMPLETE PART C ONLY Part A...
I HAVE ALREADY CORRECTLY COMPLETED PART A AND B PLEASE COMPLETE PART C ONLY Part A In late 2020, the Nicklaus Corporation was formed. The corporate charter authorizes the issuance of 6,000,000 shares of common stock carrying a $1 par value, and 2,000,000 shares of $5 par value, noncumulative, nonparticipating preferred stock. On January 2, 2021, 4,000,000 shares of the common stock are issued in exchange for cash at an average price of $10 per share. Also on January 2,...
Describe a familiar project. Ideally, this will be a work-related project that has already been completed....
Describe a familiar project. Ideally, this will be a work-related project that has already been completed. Provide examples of events that took place in each of the four stages of the product life cycle (see below). Select two of the following five components: Client interest (level of customer enthusiasm and concern); Project stake (amount of investment); Resources (commitment of financial, human, and technical resources); Creativity (the amount of innovation required); and Uncertainty (the degree of risk associated with the project)....
Can someone please explain how to do the steps for this? I already have part a...
Can someone please explain how to do the steps for this? I already have part a completed but I need help with b-e. Thank you. Problem 1: (a) What is spurious regression? Explain. (b) Assuming , randomly generate 1000 observations of variables X and Y using the following equations: Report the graphs of X and Y. (c) Run the regression: and report the estimated results. (d) What did you expect about the magnitudes and R-square? How are the estimated values...
using C , comments will be appreciated. I already posted this before and I am looking...
using C , comments will be appreciated. I already posted this before and I am looking for different answer. please answer both part of the question. A) Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that...
I did the previous steps and now im at 6 and 7. I can not figure...
I did the previous steps and now im at 6 and 7. I can not figure it out. It is a calculator code, and this part we need to make it password protected. The user is asked to enter in a username and password, and if the password is the backwards of the username you get into the calulator code (that i already have finished below). Use strings and arrays to hold the username and password (maybe use something like...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT