Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which...

50.1K

Verified Solution

Question

Programming

Java Language

-Create a project and a class with a main method,TestCollectors.

-Add new class, Collector, which has an int instance variablecollected, to keep track of how many of something they collected,another available, for how many of that thing exist, and a booleancompletist, which is true if we want to collect every itemavailable, or false if we don't care about having the completeset.

-Add a method addToCollection. In this method, add one tocollected and report the new value. If after this we have collectedall the available items, print a congratulatory message.

-Write a toString for this class as follows:

If there are more objects collected than are available, theresult should be something like

an overflowing collection with 20 out of 15 items

if there are exactly the same number collected as available

a perfect collection with 15 out of 15 items

if there are fewer collected than are available, it dependswhether we are being completist, so either

a sadly incomplete collection with 10 out of 15 items

or

a collection with 10 out of 15 items

[EC +10] Actually, if the number available is 0, no matter howmany are collected, the result should be

not really a collection at all

adjust your toString accordingly

In your main, create several Collectors with different valuesand check that their toStrings come out correctly

[EC+20]

-Add a new (different from part A) class with a main. In main,ask the user for a value for each of three int variables x, y, andz.

-Using conditionals and nesting/else-if, print the three intsback out in decreasing order. (You can ignore the casewhere two numbers are the same)

So whether you were given 2, 1, 3, or 1,2,3 or 3,1,2, you'dprint out 3, 2, 1.

You may add extra variables (i.e. small, med, and large) if youwish.

Make sure you test all possible orders for the threenumbers.

Answer & Explanation Solved by verified expert
3.8 Ratings (452 Votes)
PARTAclassclass Collector3 instance variableint collectedint availableboolean completistconstructor to set collected available completist value for thecollector class objectpublic Collectorint cint a boolean compsetting 2 instnace variable to the respective parameterscollectedcavailableacompletistcompfunction addTo Collectionvoid addToCollectionadd 1 to collectedcollectedcollected1if collected availableifcollectedavailableprint conratulatory messageSystemoutprintlnCongratulation you have collected allavailable itemstoString methodpublic String toStringif available is 0 thenifavailable0return not really a collection at allreturn this stringIf there are more objects collected than are availableelse if    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students