SlideShare a Scribd company logo
Exercise 1 [10 points]:
Write a static method named numUnique that accepts an array
of integers as a parameter and returns the number of unique
values in that array. The array may contain positive integers in
no particular order, which means that the duplicates will not be
grouped together. For example, if a variable called list stores
the following values:
int[] list = {7, 5, 22, 7, 23, 9, 1, 5, 2, 35, 6, 11, 12, 7, 9};
then the call of numUnique(list) should return 11 because this
list has 11 unique values (1, 2, 5, 6, 7, 9, 11, 12, 22, 23, and
35). It is possible that the list might not have any duplicates.
For example if the list contain this sequence of values:
int[] list = {1, 2, 11, 17, 19, 20, 23, 24, 25, 26, 31, 34, 37, 40,
41}; Then a call to the method would return 15 because this list
contains 15 different values.
If passed an empty list, your method should return 0.
Note: It might be beneficial to sort the array before you count
the unique elements. To sort an integer array, you can use
Arrays.sort() method.
Exercise 2 [10 points]:
In this exercise, you need to complete the following static
methods and then use them.
public class Password{
public static boolean passwordValidator(String pass1, String
pass2){
// Your code goes here…
}
public static String passwordGenerator(int length){
// Your code goes here
}
}
· The method passwordValidator takes two alpha-numeric
passwords and returns true only if all the following conditions
are met:
i) Length of the password must be between 8 and 32 characters.
ii) Password should contain at least one upper case and one
lower case alphabet. iii) Password should contain at least
two numbers.
iv) Password should contain at least one special character from
this list {!, ~, _, %, $, #}.
v) Both the password strings must match.
· The method passwordGenerator – generates and returns a
random password that satisfy the above-mentioned criteria with
a specified length.
· Now, write a PasswordTester class – in which you should test
these static methods.
Here is an example test run:
Enter a new password: test123
Re-enter the same password: test123
Password should contain at least 8 characters.
Enter a new password: qwerty123
Re-enter the same password: qwerty123
Password must contain at least 1 capital letter character.
Enter a new password: qwerTy123
Re-enter the same password: qwerTy123
Password must contain at least 1 special symbol.
Enter a new password: qwerTy_1
Re-enter the same password: qwerTy_1
Password must contain at least 2 numbers.
Enter a new password: qwerTy_12
Re-enter the same password: qwerty_12
Both passwords must match.
Enter a new password: qwerTy_12
Re-enter the same password: qwerTy_12
Success!
The test cases shown above are sample only. When you test
your code, you should test it for all possible cases. If the user
cannot select a valid password within 7 tries, then your program
should suggest four random passwords (with different length) to
the user that satisfies all rules for the password.
Take snapshots of different test runs for your program and
attach those snapshots during submission.
Exercise 3 [10 Points]:
DateUtil: Complete the following methods in a class called
DateUtil:
· boolean isLeapYear(int year): returns true if the given year is
a leap year. A year is a leap year if it is divisible by 4 but not
by 100, or it is divisible by 400.
· boolean isValidDate(int year, int month, int day): returns true
if the given year, month and day constitute a given date.
Assume that year is between 1 and 9999, month is between 1
(Jan) to 12 (Dec) and day shall be between 1 and 28|29|30|31
depending on the month and whether it is a leap year.
· int getDayOfWeek(int year, int month, int day): returns the
day of the week, where 0 for SUN, 1 for MON, ..., 6 for SAT,
for the given date. Assume that the date is valid.
· String toString(int year, int month, int day): prints the given
date in the format "xxxday d mmm yyyy", e.g., "Tuesday 14 Feb
2012". Assume that the given date is valid.
To find the day of the week (Reference: Wiki "Determination of
the day of the week"):
1. Based on the first two digit of the year, get the number from
the following "century" table.
1700-
1800-
1900-
2000-
2100-
2200-
2300-
2400-
4
2
0
6
4
2
0
6
2. Take note that the entries 4, 2, 0, 6 repeat.
3. Add to the last two digit of the year.
4. Add to "the last two digit of the year divide by 4, truncate the
fractional part".
5. Add to the number obtained from the following month table:
6. Add to the day.
7. The sum modulus 7 gives the day of the week, where 0 for
SUN, 1 for MON, ..., 6 for SAT.
For example: 2012, Feb, 17
(6 + 12 + 12/4 + 2 + 17) % 7 = 5 (Fri)
The skeleton of the program is as follows:
/* Utilities for Date Manipulation */ public class DateUtil {
// Month's name – for printing public static String
strMonths[]
= {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
// Number of days in each month (for non-leap years) public
static int daysInMonths[]
= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// Returns true if the given year is a leap year public static
boolean isLeapYear(int year) { ...... }
// Return true if the given year, month, day is a valid date
// year: 1-9999
// month: 1(Jan)-12(Dec)
// day: 1-28|29|30|31. The last day depends on year and month
public static boolean isValidDate(int year, int month, int day) {
...... }
// Return the day of the week, 0:Sun, 1:Mon, ..., 6:Sat
public static int getDayOfWeek(int year, int month, int day) {
...... }
// Return String "xxxday d mmm yyyy" (e.g., Wednesday 29
Feb 2012)
public static String printDate(int year, int month, int day) {
...... }
public static void main(String[] args) {
System.out.println(isLeapYear(1900)); // false
System.out.println(isLeapYear(2000)); // true
System.out.println(isLeapYear(2011)); // false
System.out.println(isLeapYear(2012)); // true
System.out.println(isValidDate(2012, 2, 29)); // true
System.out.println(isValidDate(2011, 2, 29)); // false
System.out.println(isValidDate(2099, 12, 31)); // true
System.out.println(isValidDate(2099, 12, 32)); // false
System.out.println(getDayOfWeek(1982, 4, 24)); // 6:Sat
System.out.println(getDayOfWeek(2000, 1, 1)); // 6:Sat
System.out.println(getDayOfWeek(2054, 6, 19)); // 5:Fri
System.out.println(getDayOfWeek(2012, 2, 17)); // 5:Fri
System.out.println(toString(2012, 2, 14)); // Tuesday 14 Feb
2012
}
}
You can compare the day obtained with the Java's Calendar
class as follows:
// Construct a Calendar instance with the given year, month and
day
Calendar cal = new GregorianCalendar(year, month - 1, day); //
month is 0-based
// Get the day of the week number: 1 (Sunday) to 7 (Saturday)
int dayNumber = cal.get(Calendar.DAY_OF_WEEK);
String[] calendarDays = { "Sunday", "Monday", "Tuesday",
"Wednesday",
"Thursday", "Friday", "Saturday" };
// Print result
System.out.println("It is " + calendarDays[dayNumber - 1]);
Foot Note:
The calendar we used today is known as Gregorian calendar,
which came into effect in October 15, 1582 in some countries
and later in other countries. It replaces the Julian calendar. 10
days were removed from the calendar, i.e., October 4, 1582
(Julian) was followed by October 15, 1582 (Gregorian). The
only difference between the Gregorian and the Julian calendar is
the "leap-year rule". In Julian calendar, every four years is a
leap year. In Gregorian calendar, a leap year is a year that is
divisible by 4 but not divisible by 100, or it is divisible by 400,
i.e., the Gregorian calendar omits century years which are not
divisible by 400. Furthermore, Julian calendar considers the
first day of the year as march 25th, instead of January 1st.
This above algorithm work for Gregorian dates only. It is
difficult to modify the above algorithm to handle preGregorian
dates. A better algorithm is to find the number of days from a
known date.
Exercise 4 [15 Marks]
· Address Book Entry. Your task is to create a class called
“AddressBookEntry” that contains an address book entry. The
following table describes the information that an address book
entry has.
a. Provide the necessary accessor/getter and mutator/setter
methods for all the ivars.
b. You should provide a constructor that will initialize ivars
with the supplied values from the client.
c. Also provide a “public String toString()” method that will
return a string in the following format:
“Name: ”+<name>+”tt Address: “+<address>+” tt Tel: “+
<tel> + “ttEmail:” + <email>;
where <name>, <address>, <tel> and <email> should be
replaced by the receiver’s current state or field’s values.
Save this class in a separate file called
“AddressBookEntry.java” and compile it.
· AddressBook. Create another class called “AddressBook” in
“AddressBook.java” and save it the same directory. The
AddressBook class should contain 100 entries of the
“AddressBookEntry” objects (use the class you created in the
above exercise). You can use the “AddressBookEntry” class as
long as both of the classes reside in the same folder. You should
design and provide the following public interfaces for the
address book class. In addition, please provide constructors as
you think appropriate.
a. Add entry - will add a new address book entry at the end of
the address book, and returns “true” if the entry is successfully
added, “false” otherwise.
b. Delete entry – will delete an existing valid entry from the
address book. The client should supply an index number to this
method that will specify which entry from the address book the
client wants to delete. This method returns “true” if the deletion
is successful, and returns “false” otherwise. Notice that the
index must be a valid entry value form the address book.
c. View all entries – will display the non-empty entries of the
address book with their sequence number on the screen. For
example:
1. Name: Alex Address: 123 abc St. Kamloops Tel: 123-234-
2192 Email: [email protected]
2. Name: Dan Address: 231 XYZ St. Kamloops Tel: 223-222-
2234 Email: [email protected] ...
d. Update an entry – will update a specified non-empty entry.
(One way to design this method is that the client would supply
an index number to update that entry, for example, if the
method is called “updateEntry”, then to update the first entry of
the address book client may call the method as follows:
updateEntry(1, “Poly”, “123 McGill Rd. Kamloops”, “123-435-
7532”, [email protected]);
another separate file that will have the main method and test the
functionality of the address book for all the method. Make sure
you test it for all possible boundary conditions in many possible
ways.
Submit all java source codes doc files (make a single zip file,
see the submission instruction at the beginning of the
assignment) through the moodle.tru.ca.
Lyme Disease
Case Study
A 38-year-old male had a 3-week history of fatigue and lethargy
with intermittent complaints
of headache, fever, chills, myalgia, and arthralgia. According to
the history, the patient’s
symptoms began shortly after a camping vacation. He recalled a
bug bite and rash on his
thigh immediately after the trip. The following studies were
ordered:
Studies Results
Lyme disease test, Elevated IgM antibody titers against
Borrelia burgdorferi
(normal: low)
Erythrocyte sedimentation rate
(ESR),
30 mm/hour (normal: ≤15 mm/hour)
Aspartate aminotransferase
(AST),
32 units/L (normal: 8-20 units/L)
Hemoglobin (Hgb), 12 g/dL (normal: 14-18 g/dL)
Hematocrit (Hct), 36% (normal: 42%-52%)
Rheumatoid factor (RF), Negative (normal: negative)
Antinuclear antibodies (ANA), Negative (normal: negative)
Diagnostic Analysis
Based on the patient's history of camping in the woods and an
insect bite and rash on the
thigh, Lyme disease was suspected. Early in the course of this
disease, testing for specific
immunoglobulin (Ig) M antibodies against B. burgdorferi is the
most helpful in diagnosing
Lyme disease. An elevated ESR, increased AST levels, and mild
anemia are frequently seen
early in this disease. RF and ANA abnormalities are usually
absent.
Critical Thinking Questions
1. What is the cardinal sign of Lyme disease? (always on the
boards)
2. At what stages of Lyme disease are the IgG and IgM
antibodies elevated?
3. Why was the ESR elevated?
4. What is the Therapeutic goal for Lyme Disease and what is
the recommended treatment.

More Related Content

DOCX
Exercise 1 [10 points]Write a static method named num
DOCX
Builtinfunctions in vbscript and its types.docx
PDF
DOCX
Applications-of-sequence-and-series .official.docx
PDF
Introduction to MS Excel
PPT
Oracle sql ppt2
DOCX
Google Sheets Basic to Advanced Formulas Book.docx
PPTX
131 Lab slides (all in one)
Exercise 1 [10 points]Write a static method named num
Builtinfunctions in vbscript and its types.docx
Applications-of-sequence-and-series .official.docx
Introduction to MS Excel
Oracle sql ppt2
Google Sheets Basic to Advanced Formulas Book.docx
131 Lab slides (all in one)

Similar to Exercise 1 [10 points]Write a static method named numUniq.docx (20)

PDF
23UCACC11 Python Programming (MTNC) (BCA)
PPT
Arrays and vectors in Data Structure.ppt
PPTX
Arrays
PPT
Algo>Arrays
PPTX
Lecture 9
PPT
CHAPTER-5.ppt
PDF
R_CheatSheet.pdf
PDF
beginners_python_cheat_sheet -python cheat sheet description
DOCX
maths project.docx
PPTX
Data structure.pptx
PDF
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
PPTX
Python- Regular expression
PDF
1 ESO - UNIT 02 - POWERS AND SQUARE ROOTS
PPTX
Números reales y plano numérico
PDF
Oracle sql functions
PDF
Visual Programming Lacture Nine 9 Structure.pdf
PPTX
02 Representing Sets and Types of Sets.pptx
PPTX
COM1407: Arrays
PPT
23UCACC11 Python Programming (MTNC) (BCA)
Arrays and vectors in Data Structure.ppt
Arrays
Algo>Arrays
Lecture 9
CHAPTER-5.ppt
R_CheatSheet.pdf
beginners_python_cheat_sheet -python cheat sheet description
maths project.docx
Data structure.pptx
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
Python- Regular expression
1 ESO - UNIT 02 - POWERS AND SQUARE ROOTS
Números reales y plano numérico
Oracle sql functions
Visual Programming Lacture Nine 9 Structure.pdf
02 Representing Sets and Types of Sets.pptx
COM1407: Arrays
Ad

More from rhetttrevannion (20)

DOCX
Discuss three (3) ways that large organizations are increasingly eng.docx
DOCX
Discuss this week’s objectives with your team sharing related rese.docx
DOCX
Discuss theoretical considerations or assumptions relevant to yo.docx
DOCX
Discuss theprinciple events of PROCESS AND THREAD used in both t.docx
DOCX
Discuss the Windows Registry System Hive1) What information.docx
DOCX
Discuss the way the idea of heroism develops from Gilgamesh th.docx
DOCX
Discuss the ways in which the history of the U.S. was presented in t.docx
DOCX
Discuss the value of Lean Systems Engineering to systems develop.docx
DOCX
discuss the various pathways interest groups use to influence politi.docx
DOCX
Discuss the various tools and techniques used by an HCO to incre.docx
DOCX
Discuss the various means by which slaves resisted the slave system..docx
DOCX
Discuss the typica l clinical presentation of the diagnosis , Hip Os.docx
DOCX
Discuss the types of resources, tools, and methods that are availabl.docx
DOCX
Discuss the types of items that should be examined in a firewall log.docx
DOCX
Discuss the types of property, providing an example of each an.docx
DOCX
Discuss the type of personality it takes to become a police officer..docx
DOCX
Discuss the two major sources of crime statistics for the United Sta.docx
DOCX
Discuss the two most prominent theories related to the stage of adul.docx
DOCX
Discuss the two elements required for the consent defense. In ad.docx
DOCX
Discuss the Truth in Lending Act and what role it places in financia.docx
Discuss three (3) ways that large organizations are increasingly eng.docx
Discuss this week’s objectives with your team sharing related rese.docx
Discuss theoretical considerations or assumptions relevant to yo.docx
Discuss theprinciple events of PROCESS AND THREAD used in both t.docx
Discuss the Windows Registry System Hive1) What information.docx
Discuss the way the idea of heroism develops from Gilgamesh th.docx
Discuss the ways in which the history of the U.S. was presented in t.docx
Discuss the value of Lean Systems Engineering to systems develop.docx
discuss the various pathways interest groups use to influence politi.docx
Discuss the various tools and techniques used by an HCO to incre.docx
Discuss the various means by which slaves resisted the slave system..docx
Discuss the typica l clinical presentation of the diagnosis , Hip Os.docx
Discuss the types of resources, tools, and methods that are availabl.docx
Discuss the types of items that should be examined in a firewall log.docx
Discuss the types of property, providing an example of each an.docx
Discuss the type of personality it takes to become a police officer..docx
Discuss the two major sources of crime statistics for the United Sta.docx
Discuss the two most prominent theories related to the stage of adul.docx
Discuss the two elements required for the consent defense. In ad.docx
Discuss the Truth in Lending Act and what role it places in financia.docx
Ad

