Need assistance with Java lab
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Need assistance with Java lab

  1. #1
    Join Date
    Apr 2017
    Posts
    1

    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 defining 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 file name of a file to write the contents of the collection into. Don’t forget to close the associated file 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 find 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)

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,733

    Re: Need assistance with Java lab

    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)