Question: COMPSCI QUESTIONS A. (1 point) Write a minimal definition for a class named MonthDay, about which you know nothing else (that is, dont use the
COMPSCI QUESTIONS
A. (1 point) Write a minimal definition for a class named MonthDay, about which you know nothing else (that is, dont use the information in the following questions in this answer). Your answer to this question should be just the minimal definition.
B. (2 points) Add a constructor for MonthDay that takes a month and day (of the appropriate primitive type), and stores these values in appropriately-named instance variables.
If the month or day is obviously invalid, then your constructor should throw an IllegalArgumentException. Do not exhaustively check correctness. Instead, limit your checks to checking for a non-negative day and a month between 1 and 12.
Your answer should be the entire class definition.
C. (1 point) Write a public toString() method with an appropriate signature that converts the MonthDay object to a String representation as exemplified by 31 January or 4 March.
Your answer should be just the toString() method.
D. (3 points) Given the following code, what is the output? Assume a setNumber() method sets a relevant instance variable, and a equals()method that uses only this instance variable to check if two Bus objects values are semantically equal.
Bus busA = new Bus(); Bus busB = new Bus(); busA.setNumber(44); busB.setNumber(44); System.out.println(busA == busB); System.out.println(busA.equals(busB)); Bus busC = busB; busB = busA; busA.setNumber(13); System.out.println(busA == busC); System.out.println(busA.equals(busC)); busC = busB; System.out.println(busA == busC); System.out.println(busA.equals(busC)); thanks in advance!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
