Question: JAVA - create two classes: TwitterUser and TestTweetSorting. TwitterUser is a class representing a Twitter user and has the following attributes: username ( String )
JAVA create two classes: TwitterUser and TestTweetSorting.
TwitterUser is a class representing a Twitter user and has the following attributes:
username String
tweetCount int
We need to be able to create objects instances of TwitterUsers with differing usernames
and tweet counts.
Part
Create the classes
Create the TwitterUser class with a constructor that accepts the two different arguments.
Add a toString implementation that yields a String containing the username and
tweetCount values.
Create a TestTweetSorting class with a main
Create an Array of TwitterUsers and fill it with at least four different users with varying
tweet counts.
Iterate over the Array and print out the toString result of each TwitterUser to
System.out.
Part
Add sorting by tweet count functionality using the Comparable interface. The sorting
method should sort by the number of tweets in ascending order. Modify your
TestTweetSorting class to sort the TwitterUsers you already created using Arrays.sort prior to
printing the array as you did in Part above.
Please explain how the Comparable interface is implemented.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
