Sunday, October 20, 2019
Using the ArrayList in Java
Using the ArrayList in Java Standard arrays in Java are fixed in the number of elements they can have. If you want to increase of decrease the elements in an array then you have to make a new array with the correct number of elements from the contents of the original array. An alternative is to use the ArrayList class. The ArrayList class provides the means to make dynamic arrays (i.e., their length can increase and decrease). Import Statement import java.util.ArrayList; Create an ArrayList An ArrayList can be created using the simple constructor: ArrayList dynamicArray new ArrayList(); This will create an ArrayList with an initial capacity for ten elements. If a larger (or smaller) ArrayList is required the initial capacity can be passed to the constructor. To make space for twenty elements: ArrayList dynamicArray new ArrayList(20); Populating the ArrayList Use the add method to append a value to the ArrayList: dynamicArray.add(10); dynamicArray.add(12); dynamicArray.add(20); Note: The ArrayList only stores objects so although the above lines appear to add int values to ArrayList the are automatically changed to Integer objects as they are appended to the ArrayList. A standard array can be used to populate an ArrayList by converted it to a List collection using the Arrays.asList method and adding it to the ArrayList using the addAll method: String[] names {Bob, George, Henry, Declan, Peter, Steven}; ArrayList dynamicStringArray new ArrayList(20); dynamicStringArray.addAll(Arrays.asList(names)); One thing to note about ArrayList is the elements dont have to be of the same object type. Even though the dynamicStringArray has been populated by String objects, it still can accept number values: dynamicStringArray.add(456); To minimize the chance of errors its best to specify the type of objects you want the ArrayList to contain. This can be done at the creation stage by using generics: ArrayList dynamicStringArray new ArrayList(20); Now the if we try to add an object that isnt a String a compile-time error will be produced. Displaying the Items in an ArrayList To display the items in an ArrayList the toString method can be used: System.out.println(Contents of the dynamicStringArray: dynamicStringArray.toString()); which results in: Contents of the dynamicStringArray: [Bob, George, Henry, Declan, Peter, Steven] Inserting an Item into the ArrayList An object can be inserted anywhere into the ArrayList index of elements by using the add method and passing the position for the insertion. To add the String Max to the dynamicStringArray at position 3: dynamicStringArray.add(3, Max); which results in (dont forget the index of an ArrayList starts at 0): [Bob, George, Henry, Max, Declan, Peter, Steven] Removing an Item from an ArrayList The remove method can be used to remove elements from the ArrayList. This can be done in two ways. The first is to supply the index position of the element to be removed: dynamicStringArray.remove(2); the String Henry in postion 2 has been removed: [Bob, George, Max, Declan, Peter, Steven] The second is to supply the object to be removed. This will remove the first instance of the object. To remove Max from the dynamicStringArray: dynamicStringArray.remove(Max); The String Max is no longer in the ArrayList: [Bob, George, Declan, Peter, Steven] Replacing an Item in an ArrayList Rather than removing an element and inserting a new one in its place the set method can be used to replace an element in one go. Just pass the index of the element to be replaced and the object to replace it with. To replace Peter with Paul: dynamicStringArray.set(3,Paul); which results in: [Bob, George, Declan, Paul, Steven] Other Useful Methods There are a number of useful methods to help navigate the contents of an arraylist: The number of elements contained within an ArrayList can be found using the size method: System.out.println(There are now dynamicStringArray.size() elements in the ArrayList);After all our manipulations of dynamicStringArray were down to 5 elements:There are now 5 elements in the ArrayList Use the indexOf method to find the index position of a particular element: System.out.println(The index position of George is : dynamicStringArray.indexOf(George));The String George is in index position 1:The index position of George is : 1 To clear all the elements from an ArrayList the clear method is used: dynamicStringArray.clear(); Sometimes it can be useful to see if the ArrayList has any elements at all. Use the isEmpty method: System.out.println(Is the dynamicStringArray empty? dynamicStringArray.isEmpty());which after clear method call above is now true:Is the dynamicStringArray empty? true
Saturday, October 19, 2019
Employment Law Essay Example | Topics and Well Written Essays - 3000 words - 2
Employment Law - Essay Example or not? If it is proven that he is a regular or permanent employee, his right for continuing in the job would be very genuine unless he is indulged in illegal activity or unethical practice at work place. Various tests have to be applied for determining the nature of job performed by Tom. In the contract, it was mentioned that he was not able to avail the sick leave and pension benefits which suggests that he is not a regular employee. Moreover, Tom was assured of at least 20 training sessions which also indicates that his job is more of a contractual in nature. In case of his inability to attend the sessions due to his sickness, there is a clause for substituting him with another personal trainer with the permission of the company. This also indicates the intention of the company to utilize the services of the personal trainers on contractual basis. If one trainer fails, the other one should take care and as long as this process continues, the company will not have to bother about t he job of any personal trainer. Hence, in this context, the company has to clarify on which specific grounds, Tom was terminated and it has to explain the reasons for its conclusion on poor job performance. According to the contract law, once the agreement was made, the terms and conditions should be accurately followed and in cases of minor exceptions sufficient justification has to be provided. If it is not based on the proper justification, Tom should file case against Unfit Ltd. For removing him which comes under unfair practice. The case can be filed against the Unfit Ltd. as it violated both English contract law and unfair contract terms act (1977) (Ole Lando et al., 2003 ). The length of service is not in favor of Tom as it is very short i.e. one year and hence his nature of job may not be considered as regular and hence he will not be entitled to pension and other retirement benefits as declared by the company in its regulations. In addition, he was made responsible for his tax payment and insurance payment and he rather agreed to work on self employed basis to get tax benefits which indicates that he is not a regular employee in the company. His working conditions would be completely guided by the contract made between him and the Unfit Ltd. However, it doesnââ¬â¢t give any right to company to remove an employee with out quoting proper and logical reason. In the present case study, the company abuses that Tom terminated with immediate effect due to persistent poor job performance. However, more specific details are not available and there is a need for the company to prove this and then only the termination of Tom may be considered as fair. Hence, Tom may file a case against Unfit Ltd. As it violated the principles of European contract law (The commission on European contract law, 1999) In addition, the removal process must be in conformity with the contract clauses made between the Unfit Ltd. and Tom. There are different clauses like requirement o f wearing an uniform supplied by the company, requirement of utilizing the companyââ¬â¢s equipment and support staff, allocation of atleast 20 sessions for personal training of the companyââ¬â¢s employees. In the present case, there is no evidence that Tom violated any one of these clauses and hence his termination is illogical and he can claim in court of law against the Unfit Ltd. for unfair dismissal. The company dismissed Tom with out any notice which is also not fair and violation of the contract made
Feeling after concert Essay Example | Topics and Well Written Essays - 500 words - 2
Feeling after concert - Essay Example Well, the artists made a perfect blend of features of each continent with a rich European music. It embodies a new way of cultural collaboration. At the concert, I had so much fun. I literally sang my heart out to my favorite playlists. I sang every word, danced my heart out and let everything loose as the World Percussion Ensemble performed their songs almost to perfection. In fact, I arrived at the concert hall at 7 pm, just to ensure I did not miss their first song. It would have been disappointing had I arrived late. Luckily, the concert began ten minutes after eight. What a relief! Nonetheless, it is unimaginable how fans would go wild as they screamed to their favorite tunes. Well, at first it may seem scary. However, the fun in the concert theatre drowned the screams. It is indeed memorable to witness how so many people could gather for music. When the artists kicked off the revelers were already on their feet. The theatre hall was pumped and one could literally feel the excitement of the audience. Besides, the fans were singing along too! I must have lost the number of counts the lead vocalist Njamy Sitson, let the fans finish a line. It seemed like giving the crowd an opportunity to savor their favorite songs. It was fascinating when Walter Lang, the composer, asked everyone to put their phones away and to just live in the moment. Besides, that night had been all that we had. Every performance was a goose-bump. At one point, Marco Lobo, the Brazilian magician in percussion removed his shoes to the thrill of the audience. Currently, I am in a state of a hangover---seven days after the concert. At the end of the show they promised they would be coming back soon to Columbia after a number of tours across the world. Although the band is made of people from diverse cultures, they confessed that they received much support from the audience than other places they have performed before. I was more thrilled and
Friday, October 18, 2019
Define the Origins of the Aqualung in Relation to Swim Diving Essay
Define the Origins of the Aqualung in Relation to Swim Diving - Essay Example The open air prototype expelled all exhaled air into the waters. The open air system is commonly used for the recreational diving. The Scuba divers suffers from the risks for decompression problems (divers using surface-supplied compressed air) should they ascend without adequate decompression. However, a mixture of Helium-Oxygen compressed air can help Scuba divers descend deeper as compared to compressed air. The history of scuba diving dates back centuries. Many individuals have been diving underwater throughout the ages probably for a period long as they have been swimming. However, the diving may not have been in the exact form of scuba diving but ushered in the inquiry for dive and remained breathing underwater. In ancient times, such mechanisms as hollow reeds, as well as inflated airbags but had a lot of shortcomings. They had limitations based on depth and the duration the swimmer could remain underwater breathing. Scuba diving has undergone a number of tremendous expansions till the turn of the century where the number of new divers is gradually stabilizing. By 2012, the number of new divers certified was approximately one million. The Scuba diving remains a fledgling and vibrant sport as portrayed by the ever rising evolution of the dive equipment as its associated practices. Over the recent years, the application of dive computers has been standardized effectively integrated into many certification agencies in their training curriculum. The incorporation of the wireless of air consumption into the algorithm of dive computers remains the most fundamental innovation. Accordingly, the incorporation of wireless integration into the diving sport has culminated into a safer diving. The chronology of the scuba diving is quite fantastic. The various civilizations throughout the years have indulged in breath-hold diving, free-diving. The existence of sea items on land and ancient pictures presents the evidence for early
Proposed Installation of a Swimming Pool Essay Example | Topics and Well Written Essays - 1500 words
Proposed Installation of a Swimming Pool - Essay Example Since some pools are easily removed while others become a permanent part of a property, this is an important consideration. Related to this concept is the type of coating or painting which should be used for a newly constructed pool. Another of your concerns was the safety features and insurance liability coverage you should carry, not only for your own family's security but also for visitors' coverage or for incidental pollution considerations. Electricity for pumps and filtering devices, accidental misuse of chemicals in the water and a host of other issues are involved here. While you did not ask us about enclosures or pool covers, we are including some information about these in this report. Since Atlanta is not actually in the semi-tropical areas of the USA, we felt you would appreciate some ideas for safe storage of the pool area in cooler weather. We did some interview research about the cost and life expectancy of both on-ground and in-ground pools. (Answers.yahoo). This was part of our research as to which of the three pool types to recommend to you and to provide you with the rationale for your decision. Our staff checked online sites for prices as well as the pros and cons of each of the three pool types. ... Our staff checked online sites for prices as well as the pros and cons of each of the three pool types. Of course, size influences price as surely as whether to build into the ground or on top of the ground. We looked at various building materials for the pool types. These include fiberglass, concrete, steel, aluminum and resin. We felt sure that you did not intend to be building an air-filled rubber pool so we did not check into that material. We have information on ground preparation for the pool types. The red clay of Georgia will not give you much problem for whichever type of pool you build. Lastly, we investigated liability insurance, pool covers and enclosures as well as cleaning and painting materials. In the next section of this report, we will break down our findings to aid in making an informed decision. Findings of Investigation Let us first consider the three possible pool types. They are above ground pools, on ground pools and in ground pools. There are descriptions and photos available online (Propools). The above ground pools are easily moved since they are made to be rather easily put together and taken apart. Within a few hours, the owner can put up the pool and fill it with water and begin using it. These pools sit on top of the ground. Just as easily, the pool can be disassembled for storage or removal to another spot. These pools can be made of aluminum, steel or resin. (sharkline). Pepper 3 The on ground pools are better for sloping ground and are similar to in ground pools in that they are more permanent. Their prices are a bit higher than the prices of the above ground pools since these pools are not easily removed. The third type of pool is the in ground pool. It
Thursday, October 17, 2019
The interrelation between thought and language has been a central and Essay
The interrelation between thought and language has been a central and enduring issue in philosophy and psychology. Of particular interest has been the possibil - Essay Example However, there are studies such as the classical and operant conditioning which somehow proved that even animals has the ability to learn. These studies opened the possibilities that thought exists even without language. Darwin (1920), the person behind the theory of evolution, suggests that human mind and that of animals are different on certain degree and not of kind. This statement implies that animals may also have the capability to think but not in the way and degree that human does. Theories and studies on different animals in search for the cognitive ability of animals provide evidence or somehow support this statement of Darwin. In earlier theories, the famous classical conditioning is one of the evidences of animal cognition. It was proposed by Ivan Pavlov; with the theory about the relationship between stimuli and responses using a dog, Pavlov discovered that animals could learn to display certain responses to stimuli already eliciting those responses (Tiffany, 1999 p.216). The operant conditioning started with different experiments, especially that of B.F. Skinner. Skinner developed the operant conditioning using rats and pigeons. In his rat experiment, he put a rat in the cage called Skinner Box that had a button on a wall which when pressed released a food pellet. When the rat accidentally pressed the button, food pellet came out which caused the rat to pressed the button more. When the button can not anymore give the rat some pellets, the rat stopped pressing the button. Through this theory, it was discovered that animals have the ability to learn through reinforcement or reward. However, even if Skinner used nonhuman animals with his experiment, he was still one of those who favor the total dependence of thought on language along with other behaviorists such as Watson, Ryle, Rosenberg, Wittgenstein and others (Chrucky, 1990). The operant theory is used today in human psychology
Colonialism and imperialism Assignment Example | Topics and Well Written Essays - 250 words
Colonialism and imperialism - Assignment Example The Dutch/Scottish Model were Calvinists, who believed in a God-given mission to colonize. They firmly believed that inferior races were not intelligent enough to advance as society. Since these so-called ââ¬Å"inferior racesâ⬠lacked intellect and were engaged in barbarity, it was deemed necessary to separate and categorize races. A different perspective of colonialism was founded upon the English and the Spanish model. The belief was not to segregate per say, but to convert all humans to be Catholics or Anglicans. The emphasis was based upon assimilation of white traditions rather than implementing economic models in the colonies. Although that was a motive for this model, it was clear that the English and Spaniards were clearly interested in the natural resources that colonies possessed. Modern colonialism can be dated as far the as fifteen-century when the Portugal Empire was in the quest to explore other land. The Portuguese and Spaniards were no doubt interest to establis h their kingdoms overseas in their quest to become imperialistic leaders. Africa seemed a logical place to begin as the American regions were taken by Dutch and British. The British had supreme command of the seas and were being efficient and productive with the technological advances that became catalyst to the industrial age. Mercantile colonialism can be categorized in two distinct eras.
Subscribe to:
Posts (Atom)