April 20th, 2017, 02:41 PM
Need assistance with Java lab
Here are the details of what I need to accomplish, and this lab requires the use of arrays:
• a public constructor that takes a Scanner as its only parameter. The Scanner represents an input stream deﬁning up to 100 Mugs, each of which must be placed in a collection of Mugs. The Mug class also contains a constructor to build a single Mug out of a Scanner - it is highly advisable that you utilize such!
• A method called write that takes a single String parameter and returns nothing. The parameter represents the ﬁle name of a ﬁle to write the contents of the collection into. Don’t forget to close the associated ﬁle when done writing into it. Also, don’t forget that the Mug class provides you with a toString method.
• A toString method that takes no parameters and returns a String. This method should return a String that contains each of the Mugs in the current collection, preceded by a sequence number (i.e. the corresponding index number from the array holding the Mugs). Don’t forget that Mug also has a toString method that you might ﬁnd useful.
• A method called sortByAge that returns nothing and takes no parameters. This method should re-arrange the collection so that the oldest Mug (by age) is at the bottom of the collection, and the youngest Mug (by age) is at the top of the a collection. All other elements should be in sorted order between those two Mugs. Don’t forget that Mug has a getAge
method in it.
• A method called sortByPopularity that returns nothing and takes no parameters. This method should re-arrange the collection so that the collection is sorted from most popular (largest popularity) to least popular (smallest popularity), top to bottom. Don’t forget that Mug has a getPopularity method in it.
• A method called age that returns nothing and takes no parameters. This method should add 1 (one) to the age value for every Mug in the collection. Don’t forget that the Mug class has an incAge method.
• A method called use that returns nothing and takes one integer parameter representing the index number of a Mug within the current sorted order of the collection. This method should add one to the corresponding Mug in the collection.
Any tips on how to start this lab and set me in the right direction? (I am new to arrays and need a good understanding of them)
April 20th, 2017, 06:44 PM
Re: Need assistance with Java lab
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!