Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Need some help programing Java

Need some help programing Java
Thread Tools
Senior User
Join Date: Dec 2002
Location: Canada.
Status: Offline
Reply With Quote
Oct 13, 2006, 02:39 PM
 
This is the question on my assignment. I don't really understand it, and our text is terrible. Just wondering if someone could clarify this or help me out in some way.

Write a class date that represents a day of the year. Class Date should have a String data field for month and int data fields for day and year. Write a constructor, getter and setter methods, and a toString() method for this class. Also write a reset() method that changes the Date object to which it is applied back to the first day of the year.

Write an application class to test your methods.
I understand that months have to be a String, years have to be int. The rest of it is new and getting more difficult, and the text really does suck. I think I'm going to buy a different one as well. I'm confused.

Anyways, can anyone help me out here?
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 13, 2006, 03:13 PM
 
You might try the Java tutorial on Sun's site. If your book doesn't explain this stuff, it is truly terrible.

A constructor is the method that's called when you create an instance. For example, new MyClass() calls the constructor MyClass() in the class MyClass. A getter gets an instance variable. A setter sets an instance variable. The toString() method would return a string representation of the date.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Senior User
Join Date: Dec 2002
Location: Canada.
Status: Offline
Reply With Quote
Oct 13, 2006, 04:17 PM
 
No it is bad. One of the lab instructors told us that even he cannot understand our textbook. I'm going to go ask him about some other Java books I could buy.
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
     
Senior User
Join Date: Dec 2002
Location: Canada.
Status: Offline
Reply With Quote
Oct 13, 2006, 04:34 PM
 
Well I still do not get this. I need a Java for Dummies book or something
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
     
Fresh-Faced Recruit
Join Date: Jul 2005
Status: Offline
Reply With Quote
Oct 13, 2006, 08:26 PM
 
To add to what ChunkIt said. The question is asking you to create a class Date that will represent a day of the year. Think of classes like blueprints for things (a blueprint for a hammer) and objects as an instance of that class (an actual hammer). It tells you what kinds of data types will make up your class, just like a hammer has parts that work together to do something (the wooden handle, the metal head, the glue that holds them together).

A constructor is a function that is used to initialize an object. Working with the hammer analogy, think that your data types are materials, so when someone asks your class "give me a hammer" the constructor takes the raw elements and composes a usable class (take metal use it to form a hammer head...take an integer type and use it as a variable for the year). You could use the constructor to initialize the date to start on January 1rst for instance. Remember that the computer only does what you tell it to, so if you create a date it doesn't know what date to start on unless you tell it.

A "getter" is a probably meaning a function that will retrieve a variable, so if you have three variable, month, day, year, someone in some other function could say get(month); and your class should respond with a string that is the current month. The same applies for the other two variables. With the hammer analogy, you would be asking the class what color the hammer is, for example.

A "setter" then is a function that will set a variable in your class. It will probably tell your class two things, what variable you want to set and the value you want to set it to. This would be like saying "ok I have this hammer, I want it to be red", color would be a variable and "red" would be its value.

A reset method would restore the date to whatever you started with. So if your date started with January 1rst, then if the current date is March 4th, you could call the reset() function and the date would then be January 1rst again. Think about how you could do this and you'll see it is similar to another part of the project.

A toString method will allow some other program or function to see what the current date is since you will print out your variables. You could make the date look like month-day-year, year-day-month, or anything you want. It's like saying "ok if you want to know what this hammer looks like, this is how I'm going to draw it for you".

An application class would be a java program that tests whether or not you can do the above things: can you create the date object correctly? can you retrieve variable values? can you set them?

You should try to get a firm handle on what constructors/classes/objects/methods are and how they are used before attacking problems like this. Research those things and then tackle the logic for the program Good luck.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 14, 2006, 11:27 AM
 
Originally Posted by PrOeliuM
A reset method would restore the date to whatever you started with. So if your date started with January 1rst, then if the current date is March 4th, you could call the reset() function and the date would then be January 1rst again.
Just to be clear, this isn't quite how it's specified. The assignment says the reset method should set the date to "the first day of the year." Which makes the name of the method kind of odd, but whatevs.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:38 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2