I thank you for any help you can give with this exercise.
I am reading about user-defined classes and ADT's for the first time.
This exercise asks me to create a UML diagram for a class called MyDate that contains data memebers and a constructor that meet the criteria for the following list. This class is used to initialize instance variables.
The nonstatic integer data members named month, day, and year should be private members so that they cannot be directly manipulated outside of the class.
The nonstatic Boolean data member named good should be a public member so that it can be accessed outside of the class.
The constructor MyDate() should assign to the member variables the values 1 to month, 1 to day, 2006 to year, and the value true to good.
Would the constructor look like this?
+MyDate()
+MyDate(1, 1, 2006, true)
So far I have
______________
MyDate
______________
-month: int
-day: int
-year: int
+good: int
_______________
+MyDate()
+MyDate(1,1,2006,true)
Thank you
Classes
Started by sthenri, Nov 19 2007 06:24 PM
2 replies to this topic
#1
Posted 19 November 2007 - 06:24 PM
|
|
|
#2
Posted 20 November 2007 - 10:56 PM
Basically, YES. Remove the plus symbol and it should work.
I'm not 100% sure what your wanting to do but heres my thoughts. Note, the code is examples only and would need minor adapting to your situation.
[HIGHLIGHT="Java"]
//assign to a variable: date
date = MyDate(1,1,2006,true);
//check a date using MyDate method
if(date == MyDate(1,1,2006,true){
return true;
else
return false;
}
//NB using return will end the method are return to parent method
[/HIGHLIGHT]
As you should be able to see, the basic answer is yes, depending on how you want to use it.
Hope this helps!
Domestic
I'm not 100% sure what your wanting to do but heres my thoughts. Note, the code is examples only and would need minor adapting to your situation.
[HIGHLIGHT="Java"]
//assign to a variable: date
date = MyDate(1,1,2006,true);
//check a date using MyDate method
if(date == MyDate(1,1,2006,true){
return true;
else
return false;
}
//NB using return will end the method are return to parent method
[/HIGHLIGHT]
As you should be able to see, the basic answer is yes, depending on how you want to use it.
Hope this helps!
Domestic
.

Programming Languages: Java, VB6, VB2005 (.NET2)
Web Languages: HTML, CSS, JS
Website: http://abdn.ac.uk/~u41am6
Opportunity is missed by most people because it is dressed in overalls and looks like work.

Programming Languages: Java, VB6, VB2005 (.NET2)
Web Languages: HTML, CSS, JS
Website: http://abdn.ac.uk/~u41am6
Opportunity is missed by most people because it is dressed in overalls and looks like work.
#3
Posted 06 December 2007 - 05:16 AM
Thank You


Sign In
Create Account


Back to top