Recently uploaded (20)

PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
English Language Teaching from Post-.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
From loneliness to social connection charting
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
Cardiovascular Pharmacology for pharmacy students.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Pharmacology of Heart Failure /Pharmacotherapy of CHF
English Language Teaching from Post-.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Pharma ospi slides which help in ospi learning
From loneliness to social connection charting
O7-L3 Supply Chain Operations - ICLT Program
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Week 4 Term 3 Study Techniques revisited.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Open Quiz Monsoon Mind Game Prelims.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Module 3: Health Systems Tutorial Slides S2 2025
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
How to Manage Starshipit in Odoo 18 - Odoo Slides
O5-L3 Freight Transport Ops (International) V1.pdf

Exercise 1 [10 points]Write a static method named numUniq.docx

  • 1. Exercise 1 [10 points]: Write a static method named numUnique that accepts an array of integers as a parameter and returns the number of unique values in that array. The array may contain positive integers in no particular order, which means that the duplicates will not be grouped together. For example, if a variable called list stores the following values: int[] list = {7, 5, 22, 7, 23, 9, 1, 5, 2, 35, 6, 11, 12, 7, 9}; then the call of numUnique(list) should return 11 because this list has 11 unique values (1, 2, 5, 6, 7, 9, 11, 12, 22, 23, and 35). It is possible that the list might not have any duplicates. For example if the list contain this sequence of values: int[] list = {1, 2, 11, 17, 19, 20, 23, 24, 25, 26, 31, 34, 37, 40, 41}; Then a call to the method would return 15 because this list contains 15 different values. If passed an empty list, your method should return 0. Note: It might be beneficial to sort the array before you count the unique elements. To sort an integer array, you can use Arrays.sort() method. Exercise 2 [10 points]: In this exercise, you need to complete the following static methods and then use them. public class Password{ public static boolean passwordValidator(String pass1, String pass2){ // Your code goes here… }
  • 2. public static String passwordGenerator(int length){ // Your code goes here } } · The method passwordValidator takes two alpha-numeric passwords and returns true only if all the following conditions are met: i) Length of the password must be between 8 and 32 characters. ii) Password should contain at least one upper case and one lower case alphabet. iii) Password should contain at least two numbers. iv) Password should contain at least one special character from this list {!, ~, _, %, $, #}. v) Both the password strings must match. · The method passwordGenerator – generates and returns a random password that satisfy the above-mentioned criteria with a specified length. · Now, write a PasswordTester class – in which you should test these static methods. Here is an example test run: Enter a new password: test123 Re-enter the same password: test123 Password should contain at least 8 characters. Enter a new password: qwerty123 Re-enter the same password: qwerty123 Password must contain at least 1 capital letter character.
  • 3. Enter a new password: qwerTy123 Re-enter the same password: qwerTy123 Password must contain at least 1 special symbol. Enter a new password: qwerTy_1 Re-enter the same password: qwerTy_1 Password must contain at least 2 numbers. Enter a new password: qwerTy_12 Re-enter the same password: qwerty_12 Both passwords must match. Enter a new password: qwerTy_12 Re-enter the same password: qwerTy_12 Success! The test cases shown above are sample only. When you test your code, you should test it for all possible cases. If the user cannot select a valid password within 7 tries, then your program should suggest four random passwords (with different length) to the user that satisfies all rules for the password. Take snapshots of different test runs for your program and attach those snapshots during submission. Exercise 3 [10 Points]: DateUtil: Complete the following methods in a class called DateUtil: · boolean isLeapYear(int year): returns true if the given year is a leap year. A year is a leap year if it is divisible by 4 but not
  • 4. by 100, or it is divisible by 400. · boolean isValidDate(int year, int month, int day): returns true if the given year, month and day constitute a given date. Assume that year is between 1 and 9999, month is between 1 (Jan) to 12 (Dec) and day shall be between 1 and 28|29|30|31 depending on the month and whether it is a leap year. · int getDayOfWeek(int year, int month, int day): returns the day of the week, where 0 for SUN, 1 for MON, ..., 6 for SAT, for the given date. Assume that the date is valid. · String toString(int year, int month, int day): prints the given date in the format "xxxday d mmm yyyy", e.g., "Tuesday 14 Feb 2012". Assume that the given date is valid. To find the day of the week (Reference: Wiki "Determination of the day of the week"): 1. Based on the first two digit of the year, get the number from the following "century" table. 1700- 1800- 1900- 2000- 2100- 2200- 2300- 2400- 4 2 0 6 4 2 0 6 2. Take note that the entries 4, 2, 0, 6 repeat. 3. Add to the last two digit of the year. 4. Add to "the last two digit of the year divide by 4, truncate the fractional part".
  • 5. 5. Add to the number obtained from the following month table: 6. Add to the day. 7. The sum modulus 7 gives the day of the week, where 0 for SUN, 1 for MON, ..., 6 for SAT. For example: 2012, Feb, 17 (6 + 12 + 12/4 + 2 + 17) % 7 = 5 (Fri) The skeleton of the program is as follows: /* Utilities for Date Manipulation */ public class DateUtil { // Month's name – for printing public static String strMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; // Number of days in each month (for non-leap years) public static int daysInMonths[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Returns true if the given year is a leap year public static boolean isLeapYear(int year) { ...... } // Return true if the given year, month, day is a valid date // year: 1-9999 // month: 1(Jan)-12(Dec) // day: 1-28|29|30|31. The last day depends on year and month public static boolean isValidDate(int year, int month, int day) { ...... } // Return the day of the week, 0:Sun, 1:Mon, ..., 6:Sat public static int getDayOfWeek(int year, int month, int day) { ...... } // Return String "xxxday d mmm yyyy" (e.g., Wednesday 29 Feb 2012) public static String printDate(int year, int month, int day) { ...... } public static void main(String[] args) {
  • 6. System.out.println(isLeapYear(1900)); // false System.out.println(isLeapYear(2000)); // true System.out.println(isLeapYear(2011)); // false System.out.println(isLeapYear(2012)); // true System.out.println(isValidDate(2012, 2, 29)); // true System.out.println(isValidDate(2011, 2, 29)); // false System.out.println(isValidDate(2099, 12, 31)); // true System.out.println(isValidDate(2099, 12, 32)); // false System.out.println(getDayOfWeek(1982, 4, 24)); // 6:Sat System.out.println(getDayOfWeek(2000, 1, 1)); // 6:Sat System.out.println(getDayOfWeek(2054, 6, 19)); // 5:Fri System.out.println(getDayOfWeek(2012, 2, 17)); // 5:Fri System.out.println(toString(2012, 2, 14)); // Tuesday 14 Feb 2012 } } You can compare the day obtained with the Java's Calendar class as follows: // Construct a Calendar instance with the given year, month and day Calendar cal = new GregorianCalendar(year, month - 1, day); // month is 0-based // Get the day of the week number: 1 (Sunday) to 7 (Saturday) int dayNumber = cal.get(Calendar.DAY_OF_WEEK); String[] calendarDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; // Print result System.out.println("It is " + calendarDays[dayNumber - 1]); Foot Note:
  • 7. The calendar we used today is known as Gregorian calendar, which came into effect in October 15, 1582 in some countries and later in other countries. It replaces the Julian calendar. 10 days were removed from the calendar, i.e., October 4, 1582 (Julian) was followed by October 15, 1582 (Gregorian). The only difference between the Gregorian and the Julian calendar is the "leap-year rule". In Julian calendar, every four years is a leap year. In Gregorian calendar, a leap year is a year that is divisible by 4 but not divisible by 100, or it is divisible by 400, i.e., the Gregorian calendar omits century years which are not divisible by 400. Furthermore, Julian calendar considers the first day of the year as march 25th, instead of January 1st. This above algorithm work for Gregorian dates only. It is difficult to modify the above algorithm to handle preGregorian dates. A better algorithm is to find the number of days from a known date. Exercise 4 [15 Marks] · Address Book Entry. Your task is to create a class called “AddressBookEntry” that contains an address book entry. The following table describes the information that an address book entry has. a. Provide the necessary accessor/getter and mutator/setter methods for all the ivars. b. You should provide a constructor that will initialize ivars with the supplied values from the client. c. Also provide a “public String toString()” method that will
  • 8. return a string in the following format: “Name: ”+<name>+”tt Address: “+<address>+” tt Tel: “+ <tel> + “ttEmail:” + <email>; where <name>, <address>, <tel> and <email> should be replaced by the receiver’s current state or field’s values. Save this class in a separate file called “AddressBookEntry.java” and compile it. · AddressBook. Create another class called “AddressBook” in “AddressBook.java” and save it the same directory. The AddressBook class should contain 100 entries of the “AddressBookEntry” objects (use the class you created in the above exercise). You can use the “AddressBookEntry” class as long as both of the classes reside in the same folder. You should design and provide the following public interfaces for the address book class. In addition, please provide constructors as you think appropriate. a. Add entry - will add a new address book entry at the end of the address book, and returns “true” if the entry is successfully added, “false” otherwise. b. Delete entry – will delete an existing valid entry from the address book. The client should supply an index number to this method that will specify which entry from the address book the client wants to delete. This method returns “true” if the deletion is successful, and returns “false” otherwise. Notice that the index must be a valid entry value form the address book. c. View all entries – will display the non-empty entries of the address book with their sequence number on the screen. For example:
  • 9. 1. Name: Alex Address: 123 abc St. Kamloops Tel: 123-234- 2192 Email: [email protected] 2. Name: Dan Address: 231 XYZ St. Kamloops Tel: 223-222- 2234 Email: [email protected] ... d. Update an entry – will update a specified non-empty entry. (One way to design this method is that the client would supply an index number to update that entry, for example, if the method is called “updateEntry”, then to update the first entry of the address book client may call the method as follows: updateEntry(1, “Poly”, “123 McGill Rd. Kamloops”, “123-435- 7532”, [email protected]); another separate file that will have the main method and test the functionality of the address book for all the method. Make sure you test it for all possible boundary conditions in many possible ways. Submit all java source codes doc files (make a single zip file, see the submission instruction at the beginning of the assignment) through the moodle.tru.ca. Lyme Disease
  • 10. Case Study A 38-year-old male had a 3-week history of fatigue and lethargy with intermittent complaints of headache, fever, chills, myalgia, and arthralgia. According to the history, the patient’s symptoms began shortly after a camping vacation. He recalled a bug bite and rash on his thigh immediately after the trip. The following studies were ordered: Studies Results Lyme disease test, Elevated IgM antibody titers against Borrelia burgdorferi (normal: low) Erythrocyte sedimentation rate (ESR), 30 mm/hour (normal: ≤15 mm/hour) Aspartate aminotransferase (AST), 32 units/L (normal: 8-20 units/L)
  • 11. Hemoglobin (Hgb), 12 g/dL (normal: 14-18 g/dL) Hematocrit (Hct), 36% (normal: 42%-52%) Rheumatoid factor (RF), Negative (normal: negative) Antinuclear antibodies (ANA), Negative (normal: negative) Diagnostic Analysis Based on the patient's history of camping in the woods and an insect bite and rash on the thigh, Lyme disease was suspected. Early in the course of this disease, testing for specific immunoglobulin (Ig) M antibodies against B. burgdorferi is the most helpful in diagnosing Lyme disease. An elevated ESR, increased AST levels, and mild anemia are frequently seen early in this disease. RF and ANA abnormalities are usually absent. Critical Thinking Questions 1. What is the cardinal sign of Lyme disease? (always on the boards) 2. At what stages of Lyme disease are the IgG and IgM
  • 12. antibodies elevated? 3. Why was the ESR elevated? 4. What is the Therapeutic goal for Lyme Disease and what is the recommended treatment.