Write a method that is passed a day, a month, and year and checks to make sure it is valid.

computer science

Description

Exercise 1a 

Write a class named Date to represent a standard date. This class should include instance variables for day, month and year. 

a. Write a constructor to create the Date with an initial date 

b. Write a method that is passed a day, a month, and year and checks to make sure it is valid. 

c. Write a method that is passed a new date to set. It should be passed all the day, month, and year, not just one. This method must check that the new date is valid (reuse your validator method from part b.) 

d. Write accessor methods to return each individual date element


Exercise 1b 

Write a class named Friend to represent one of your friends. Please note that you should not include the dateOfBirth attribute yet, as you need the Date class to be written. 

a. Write a constructor to create the Friend with their basic information (just their name) 

b. Write a method to validate that the phone number is at least 8 digits long (hint… if you divide an integer of less than 8 digits by 100,000,000 then the result is always less than 1) 

c. Write mutator methods for each of the other friend details. The phone number mutator should utilise the validator method from part b. 

d. Write accessor methods to return the friend’s details 


Related Questions in computer science category