Question

In: Computer Science

Question 17 (1 point) What is the return type of this method? public <E extends Comparable<E>>...

Question 17 (1 point)

What is the return type of this method?

public <E extends Comparable<E>> int theMethod(E arg)

Question 17 options:

E

Comparable

int

arg

Question 18 (1 point)

What is the primary benefit of writing generic classes and methods?

Question 18 options:

Generic classes and methods are more type-safe

Generic classes and methods are shorter

Generic classes and methods are faster

Generic classes and methods are backwards compatible

Question 19 (1 point)

What is wrong with the following method?

public static E copy(E arg) {

E theCopy = arg.clone();

return theCopy;

}

Question 19 options:

The method cannot be static if it uses generics

The method calls clone on the argument, but that method is not guaranteed to exist for the argument

You cannot declare a variable (e.g. theCopy) with a generic type

The returned value does not match the method signature

Question 20 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a class scheduling application, and you need to keep track of the wait list for overbooked classes. If a student tries to register for a course that is full, she should be placed at the end of the wait list. If a student drops the course, the student currently at the beginning of the wait list should be moved into the class.

Question 20 options:

list

stack

queue

priority queue

Question 21 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to play a card game, and you need to keep track of the discard pile. When a player discards a card, it is placed at the top of the discard pile. If a player wants to pick up a card from the discard pile, she must take the card that is currently on the top.

Question 21 options:

list

stack

queue

priority queue

Question 22 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to help the human resource department of a company in scheduling interviews. As applications come in, the hiring manager gives them a score from 0 to 100 according to how well the applicant appears to fit the needs of the position. After a period of two weeks, interviews need to be scheduled. You need a data structure to tell the HR employee which applicant should next be scheduled for an interview. The choice is based on the applicant with the highest score.

Question 22 options:

list

stack

queue

priority queue

Question 23 (1 point)

Which of these data structures is the best choice in the following situation? You are writing a program to track various statistics for the players on the active roster of a baseball team. The order in which the players are stored is not important, but you will frequently need to iterate over all of the players to compute aggregate statistics for the team.

Question 23 options:

list

stack

queue

priority queue

Question 24 (1 point)

What is the output of the following code?

public class Widget implements Cloneable {

public int count;

public FiddlyBit bit;

public Widget() {

bit = new FiddlyBit();

}

public Object clone() throws CloneNotSupportedException {

  return super.clone();

}

public String toString() {

  return "count = " + count + "; bit part number = " + bit.partNo;

}

class FiddlyBit {

  int partNumber;

}

public static void main(String[] args) {

Widget widgetA = new Widget();

widgetA.count = 5;

widgetA.bit.partNo = 111;

Widget widgetB = (Widget) widgetA.clone();

widgetB.count = 6;

widgetB.bit.partNo = 222;

System.out.println("widgetA: " + widgetA);

System.out.println("widgetB: " + widgetB);

}

}

Question 24 options:

widgetA: count = 5; bit part number = 111;
widgetB: count = 6; bit part number = 222;

widgetA: count = 6; bit part number = 222;
widgetB: count = 6; bit part number = 222;

widgetA: count = 6; bit part number = 111;
widgetB: count = 6; bit part number = 222;

widgetA: count = 5; bit part number = 222;
widgetB: count = 6; bit part number = 222;

Question 25 (1 point)

Which of the following is valid, assuming myPetStore is an instance of PetStore? Choose all that apply.

public interface Animal { 
 public abstract void eat();
} 

public class Pet implements Animal { 
 public void eat() { 
  System.out.println("Eating pet food"); 
 }
} 

public class Dog extends Pet { 
}

public class PetStore { 
 public void feedingTime(Animal a) { 
  a.eat(); 
 }
}

Question 25 options:

Animal anAnimal = new Animal();myPetStore(anAnimal);

Pet aPet = new Pet();myPetStore(aPet);

Dog aDog = new Dog();myPetStore(aDog);

None of these are valid

Previous PageNext Page

Solutions

Expert Solution

Hi,

Please find the below answers according to problem statement.

Q17. Comparable

Because <E extends Comparable<E>> is a upper bounded wildcard which represents wildcard character (‘E’), followed by the extends keyword, followed by its upper bound.

Q18. Generic classes and methods are more type-safe

The basic purpose of generics in java is to achieve type safety and to avoid type casting.

Q19. The method calls clone on the argument, but that method is not guaranteed to exist for the argument.

Q20. Queue data structure will be suite in this particular situtation. becuase queue uses first in first out.

Q21. Stack data structure will suits in this particular situation. becuase Stack uses last in first out.

Q22. In this scenario Priority Queue data structure will be helpful. because In a priority queue, elements can be inserted in any order but removal of the elements is in a sorted order.

