subject

Write a generic class called Bag. It should have three methods as follows: The add method should take in two generic values and save them into the theoretical bag, returning nothing from the method. The contains method should take the second type of generic parameter, and return whether or not that value is located in the theoretical bag. The isEmpty method should take no parameters and return true if the bag is empty, and false otherwise. For example, the class should support the following behavior:

Bag bag1 = new Bag();
Bag bag2 = new Bag();
Bag bag3 = new Bag();

bag1.add( 20, 92 );
bag2.add( 20, "A-" );
bag3.add( "B", 84.5 );

// prints false
System. out. printf( "Bag 1 is empty? %s\n", bag1.isEmpty() );
// prints false
System. out. printf( "Found B in bag 2? %s\n", bag2.contains("B") );
// prints true
System. out. printf( "Found 84.5 in bag 3? %s\n", bag3.contains(84.5) );

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 18:00, roudjinapierre214
Amara created a workbook to track the number of minutes she reads each week. each day, she entered the number of minutes into the workbook. identify the types of data in the workbook using the drop-down menus.
Answers: 3
image
Computers and Technology, 23.06.2019 07:00, bskyeb14579
Why is investing in a mutual fund less risky than investing in a particular company's stock? a. mutual funds only invest in blue-chip stocks. b. investments in mutual funds are more liquid. c. mutual funds hold a diversified portfolio of stocks. d. investments in mutual funds offer a higher rate of return.
Answers: 2
image
Computers and Technology, 23.06.2019 17:00, quanharris2k19
The camera still is bad even with the new iphone xr and especially in low light it is even worst because you can see the pixels more if its in low light. if all you apple customers want apple to fix this then lets fill there feedback with complaints about the
Answers: 1
image
Computers and Technology, 23.06.2019 17:00, ayoismeisjjjjuan
The camera still is bad even with the new iphone xr and especially in low light it is even worst because you can see the pixels more if its in low light. if all you apple customers want apple to fix this then lets fill there feedback with complaints about the can apple do to fix this issue?
Answers: 1
You know the right answer?
Write a generic class called Bag. It should have three methods as follows: The add method should tak...

Questions in other subjects:

Konu
Social Studies, 15.03.2022 07:50