1.
Suppose you must write a program that performs statistical calculations for a very large set of numerical data. Which would not be the best choices for storing such a collection if performance is important? (select all that apply)
Select one or more:
A. ArrayList
B. LinkedList
C. HashMap
D. An array of type int or double
2.
Which of the following statements is true?
Select one:
A. The Java map classes can access objects by reference values.
B. The Java LinkedList class can access objects by absolute values.
C. The Java map classes can access objects by key values.
D. The Java map classes can access objects by absolute values.
3.
Assume that myList is an ArrayList<Integer> object containing the elements 1 2 3 4 5 6. Assuming that each of the following statements is independent of the others, which would cause an error? (select all that apply)
Select one or more:
A. Object o = myList.remove(6);
B. myList.add(6, 9);
C. Integer o = myList.add(2.4);
D. Object o = myList.set(6, 8);
Question 1: Time complexity of adding and searching an element in ArrayList, HashMap and array are O(1). Where as for LinkedList is O(n) Answer: B. LinkedList ============================ Question 2: Map is a collection of key value pairs. Answer: C. The Java map classes can access objects by key values. ============================ Question 3: A. Object o = myList.remove(6); This gives "java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 6" C. Integer o = myList.add(2.4); This gives compile time error because 2.4 is not an integer. D. Object o = myList.set(6, 8); This gives "java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 6" Answers: Options A,C,D
1. Suppose you must write a program that performs statistical calculations for a very large set...
For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes: Student – a Student object has three private instance variables: lastName, a String; firstName, a String; and average, a double. It has accessor methods for lastName and firstName, and an accessor...
question 27’s end is in the next page
24 Suppose you have created a list using the statement ArrayList String> NYIT CS Courses new ArrayList(31 What would java do when you try to insert more than 31 courses? ANS: LinelI) check one with x: continue process as usual I Ijava automatically expand array space you manually expand more array spaces 25 Suppose NYIT CS COurscs is an object of the class Array List Suring Write Java statements that will display...
10.3 Example. When you first declare a new list, it is empty and its length is zero. If you add three objects—a, b, and c—one at a time and in the order given, to the end of the list, the list will appear as a b c The object a is first, at position 1, b is at position 2, and c is last at position 3.1 To save space here, we will sometimes write a list’s contents on one...
9. Java coder Courtney is writing a program that derives a list of unique words contained in a given text file: the word values themselves, and a total count for the file. What Collection type would be best suited for the job? Check only one) O (a) BinarySearch (b) List □ (c) Map (d) Set D (e) Queue 10.Software-Engineer Ellie is designing a similar program to Courtney. She needs to track a count for each unique word contained in a...
1-Suppose you write an application in which one class contains code that keeps track of the state of a board game, a separate class sets up a GUI to display the board, and a CSS is used to control the stylistic details of the GUI (for example, the color of the board.) This is an example of a.Duck Typing b.Separation of Concerns c.Functional Programming d.Polymorphism e.Enumerated Values 2-JUnit assertions should be designed so that they a.Fail (ie, are false) if...
Please use Java only: Background: Java contains several different types of interfaces used to organize collections of items. You may already be familiar with the List interface, which is implemented by classes such as the ArrayList. A List represents a collection of elements from which elements can be stored or retreived, in which elements are ordered and can be retrieved by index. A List extends from a Collection, which represents a collection of elements but which may or may not...
Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...
Question 11 The feature that enables you to split source code between two or more files is: Select one: a. base class b. partial classes c. generics d. dynamic link library e. package Question 12 Packaging data attributes and behaviors into a single unit so that the implementation details can be hidden describes an object-oriented feature called: Select one: a. abstraction b. objects c. inheritance d. polymorphism e. encapsulation Question 13 A multitier application would probably have:...
need code for this in java
Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...