Assignment 1- Classes, Object, Constructor and Getter/Setter, Encapsulation
In this experiment, you are supposed to develop a simple Journal System program. The main aim of the experiment is to develop your skill of using Class, Object, Constructor, Getter/Setter, and Encapsulation with Java programming language.
2 General Information
In this section you can find some useful beginners level information that you will need for this project. For more information on each subject you need to do additional research and consult other resources (e.g. lecture notes, textbook, Internet resources, etc.).
Object-oriented programming (OOP) is more than just adding a few new features to programming languages. It is rather a new way of thinking about decomposing and modeling problems with less complexity and more code reuse when developing programming solutions. In OOP, a program is viewed as a collection of loosely connected objects, each of which is responsible for specific tasks. It is through the interaction of these objects that computation proceeds and the model works as a whole.
In this assignment, you will work with the concepts of OOP in order to practice them and observe their advantages. With this assignment, you will learn the concepts of relationships among classes, encapsulation.
2.1 Encapsulation
Encapsulation is one of the fundamental OOP concepts. It is a technique of wrapping (packaging) the related data (attributes) and behavior (code methods) together into a single unit. It also provides a way to hide and control data by protecting it from misuse by the outside world. This is achieved by making data members private, and using public helper methods through which we can decide the level of access we want to provide (e.g. read-only, write-only). A fully encapsulated Java class is a class whose all variables are private.
The advantages of encapsulation include: flexibility in modifying code in case requirements change, reusability of encapsulated code throughout multiple applications if necessary, and reducing the time of maintenance (update) process.
2.1.1 Visibility Modifiers
In Java, there are four access modifiers which provide various access levels: private (visible inside of the class only), default/package (visible inside of the package), protected (visible inside the package and to all subclasses) and public (visible to everyone).
3 Problem
You will write a Journal System application. You will use the given corpus in order to list articles which belong to Authors. Also you will complete Authors articles by using article file.
General Rules:
- An author has maximum 5 articles.
- An article ids first 3 characters equal to an author id.
Your program should read the following three files: article file, author file and command file. Java provides a rich API for input/output (I/O) operations. In this experiment you will use I/O (Input/Output) classes of Java to perform file operations.
4 Input File Format
- Author File (author.txt): Each line starts with AUTHOR string and author id. The others are optional. An author has 10 attributes which are id, name, university, department, email, article#1, article#2, article#3, article#4 and article#5. All attributes of the Author must be private Java access modifier.
Figure 1: A class structure for the Author file
Figure 2: Sample Author File
- Article File (article.txt): Each line starts with ARTICLE string. An article has 4 attributes which are paper id, name, publisher name and year of publish. All attributes of Article must be private Java access modifier.
Figure 3: A class structure for the Article file
Figure 4: Sample Article File
- Command File (command.txt): Your program should be able to process and respond to 5 different commands, which are defined below. You will take these commands from an input file (command.txt), according to commands, show the output to the output file (output.txt). The name of the input files (author.txt and command.txt) and output file (output.txt) will be fixed. So, please be careful about not to taking these files with a different name.
Figure 5: Sample command.txt
Now, we go through all the lines of the sample command.txt with the following commands:
COMMAND-1: read articlefilename: The Journal System will read the article file and add articles to the end of the article array which stores article objects. You dont need to print anything to the output file for this command. The output should be as shown in Figure 6 when performing line 2 (command-2: (list)) after line 1 (command-1: (read article1.txt)) from sample command.txt as shown in Figure 5.
Figure 6: Output format for read article1.txt and list commands
COMMAND-2: list: The Journal System will show authors and authors article(s) in the following format. The outcome of this command will be printed out on output file (the name of the output file will be fixed as output.txt). This command always comes after the other four commands (command-1, command-3, command-4, and command-5).
Figure 7: Output format for list command
COMMAND-3: completeAll: We have mentioned that an author has max 5 articles in Section 3. So, by this command, the Journal System will complete articles of the Authors, who have less than 5 articles, with considering article paper id. When performing completeall command, you will going through the article.txt file, and check the missing articles according to the article id for each author, and complete his/her articles to the 5 articles. The output should be as shown in Figure 8 when performing line 4 (command-2: (list)) after line 3 (command-3: (completeAll)) from sample command.txt as shown in Figure 5.
Figure 8: Output format for completeAll and list commands
COMMAND-4: sortedAll: print articles which are sorted in ascending order according to article paper id. After performing the line 5 (command-4) and line 6 (command-2) from sample command.txt as given in Figure 5 respectively, the output for this command should be as given in figure 10.
Figure 9: Output format for sortedAll and list commands
COMMAND-5: del authorid: This command deletes the corresponding author, which is given with its id, and all its attributes. This operation will be done regarding author id. del 100 means that delete the author whose id is equal 100, and list the updated version of the array. After performing the line 7 (command-5) and line 8 (command-2) respectively from sample command.txt as shown in Figure 5, the output should be as given in Figure 10.
Figure 10: Output format for del and list commands
5 Output Format
The output format and an exemplar output example are given in Figure ??.
Figure 11: Sample output format
Output of the program will be as shown below:
-List
Author:100 Olivier_Duchenne MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1002007 Variational_Stereo_in_Dynamic_Illumination ICCV 2012
+1002012 Source_Constrained_Clustering ICCV 2012
+1002018 Content-Based_Photo_Quality_Assessment CVPR 2013
Author:101 Ruonan_Li MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002009 A_Theory_of_Coprime_Blurred_Pairs ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012 Author:102 Horst_Bischof HUN Computer_Engineering [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
Author:103 Pietro_Perona METU Computer_Science [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1032019 HEAT:Iterative_Relevance_Feedback_with_One_Million_Images CVPR 2013
Author:104 Nadia_Payet METU Computer_Engineering [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1042020 Unsupervised_Learning_of_a_Scene-Specific_Coarse_Gaze_Estimator CVPR 2013
+1042010 Learning_to_Predict_the_Perceived_Visual_Quality_of_Photos ICCV 2012
+1042008 Revisiting_Radiometric_Calibration_for_Color_Computer_Vision ICCV 2012
Author:105 Blake_Johnson HARVARD Computer_Science [email protected]
End
**************************CompleteAll Successful*******************
List
Author:100 Olivier_Duchenne MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1002007 Variational_Stereo_in_Dynamic_Illumination ICCV 2012
+1002012 Source_Constrained_Clustering ICCV 2012
+1002018 Content-Based_Photo_Quality_Assessment CVPR 2013
Author:101 Ruonan_Li MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002009 A_Theory_of_Coprime_Blurred_Pairs ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1012013 Inferring_Social_Relations_from_Visual_Concepts ICCV 2013
+1012014 Maximizing_All_Margins:Pushing_Face_Recognition_with_Kernel_Plurality CVPR 2013
Author:102 Horst_Bischof HUN Computer_Engineering [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1022002 Domain_Adaptation_for_Object_Recognition:An_Unsupervised_Approach ICCV 2012
+1022005 Non-stationary_Correction_of_Optical_Aberrations ICCV 2012
+1022015 DTAM:Dense_Tracking_and_Mapping_in_Real-Time CVPR 2013
+1022016 Kernel_Non-Rigid_Structure_from_Motion CVPR 2013
Author:103 Pietro_Perona METU Computer_Science [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1032019 HEAT:Iterative_Relevance_Feedback_with_One_Million_Images CVPR 2013
+1032003 Decision_Tree_Fields ICCV 2012
+1032011 HMDB:A_Large_Video_Database_for_Human_Motion_Recognition ICCV 2012
+1032017 A_Dimensionality_Result_for_Multiple_Homography_Matrices CVPR 2013
Author:104 Nadia_Payet METU Computer_Engineering [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1042020 Unsupervised_Learning_of_a_Scene-Specific_Coarse_Gaze_Estimator CVPR 2013
+1042010 Learning_to_Predict_the_Perceived_Visual_Quality_of_Photos ICCV 2012
+1042008 Revisiting_Radiometric_Calibration_for_Color_Computer_Vision ICCV 2012
+1042006 Linear_stereo_matching ICCV 2012
Author:105 Blake_Johnson HARVARD Computer_Science [email protected] End-
*****************************SortedAll Successful********************* List-
Author:100 Olivier_Duchenne MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1002007 Variational_Stereo_in_Dynamic_Illumination ICCV 2012
+1002012 Source_Constrained_Clustering ICCV 2012
+1002018 Content-Based_Photo_Quality_Assessment CVPR 2013
Author:101 Ruonan_Li MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1002009 A_Theory_of_Coprime_Blurred_Pairs ICCV 2012
+1012013 Inferring_Social_Relations_from_Visual_Concepts ICCV 2013
+1012014 Maximizing_All_Margins:Pushing_Face_Recognition_with_Kernel_Plurality CVPR 2013
Author:102 Horst_Bischof HUN Computer_Engineering [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1022002 Domain_Adaptation_for_Object_Recognition:An_Unsupervised_Approach ICCV 2012
+1022005 Non-stationary_Correction_of_Optical_Aberrations ICCV 2012
+1022015 DTAM:Dense_Tracking_and_Mapping_in_Real-Time CVPR 2013
+1022016 Kernel_Non-Rigid_Structure_from_Motion CVPR 2013
Author:103 Pietro_Perona METU Computer_Science [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1032003 Decision_Tree_Fields ICCV 2012
+1032011 HMDB:A_Large_Video_Database_for_Human_Motion_Recognition ICCV 2012
+1032017 A_Dimensionality_Result_for_Multiple_Homography_Matrices CVPR 2013
+1032019 HEAT:Iterative_Relevance_Feedback_with_One_Million_Images CVPR 2013
Author:104 Nadia_Payet METU Computer_Engineering [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1042006 Linear_stereo_matching ICCV 2012
+1042008 Revisiting_Radiometric_Calibration_for_Color_Computer_Vision ICCV 2012
+1042010 Learning_to_Predict_the_Perceived_Visual_Quality_of_Photos ICCV 2012
+1042020 Unsupervised_Learning_of_a_Scene-Specific_Coarse_Gaze_Estimator CVPR 2013
Author:105 Blake_Johnson HARVARD Computer_Science [email protected]
-End
*************************del Successful************************************
-List-
Author:101 Ruonan_Li MIT Computer_Science [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1002009 A_Theory_of_Coprime_Blurred_Pairs ICCV 2012
+1012013 Inferring_Social_Relations_from_Visual_Concepts ICCV 2013
+1012014 Maximizing_All_Margins:Pushing_Face_Recognition_with_Kernel_Plurality CVPR 2013
Author:102 Horst_Bischof HUN Computer_Engineering [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1022002 Domain_Adaptation_for_Object_Recognition:An_Unsupervised_Approach ICCV 2012
+1022005 Non-stationary_Correction_of_Optical_Aberrations ICCV 2012
+1022015 DTAM:Dense_Tracking_and_Mapping_in_Real-Time CVPR 2013
+1022016 Kernel_Non-Rigid_Structure_from_Motion CVPR 2013
Author:103 Pietro_Perona METU Computer_Science [email protected]
+1002004 From_Contours_to_3D_Object_Detection_and_Pose_Estimation ICCV 2012
+1032003 Decision_Tree_Fields ICCV 2012
+1032011 HMDB:A_Large_Video_Database_for_Human_Motion_Recognition ICCV 2012
+1032017 A_Dimensionality_Result_for_Multiple_Homography_Matrices CVPR 2013
+1032019 HEAT:Iterative_Relevance_Feedback_with_One_Million_Images CVPR 2013
Author:104 Nadia_Payet METU Computer_Engineering [email protected]
+1002001 A_Graph-matching_Kernel_for_Object_Categorization ICCV 2012
+1042006 Linear_stereo_matching ICCV 2012
+1042008 Revisiting_Radiometric_Calibration_for_Color_Computer_Vision ICCV 2012
+1042010 Learning_to_Predict_the_Perceived_Visual_Quality_of_Photos ICCV 2012
+1042020 Unsupervised_Learning_of_a_Scene-Specific_Coarse_Gaze_Estimator CVPR 2013
Author:105 Blake_Johnson HARVARD Computer_Science [email protected]
6 Execution and Test
The input files are going to be given as program arguments. There are text files (article.txt, author.txt, command.txt) in your working directory. In order to test your program, you should follow the following steps:
- Upload your java files to your server account (dev.cs.hacettepe.edu.tr)
- Compile your code (javac *.java)
- Run your program (java Main author.txt command.txt)
- Control your output data (output.txt).
Reviews
There are no reviews yet.