Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I need help solving my question in my homework

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Thanked 0 Times in 0 Posts

    Question I need help solving my question in my homework

    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.
    Storing Data

    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
    Authors: {author1}
    Published: true

    First Name: "John"
    Last Name: "Doe"
    Date Hired: GregorianCalendar object storing 1994-12-01
    Article Count: 22

    should return
    "News is good\tAccording to scientists...\t1995-01-01 07:19AM\tJohn\tDoe\tyes\n
    should return
    Main class

    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).

    Project Turn-in

    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

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 632 Times in 540 Posts

    Default Re: I need help solving my question in my homework

    What's your question?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Homework Question Help
    By zng690 in forum Object Oriented Programming
    Replies: 2
    Last Post: January 28th, 2014, 06:46 AM
  2. Homework question having to do with arrays...
    By TheoAnderson in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 3rd, 2013, 12:55 PM
  3. [SOLVED] Homework Question
    By EPC in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 24th, 2013, 12:33 PM
  4. Question about homework problem.
    By Rain_Maker in forum Java Theory & Questions
    Replies: 13
    Last Post: February 7th, 2013, 07:11 PM
  5. need help solving this question asap plzzzzzzzzzz
    By rana_marie in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 17th, 2012, 09:43 AM