Hi all. Sent this out as an e-mail. Here for your convenience, as well:
As promised in class, here is both some news about the
upcoming quiz AND some hints on the next assignment (which is GregorianCalendar,
Page 77, P2.7):
QUIZ:
·
OPEN NOTE (MUST BE YOUR OWN HANDWRITING)
·
MULTIPLE CHOICE
·
TOPICS INCLUDE
o Syntax
errors, and specifically what thing detects a syntax error
o Any
time you want to RUN a program, the program needs to have a certain type of method…
we give this method a specific generalized name
o Understanding
the multiple forms of writing comments into your code
§ Single-line
comments (//)
§ Multi-line
comments (/* followed by lines of comments followed by */)
o Understanding
how to declare and initialize a variable (hint: there are two ways, as
follows):
§ Declaring
the variable in one line of code, then initializing the variable in a separate
line
§ Declaring
AND initializing the variable in a single line of code
o Understanding
what a .java file is and does, and specifically what purpose it has in
developing Java programs
o Understanding
what a .class file is and does, and specifically what purpose it has in
developing Java programs
o Understanding
how to create (or “instantiate”) a new Random gen object.
GREGORIANCALENDAR:
·
Hints and suggestions:
o You
will be using a combination of the code shown in the textbook AND the online
API for GregorianCalendar (Google “Java 8 API GregorianCalendar”). I’d
suggest starting with the source code in the book FIRST and then moving on to
the API as you need to
o To
do this assignment, you are going to want to import both the Calendar class and
the GregorianCalendar class, as follows:
§ import
java.util.Calendar;
§ import
java.util.GregorianCalendar;
o The
assignment requires you to generate THREE DISTINCT THINGS using the
GregorianCalendar class
§ Both
the DATE and the WEEKDAY that is 100 days from today
§ The
WEEKDAY of your birthday
§ The
DATE that is 10000 days from your birthday
o To
accomplish the first thing, you are going to want to make one GregorianCalendar
object using its constructor that has NO parameters. That will
automatically store information related to today’s date
§ Once
there, you will need to tell the GregorianCalendar you create to .get() the
modifiedMonth after adding 100 days to the current day of the month and store
it an int variable
§ Then,
you’ll want to tell the GregorianCalendar you create to .get() the modifiedDay
after adding 100 days to the current day of the month and store it in a
separate int variable
§ Finally,
you’ll want to tell it to .get() the modifiedYear after adding 100 days to the
current day of the month and store it in a separate int variable
§
(Hint #1: Pay close attention to the sample
code in the textbook for how to actually go about doing this.)
§
(Hint #2: One tricky thing about getting the
current month….. the int that you get when you instruct the GregorianCalendar
to get the month will actually be one less than how we normally refer to
it. In other words, January is represented as month 0, February as month
1, and so on… You can easily fix this by just adding 1 to whatever the calendar
gives you when you call the .get() method for this.)
§ Once
there, you’ll want to print out each of these ints in some sort of “pretty”
manner. See the attached .java file for how I printed out information
about the current day.
o To
accomplish the second and third thing, you are going to want to make a SECOND
GregorianCalendar object (give it a separate name than the first one) using its
constructor that has the parameters corresponding to your birthday.
§ Again,
look at the example code in the book for some guidance on how to create this
new GregorianCalendar
§ Once
it’s created, you’ll want to make three new int variables, each representing
the month, day, and year you were born (remember what I said about adding one
to the month number up above!)
§ Print
out the day of week on which you were born (maybe check with a family member to
see if this is accurate!)
§ Then,
to do the third thing, you’ll want to add 10000 days to the day of month of the
calendar to set it up for 10000 days past the day you were born.
§ After
that, repeat the steps of collecting the new value of the month, the day, and
the year, and then display that information
o See the e-mail I sent out for images of how the output should look. Doesn't have to be formatted exactly as I have it, but it should contain the same info.
Hope this helps! Let me know if you have any questions.
Mr. Svetlik