程序代写案例-COSI 12B-Assignment 3

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
COSI 12B Summer 2021 – Advanced Programming Techniques
Programming Assignment 3
Objective:
• Create client code using a provided library
Create a new library
• Use global constants
• Generate Javadocs
Overview:
The assignment has three parts: (1) you will create a client program called Birthday that
prompts a user for their birthdate and uses a provided TeacherDate class to generate some
statistics based on the birthdate, (2) you will create your own version of the TeacherDate class
called Date and re-configure your Birthday code to use Date instead of TeacherDate writing
good quality Javadoc commentaries in the process, and (3) you will generate good quality
Javadoc comments so that users of your Date class will have a better manual than the one you
received with TeacherDate.
Intro to Javadoc:
JavaDoc is a generator that creates Application Programming Interface (API) documentation in
HTML format. The “doc format” is the de-facto industry standard for Java documentation.

Doc Format

/**

*/

Doc Comment Structure

1st paragraph: general description
2nd paragraph (optional): longer description if 1st paragraph was a one-liner
3rd paragraph+ (optional): “tags” that label / classify the description:
• @param: parameters of the method
• @return: return value of a method
• @throws: exceptions the method may throw
• @author: who wrote the class / interface

for more see: https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#tag

Note: JavaDoc comments must be place immediately before the code they are documenting.
Why JavaDocs?

Ease of:
• documentation creation
• documentation maintenance
• distribution of documentation
• code reuse since all documentation is standardized
• navigation within documentation because of cross hyperlinking

Examples of Doc Comments

Example of the file header

/**
* TeacherDate class is used for manipulating dates.
*


* This class was written for one of the Programming Assignments
* (PAs)in COSI 12B at the Brandeis University Department of
* Computer Science.
*
* @author Unknown
* @author Antonella Di Lillo
* @author Michael Golitsyn
* @version 1202v1
* @since 1103
*/

Example of the method

/**
* Constructs a new TeacherDate object representing the given year,
* month, and day.
*
* @param year integer year according to the Gregorian calendar
* (assumes that the year will be greater than or equal
* to 1752, the year of creation of the Gregorian calendar)
* @param month integer month of the year (assumes 0 – 12)
* @param day integer day of the month (assumes valid number)
*/
public TeacherDate(int year, int month, int day){
...
}

Learn more at: https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html

Intro to Global Constants:

A global constant represents a value that does not change throughout the execution of the
program. Global constants are defined at the top of the class using modifiers static final. The
global constants are named in ALL_CAPS and can either be private or public depending on your
needs.
The rule of thumb: whenever you are using an actual (hard-coded) number in your code that is
not self-evident, or you are using the same hard-coded number more than once you should
consider replacing it with a global constant named in such a way that:
• it makes the code easier to understand and
• there is only one place that needs to be changed if the constant need to be changed in the
next version of the program
Example 1

