Assignment Requirements
You are supposed to write Java program for the following questions. For every question, do provide at least THREE (3) different test cases.
Question 1
Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. February has 28 days except for leap years when it has 29. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400. (10 Marks)
Question 2
(a)
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438- 5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies must use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than seven letters, then process only the first seven letters. Also output the - (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words. (15 Marks)
(b)
Modify question 3 of Assignment 1 to accept a telephone number with any number of letters. The output should display a hyphen after the first 3 digits and subsequently a hyphen (-) after every four digits. Also, modify the program to process as many telephone numbers as the user wants. (15 Marks)
Question 3
a) Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor (the factors are + and – ). Create a default constructor that sets the fields to “O” and “+”, and an overloaded constructor that requires values for both fields. Include get and set methods for each field. Save this file as BloodData.java. Create an application named TestBloodData that demonstrates that each method works correctly.
Save the application as TestBloodData.java. (30 marks)
b) Create a class named Patient that includes an ID number, age, and BloodData.
Provide a default constructor that sets the ID number to “0”, the age to 0, and the BloodData to “O” and “+” . Create an overloaded constructor that provides values for each field. Also provide get methods for each field. Save the file as Patient.java. Create an application named TestPatient that demonstrates that each method works correctly, and save it as TestPatient.java. (30 marks)
MARKING GUIDE
Question
|
Tasks to be done
|
Marks to be awarded
|
1
|
- Java program free from syntax, logic and run time errors.
- Used appropriate string function to separate single input into multiple variables.
- Student did validation checks for day, month and year. Also check for all digits.
- Code optimisation: reduced number of repeated display statements.
- Sample output screenshot shown for 3 cases (at least one of them is incorrect input). Descriptive block and inline
comments included.
|
10
|
2
a)
|
- Java program free from syntax, logic and run time errors.
- Used appropriate String and Character methods to handle blank spaces, digits, letters and others.
- Code optimisation: no unnecessary variables, if statements and counters.
- Sample output screenshot shown with 3 cases (at least one with blank spaces etc.)
- Descriptive block and inline comments included.
|
15
|
b)
|
- Java program free from syntax, logic and run time errors.
- Used appropriate String and Character methods to handle blank spaces, digits, letters and others.
- Code optimisation: no unnecessary variables, if statements and counters.
- Sample output screenshot shown with 3 cases (at least one with blank spaces etc.)
- Descriptive block and inline comments included.
|
15
|
3
a)
|
- Java program free from syntax, logic and run time errors.
- Used appropriate methods, constructors and parameters as mentioned in the question.
- Code optimisation: no unnecessary assignment of variables, calculations, parameters and loops.
- Sample output screenshot.
- Descriptive block and inline comments included.
|
30
|
b)
|
- Java program free from syntax, logic and run time errors.
- Used appropriate methods, constructors and parameters as mentioned in the question.
- Code optimisation: no unnecessary assignment of variables, calculations, parameters and loops.
- Sample output screenshot.
- Descriptive block and inline comments included.
|
30
|
Total
|
100
|