File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Having issues with classes and objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having issues with classes and objects" Watch "Having issues with classes and objects" New topic
Author

Having issues with classes and objects

Ryan Hickman
Ranch Hand

Joined: Oct 13, 2012
Posts: 36
I have a program assigned to me for school and have no idea where to start. I don't know what it is about classes and objects but it loses me. This is what I have to make the program do:

Attributes:

String assetID
double cost
integer lifeExpectancy
String employee ID
String purchaseDate
String description

Methods:

Special construcor that sets assetID and employeeID, defualt values for the rest
Special constructor that takes and sets all data
Typical getters for all data
Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase. These setters should be called from the special constructor.
Typcial setter for the rest
Create a method called calcAge that accepts the current date in a String, formatted as mm/dd/yyyy, and returns the age (in years only).
Predicate method to decide if the component needs to be replaced; name it outdated. Return true if the age exceeds the life expectancy, return false if the age is less than or equal to the life expectancy
Method called printData that prints all data including the age of the component to the console with labels.

This is what I have so far:




Any help would be appreciated. I have no idea where to go with this since it is my first Java class taken and her assignments are a bit hard for what we have learned thus far.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
Ryan Hickman wrote: . . .
Special construcor that sets assetID and employeeID, defualt values for the rest
Special constructor that takes and sets all data
. . .
There is a spelling mistake in that. The word s-p-e-c-i-a-l should be spelt o-r-d-i-n-a-r-y.

Hint 1: Don’t try to do everything. Do one thing and get it working. Then try the next thing.
Were you told to make the set methods public? You are not going to change the original cost or purchase date of an asset ever. I wouldn’t have provided them in the first place, but if I am told to, give them private access.Because it says set methods in the assignment, I think you should query that with your instructor first, however. Also, using usual conventions, one would call the pastItsSellByDate() method isOutdated().
Methods called from the constructor should be marked private or final (you don’t need both).
How are you turning the eid method into UPPERCASE? Have you been through the String class documentation?
Ryan Hickman
Ranch Hand

Joined: Oct 13, 2012
Posts: 36
Hi. Thanks for your quick reply. I have the program just about finished now (with the help from a student that once took this class) and will post it tomorrow. I am having just one error now. I agree that it is SO much easier just to take it one thing at a time. You are definitely right about that. As for the instructions the teacher gave us; VERY unclear. Even the other student agreed. special constructor..... is just a normal constructor like you said. I spent a good amount of time researching "special constructors" for no reason. Several things in the program's description could have been worded so much simpler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having issues with classes and objects
 
Similar Threads
Session Management - Serialization
Bind class to HttpSession?
Joining tables
Unable to persist the data in hibernate
why am i getting a null value on fetching from map