Instead of:
for (int i = 0; i<12; i++} {…
You write:
public static final int NUM_OF_MONTHS_IN_YEAR = 12;

for (int i = 0; i < NUM_MONTHS_IN_YEAR; i++} {…

Example 2

Instead of:
for (int i = 0; i<4; i++} {…
You write:
public static final int NUM_OF_PLAYERS = 4;

for (int i = 0; i < NUM_OF_PLAYERS; i++} {…
PA Implementation Details:

Part 1: TeacherDate Client Code

Write a client Java program Birthday that uses a provided date class TeacherDate. Your
program will prompt the user for their birth year, month, and day. Based on this information, you
will print that birth date, what day of the week it fell on, a message if that was a leap year, and
the number of days until the user's birthday. If it is the user's birthday, you will print a Happy
Birthday message including the user's current age.
The following three logs of execution show the various behaviors of the program. Note that the
number of days until the user's birthday depends on when the program was run. The logs of
execution below were generated on Wednesday, July 14, 2021. Since you run the program on a
different date, you will receive slightly different output.
Example logs of execution (user input underlined for clarity; underlining not required in the
final submission):
What month, day, and year were you born? 5 8 1987
You were born on 1987/5/8, which was a Friday.
It will be your birthday in 298 days.
You are 12486 days old.

What month, day, and year were you born? 1 28 1952
You were born on 1952/1/28, which was a Monday.
1952 was a leap year.
It will be your birthday in 198 days.
You are 25370 days old.

What month, day, and year were you born? 7 14 1900
You were born on 1900/7/22, which was a Sunday.
Happy birthday! You are now age 121.
You are 44195 days old.

You should implement this program using the TeacherDate class provided to you. A
TeacherDate contains all of the methods and behavior described on the next page, exactly
matching the Date class you will implement in Part2. You can construct a TeacherDate
object in one of two ways:

TeacherDate date = new TeacherDate(year, month, day); // represents
specific date TeacherDate today = new TeacherDate(); // represents today.
You may assume that the user types valid input: the user will type integers, and they will be
within the proper ranges (year will be at least 1753, month will be between 1 and 12, and day
will be between 1 and the number of days in that month, and that the user's birth date will be a
date no later than today (the user will not claim to have been born in the future). You may also
assume that the user's birthday is not on the "leap day" of February 29, because this is an odd
case, since that date only occurs approximately once every four years. (Leap day babies usually
celebrate their birthdays on February 28 or March 1 on non-leap years).
Part 2: Date Class
After you are done with the client code, you need to implement a class named Date. Your Date
class should implement the following behavior. None of the methods below should print any
output to the console. You may not call any methods or utilize any behavior from the
TeacherDate class to help implement your Date class (other than getDaysSinceEpoch,
see below), nor use any of Java's date-related objects such as GregorianCalendar.
Methods you must implement in your Date class
(these methods are also already present in the
TeacherDate class):

public Date(int year, int month, int day)
Constructs a new Date representing the given year, month, and day. You may assume
that the parameter values are valid. Since the modern Gregorian calendar was
established in late 1752, you may assume that the year parameter value will be greater
than or equal to 1753.
public Date()
Constructs a new Date representing today (the date at which the program is run).
It
may be helpful for you to know that the following expression returns the number of
days that have elapsed since January1,1970. (You must import java.util.*; to be
able to refer to TimeZone.)
int daysSinceEpoch = (int) ((System.currentTimeMillis() +
TimeZone.getDefault().getRawOffset()) / 1000 / 60 / 60 / 24);
Or, rather than the above complicated expression, you may call the method
TeacherDate.getDaysSinceEpoch() to see how many days have elapsed
since 1/1/1970. (This is the ONLY place where your Date code may refer to
TeacherDate.)
int daysSinceEpoch = TeacherDate.getDaysSinceEpoch();
public int getDay()
Returns this Date's day of the month, between 1 and the number of days in that month
(which will be between 28 and 31).
public int getMonth()
Returns this Date's month of the year, between 1 and 12.
public int getYear()
Returns this Date's year.
public String getDayOfWeek()
Returns a String representing what day of the week this Date falls on. The String will
be "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", or
"Saturday". For example, August 7, 2005 fell on a Sunday, so the return value for a
new Date (2005, 8, 7) object would be "Sunday". It may be helpful for you to know
that January 1, 1753 was a Monday.
public boolean isLeapYear()
Returns whether this Date's year is a leap year. Leap years are all years that are
divisible by 4, except for years that are divisible by 100 but not by 400. For example,
1756, 1952, 2004, 1600, and 2000 are all leap years, but 1753, 2005, 1700, and 1900
are not.
public void nextDay()
Advances this Date to the next day after its current day. Note that this might advance
the Date into the next month or year. For example, the next day after August 7 is
August 8; the next day after December 31 is January 1; the next day after February 28,
2005 is March 1, 2005, and the next day after February 28, 2004 is February 29, 2004
(because 2004 is a leap year).
public String toString()
Returns a String representation of this Date, in a year/month/day format to match the
following: "2005/5/24"
public boolean equals(Object o)
Returns whether the given object is a Date that refers to the same year/month/day as
this Date.


Part 3: Generating Documentation Using JavaDocs

Because you were writing good Doc Comments alongside your code, you are now able to
generate documentation for your Date class using the JavaDoc Tool:



Follow the prompts. That was easy!

You can now find all the documentation about your Date class inside the doc folder in your
project. Please review the documentation to make sure it makes sense. If you go back to your
code and adjust your doc comments, remember that you will need to Generate Javadoc once
again.

Finally, please remember to include your docs when exporting your project for the final
submission.

Stylistic Guidelines:
A major portion of this assignment is to demonstrate your understanding of using objects and
defining new types of objects. Therefore, for the Birthday program, you should implement the
expected behavior using TeacherDate objects. For the Date program, you should
implement your Date as a new type of objects, using non-static methods and non-static data
fields as appropriate.
We will be grading on your appropriate use of control structures like loops and if/else statements,
your ability to avoid redundancy and your ability to break down the overall problem into
methods that each solve part of the overall problem. In the Birthday program you should have at
least 2 static methods other than main to solve the problem. No one method should be overly
long, and each method should perform a coherent task. Your main method should still contain
the overall control flow of the program.
You should keep in mind the ideas we have been stressing in class. You do not want to have
redundant code. You do not want to have any method be overly long. You want to break the
problem down into logical sub-problems so that someone reading your code can see the sequence
of steps it is performing.
Your Date class, you should use at least one global constant in your program. The choice of
what constant to use is up to you, but it should represent an important value that is used in your
class.
For your Date class, you should properly encapsulate your Date objects.

Follow general stylistic guidelines, such as indentation and whitespace, meaningful identifier
names, and localization of variables.
Include a comment at the beginning of your program with basic information and a description of
the program and include a comment at the start of each method. Also put brief comments inside
longer methods explaining the more complex sections of code.
Hints and Suggestions:
Complete your Birthday program before you start your own Date class, to get a good
understanding of how Date objects work. Write your Date class in phases:
• Write the Date(year,month,day) constructor, getDay, getMonth, getYear,
toString, equals methods first.
• Then implement isLeapYear.
• Next, try to write nextDay. (You may wish to write a helping method that returns the
number of days in this Date's month, to help you implement nextDay.)
• Lastly, write getDayOfWeek and the Date() 'today' constructor. You can use your
nextDay method to help you write these methods.

You can test your Date class by creating a modified version of your Birthday program that uses
your Date instead of TeacherDate.
Submission and Grading: 

Make sure to rename your project in Eclipse to yourfirstname_yourlastnamePA3 before
exporting. Include the generated JavaDocs in your export. Submit via Latte a zip file named
yourfirstname_yourlastnamePA3.zip into Latte. Please make sure to use exactly this file name,
including identical capitalization.

欢迎咨询51作业君

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468