Uploaded by sxcmain

ProgrammingAssignment3 SocialMediaFeed2

advertisement
Social Media Feed
Overview
The goal of this assignment is to create the set of classes given in the UML class diagram
above. This project simulates a basic social media feed window that can display text and
images. The PNG image of the diagram above is included in the zip file for this assignment.
There is a zip file containing several items provided for you. They are:
1. Main class
2. Window class - a graphical user interface class, we will learn these later in the class
3. Resources folder
4. PostGenerator class
5. PNG image of the UML diagram
Main class
The Main class has a set of instructions for you to complete. If you follow the instructions, then
you should see a window pop up and show you the text posts and images when you run the
project.
Window class
The Window class provides a visual representation of the posts that are created. Do not
change the Window class. If your project is set up correctly, then everything will compile and
when you run the project a window will appear to display the posts in the feed.
The window that will be displayed looks something like the following:
Resources folder
The resources folder contains the images and text that make up the posts in this project. Do not
delete anything from this folder. If you want to add more possible pictures, then you can add
the images to the “images” folder and add a caption to the caption.txt file. Each line of
caption.txt corresponds to an image in the folder in alphabetical order. If you want to add texts,
then add lines to the “text_posts.txt” file.
PostGenerator class
The purpose of this class is to generate random posts. Part of this class is given to you, and the
rest will be implemented by you. The fields, getter+setters, and constructor are given to you.
The constructor will read all the images, captions, and texts from the files in the resources folder
into the fields images, captions, and texts.
You will need to finish implementing this class. Refer to the UML class diagram above to see
the list of methods that you should implement. Each post should have the following randomized:
● Type (image or text).
● Date and time
● Content
○ If it’s an image post, then it should have a randomly selected image to display
(remember to grab the correct caption!).
○ If it’s a text post, then it should have a randomly selected sentence to display.
● User
In the end, when you run the project you should see the window that displays a number of
randomized posts. Since they are random, the posts should be different each time.
Miscellaneous
ImagePost
● You will need “import java.awt.Image;” in the ImagePost class to have access to the
Image class.
PostGenerator
● The images and captions go together. When selecting a random image use the same
index to select the corresponding caption.
● There is code below you can use to get an image. The variable “i_image” is a random
integer in range [0, images.length].
Image myImage = null;
try {
BufferedImage myPicture = ImageIO.read(images[i_image]);
myImage = myPicture.getScaledInstance(100, 100, Image.SCALE_DEFAULT);
}
catch(IOException ex)
{
ex.printStackTrace();
}
Download