Watch This Video
------------------------------------------------------------------------------------------------[Exercise] Create Your own Class
In this exercise you are going to create your own class and start to think about what your class would contain. There is no 1 correct answer for this. Follow the rules and see what you come up with.
Create a class called Tweet
Add properties to this class.
What properties would be present in a class that holds information about a tweet
Think about what their data types would be
What methods would go in this class?
How about a constructor to create a new tweet.
How about methods to change some of your properties?
How about a toString method (or AST Transformation)
Create a script called Twitter.
In this script create one or more Tweets.
print the Tweet instances to the console (and have their string representations shown)
Bonus
Create a file called Tweet.groovy.
Inside this file create a class called Tweet (the one you created above)
@groovy.transform.ToString
class Tweet{
String username
String text
Integer retweets
Integer favorites
Date createdOn
public Tweet(String user, String tweet){
username=user
text=tweet
retweets=0
favorites=0
createdOn=new Date()
}
void addToRetweets(){
retweets=+1
}
void addToFavorite(){
favorites=+1
}
def whatsapp =new whatsapp("sudheer","Helomsg")
print whatsapp
No comments:
Post a Comment
Note: only a member of this blog may post a comment.