I have this question in my homework if there anyone tell me how to solve it step by step
Update March 22: If you used JUnit test cases to test your code, you can simply mention that in your memo.txt instead of telling me in detail how you tested.
Your New Life in the Newspaper 'Biz
Congratulations, you just got a new job working in the IT Department at the Boston Globe! Unfortunately, you've also been transported back in time to 1995 and the newspaper industry is still very antiquated. Right now, the IT Dept. consists of you and your boss, Barry, who's a self-proclaimed "ideas guy." Barry tells you that the Globe needs a way to start storing electronic records of their articles, in case "this whole internet thing catches on."
The two most important pieces of data for you to store are the articles written by the Globe (Articles), and a personnel record for the authors of the articles (Authors). In order to store electronic records of articles at the Globe, you'll need to first write two Java classes, Article and Author.
The Article Class
There are several fields which maintain the state of an Article:
The Article's title
The body of the Article
A list of Authors that contributed to the Article
A publication date
Some indicator that tells whether the article has been published yet
You should construct your Article class to contain fields that can adequately store each of these different fields, using an appropriate data type. In addition to storing these fields, an Article has behavior defined by the following interface -
public String getTitle();
public void setTitle(String title);
public String getBody();
public void setBody(String body);
public Author getAuthors(); // as discussed in class, easier to change authors field to an ArrayList<Author>
public void addAuthor(Author author);
public GregorianCalendar getPublicationDate();
public void setPublicationDate(GregorianCalendar date);
public boolean isPublished();
public void setPublished(boolean published);
This interface should tell you exactly what data type you should use for each field in this class.
The GregorianCalendar class is new for us. This class is one of the ways that Java allows us to store dates/times. The API for this class is defined in the documentation. You'll want to store article publication dates down to the minute, i.e. say that an article was published at 7:19AM on January 1, 1990 (don't worry about timezones).
To create a new Article object, you should be able to pass in a value for the title only (as a sort-of "place-holder" Article), or pass in values for all of the fields in the Article. Thus, you will need to provide two different constructors in this class.
The Author Class
The state of an Author is defined by the following fields:
The Author's first name
The Author's last name
The date the author was hired
The number of Articles the Author has contributed to.
The interface for the author class looks like this:
public String getFirstName();
public void setFirstName(String firstName);
public String getLastName();
public void setLastName(String lastName);
public GregorianCalendar getDateHired();
public int getArticleCount();
public void setArticleCount(int amount);
Note that you cannot set the hire date of an Author once that Author object is created. The constructor for the Author class should take a first name, last name, and hire date of the author. The article count of an Author should be 0 by default. The hire date for an Author should be accurate to the year, month and day.
Your boss, Barry, thinks that the best way for you to store data is in tab-separated CSV files. Thus, you need to add a method to both the Author and Article classes called "toRecord" which returns a tab-delimited String representation of each of these two types of objects. Each of these Strings will be like a row in our CSV-backed "database". Let's say we have an Article article1 and Author author1 with the following states:
Title: "News is good"
Body: "According to scientists..."
Publication Date: GregorianCalendar object storing 1995-01-01 07:19AM
First Name: "John"
Last Name: "Doe"
Date Hired: GregorianCalendar object storing 1994-12-01
Article Count: 22
"News is good\tAccording to scientists...\t1995-01-01 07:19AM\tJohn\tDoe\tyes\n
In addition to your Article.java and Author.java files, you'll want to write a third class called Data.java, which should use both Articles and Authors. This class will have a main method, inside of which you should create 3 Authors and 3 Articles. At least one Article should have multiple authors. After creating these objects, you should print out the data representation of each using your toRecord() method (this will demonstrate how a CSV-backed database could be constructed to store these records).
You need to turn in 3 .java files (Article, Author and Data). You also should provide a plain text file called "memo.txt", which should contain a narrative describing how you went about designing and implementing these requirements, how you tested your program, and a copy-and-pasted result for your tests. If you used JUnit test cases to test your code, you can simply mention that in your memo.txt instead of telling me in detail how you tested. Create a subdirectory called "p2" (lowercase) in your it115 subdirectory on your Unix account, and transfer a copy of your resulting Java files and memo.txt there. Final delivery files:
Any unit test files