Q23.List data structure can be used here because in list insertion of elements can be done in any order.

Q24.

widgetA: count = 5; bit part number = 222;
widgetB: count = 6; bit part number = 222;

Q25. Pet aPet = new Pet();myPetStore(aPet);

Dog aDog = new Dog();myPetStore(aDog);

These two are the valid ones. becuase Pet is sub class of Animal and Dog is a subclass of Pet. So both can use Petstore.

I hope this helps you!!

Thanks!!


Related Solutions

(Sort ArrayList) Write the following method that sorts an ArrayList:   public static <E extends Comparable<E>> void...
(Sort ArrayList) Write the following method that sorts an ArrayList:   public static <E extends Comparable<E>> void sort(ArrayList<E> list) Write a program to test the method with three different arrays: Integers: 2, 4, and 3; Doubles: 3.4, 1.2, and -12.3; Strings: "Bob", "Alice", "Ted", and "Carol"
(Sort ArrayList) Write the following method that sorts an ArrayList: public static <E extends Comparable<E>> void...
(Sort ArrayList) Write the following method that sorts an ArrayList: public static <E extends Comparable<E>> void sort(ArrayList<E> list) Write a program to test the method with three different arrays: Integers: 2, 4, and 3; Doubles: 3.4, 1.2, and -12.3; Strings: "Bob", "Alice", "Ted", and "Carol" This program is similar to the Case Study in the book: Sorting an Array of Objects the language is in java
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T...
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T extends Comparable<T>>    void swap(T[] data, int index1, int index2)    {       T temp = data[index1];       data[index1] = data[index2];       data[index2] = temp;    }    public void sort(T[] data)    {       int position, scan;       for (position = data.length - 1; position >= 0; position--)       {          for (scan = 0; scan <= position - 1; scan++)          {...
How do I implement public class CircularArrayQueue<E> extends AbstractQueue <E> and test the methods with junit?
How do I implement public class CircularArrayQueue<E> extends AbstractQueue <E> and test the methods with junit?
Discuss the “Comparison” or “Comparable” type of approach to value property and what type of property?
Discuss the “Comparison” or “Comparable” type of approach to value property and what type of property?
Question 11 (1 point) What is wrong with the following recursive method, which is meant to...
Question 11 (1 point) What is wrong with the following recursive method, which is meant to compute the sum of all numbers from 1 to n? public int summation(int n) { return n + summation(n-1);} Question 11 options: The method lacks a base case The method lacks a recursive step The base case is incorrect The recursive step is incorrect Question 12 (1 point) In which of these situations does it make sense to consider a recursive solution? Question 12...
analysis line 17 to 21 RATIOS ANALYSIS Management Effectiveness (%) E. commerce Amazon EBay 17) Return...
analysis line 17 to 21 RATIOS ANALYSIS Management Effectiveness (%) E. commerce Amazon EBay 17) Return On Assets 7.16% 7.34% 8.61% 18) Return On Investment 9.71% 11.66% 10.41% 19) Return On Equity 15.72% 21.12% 34.55% Dividends     20) Dividend Yield 17.20% 0 1.39% 21) Payout Ratio 0.02% 0 12.60%
1. Explain that auditor’s public interest responsibility including the source of their responsibility they extends to...
1. Explain that auditor’s public interest responsibility including the source of their responsibility they extends to which they embrace this responsibility & tangible ways that entry-level auditors can embrace this responsibility? 2. Explain the concept of professional skepticism including its underlying attributes and in addition to describing the different approaches to professional skepticism and how they are used in audit? 3. Applied question(use example):1. Use of example of testing revenue explain the steps and performance of standard analytical produces 2....
Question 11 (1 point) Which of the following are early mediators of type I hypersensitivity? Question...
Question 11 (1 point) Which of the following are early mediators of type I hypersensitivity? Question 11 options: histamines, prostaglandins, IL-4, serotonin, altered phospholipids histamines, prostaglandins as well as eosinophil chemotaxins, serotonin histamines, prostaglandins, cytokines, serotonin leukotrienes, platelet activating factors, histamines, prostaglandins Question 12 (1 point) An example of a type I hypersensitivity reaction is Question 12 options: an allergic reaction to the gold in a ring the allergic reaction to peanuts a transfusion reaction the allergic reaction to poison...
Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1");...
Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1"); super.method2(); } public void method2() { System.out.println("Bay 2"); } } //********************************* class Pond { public void method2() { System.out.println("Pond 2"); } } //************************** class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } //********************************* class Lake extends Pond { public void method3() { System.out.println("Lake 3"); method2(); } } //**************************** class Driver { public static void main(String[] args) { Object var4 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT