Another Computer Science Question

<p>I don't understand this question, could someone explain the answer choices?</p>

<p>Consider the following class declaration:</p>

<p>public class Date
{
public Date() { < code not shown > }
public Date(String monthName, int day, int year)
{ < code not shown > }
public void setDate(int month, int day, int year)
{ < code not shown > }</p>

<pre><code> < other class members not shown >
</code></pre>

<p>}</p>

<p>Consider modifying the Date class to make it possible to initialize variables of the type Date with month (given as a month name or number), day, and year information when they are declared, as well as to set their values later using the member method setDate. For example, the following code should define and initialize three Date variables:</p>

<p>Date d1 = new Date();
d1.setDate("May", 11, 2004);
Date d2 = new Date("June", 30, 2010);
Date d3 = new Date(6, 30, 2010);</p>

<p>Which of the following best describes the additional features that should be present?</p>

<p>A) An overloaded version of setDate with three int arguments
B) An overloaded version of setDate with one String and two int arguments
C) A constructor with three int arguments
D) Both an overloaded version of setDate with three int arguments and a constructor with three int arguments
E) Both an overloaded version of setDate with one String and two int arguments and a constructor with three int arguments</p>

<p>** I chose A because you already have setDate with month as a string, so you overload it with an int version of month. ** Can anyone explain the correct answer and why?</p>

<p>Well since no one has posted yet, I have one last question.
These are all questions from a packet for my semester exam. (I'm almost finished, just these last two). </p>

<p>public class TicketSales
{
public TicketSales(String movieName) { < code not shown > }</p>

<p>// precondition 1 <= week <= 52
// postcondition: sets box office receipts for a given week
public void setWeekSales(int week, double dollars)
{ < code not shown > }</p>

<p>// Finds and returns the week with best sales
private int findBestWeek() { < code not shown > }</p>

<p>< Other methods not shown ></p>

<p>private String myName;
private double[] mySales; //mySales[0]....mySales[51] hold sales totals for 52 weeks
}</p>

<p>The method findBestWeek is declared private because</p>

<p>a) findBestWeek is not intended to be used by clients of the class
b) findBestWeek is intended to be used only by clients of the class
c) Methods that work with private instance variables of the array type cannot be public
d) Methods that have a loop in their code cannot be public
e) Methods that return a value cannot be public</p>

<p>** I eliminated D and E, but I'm stuck between the first three. And on the one above, I'm rethinking my answer and I think it is B or E and not A. **</p>

<p>Thanks for helping :)</p>

<p>For question 1, the answer is E.
You already have a setDate method with three integers as parameters. In the code provided, however, you have a call to the setDate method with a String and two ints (d1.setDate("May", 11, 2004);). Therefore, you need to create an overloaded version of setDate with one String and two int arguments. You also already have a constructor with one String and two ints as parameters. In the code provided, you call a constructor with three ints as arguments ( Date d3 = new Date(6, 30, 2010);) so you need to create a constructor with three int arguments. The answer is therefore E.</p>

<p>For Question 2, a method is declared private when the method is not intended to be used by clients of the class. That's what a private declaration does... it means that only an object of the class itself can use that method, or that variable, or whatever it is that you're declaring private. The answer is therefore A.</p>

<p>Dude michael. She didn't say the exams would come from that packet!</p>

<p>MICHEAL I BELIEVE I TOLD YOU BOTH OF THOSE choices also</p>