Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: First Java class. Cannot figure out programming assignment. Please help.

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default First Java class. Cannot figure out programming assignment. Please help.

    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:


    public class Asset
    {
    private String assetID;
    private double cost;
    private int lifeExpectancy;
    private String employeeID;
    private String purchaseDate;
    private String description;

    public Asset(String aid, String eid)
    {
    assetID = aid;
    employeeID = eid;
    }


    public void setAssetID(String aid)
    {
    assetID=aid;
    }

    public void setCost(double cost)
    {
    cost=cost;
    }

    public void setLifeExpectancy(int lifeExpectancy)
    {
    lifeExpectancy=lifeExpectancy;
    }

    public void setEmployeeID(String eid)
    {
    employeeID=eid;
    }

    public void setPurachaseDate(String purchaseDate)
    {
    purchaseDate=purchaseDate;
    }

    public void setDescription(String description)
    {
    description=description;
    }

    public String assetID()
    {
    return assetID;
    }

    public double cost()
    {
    return cost;
    }

    public int lifeExpectancy()
    {
    return lifeExpectancy;
    }

    public String employeeID()
    {
    return employeeID;
    }

    public String purchaseDate()
    {
    return purchaseDate;
    }

    public String description()
    {
    return description;
    }

    }

    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.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    Please explain what step you are having problems with. Ask some specific questions about your problem.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

     
    public class Asset 
    {
    	private String assetID;
    	private double cost;
    	private int lifeExpectancy;
    	private String employeeID;
    	private String purchaseDate;
    	private String description;
     
    	public Asset(String aid, String eid)
    	{
    		assetID = aid;
    		employeeID = eid;
    	}
     
     
    		public void setAssetID(String aid)
    		{
    			assetID=aid;
    		}
     
    		public void setCost(double cost)
    		{
    			cost=cost;
    		}
     
    		public void setLifeExpectancy(int lifeExpectancy)
    		{
    			lifeExpectancy=lifeExpectancy;
    		}
     
    		public void setEmployeeID(String eid)
    		{
    			employeeID=eid;
    		}
     
    		public void setPurachaseDate(String purchaseDate)
    		{
    			purchaseDate=purchaseDate;
    		}
     
    		public void setDescription(String description)
    		{
    			description=description;
    		}
     
    		public String assetID()
    		{
    			return assetID;
    		}
     
    		public double cost()
    		{
    			return cost;
    		}
     
    		public int lifeExpectancy()
    		{
    			return lifeExpectancy;
    		}
     
    		public String employeeID()
    		{
    			return employeeID;
    		}
     
    		public String purchaseDate()
    		{
    			return purchaseDate;
    		}
     
    		public String description()
    		{
    			return description;
    		}
     
    	}

    I am having trouble with the:

    Special constructor that takes and sets all data
    Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase.

    I haven't even started the other steps yet; partially because I cannot even figure these ones out.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    Special constructor that takes and sets all data
    Take a look at the tutorial: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase.
    Look at the String class's API doc for a method to change a String to uppercase.
    http://docs.oracle.com/javase/7/docs/api/
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    .

  6. #6
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    Quote Originally Posted by freestylpolaris View Post

    I am having trouble with the:

    Special constructor that takes and sets all data
    One way to figure out how this constructor should be written is to think how you would call a method from the Asset class, such as one of your getters. You could use the, "public Asset(String aid, String eid) {...}" constructor but you would be forced to set values for those two field variables. If you just want to create an object without having to change the value of any of your field variables, think how the method signature (or parameter list) should be. Once you have that figured out, setting all of the data should be straight forward.

    Quote Originally Posted by freestylpolaris View Post
    Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase.
    These two variables are String objects, so you want to look at the documentation for primitive String manipulation methods. norm provided a link for that, here is another one: JavaScript - Strings

  7. #7
    Member
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    54
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    Quote Originally Posted by freestylpolaris View Post
    Special constructor that takes and sets all data
    Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase.
    You already have one constructor that takes and sets the values for assetId and employeeId. If you do this for all your field variables, then this constructor will be created. You can also consider using the keyword, "this" in both of your constructors when setting the field variables.

    assetID and employeeID are String objects, meaning you can use primitive String methods to manipulate them. norm provided an excellent link explaining how to do this.

  8. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First Java class. Cannot figure out programming assignment. Please help.

    Resolved it; had to add another buffer in the driver class for calculating the int. All that trouble for just one buffer statement to fix it all. Thank you everybody for your help.

Similar Threads

  1. Help with Java Programming Assignment Please?
    By a21j92 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 26th, 2012, 10:35 AM
  2. java programming assignment help
    By darking123 in forum What's Wrong With My Code?
    Replies: 56
    Last Post: October 4th, 2012, 06:05 PM
  3. java programming assignment help
    By darking123 in forum Java Theory & Questions
    Replies: 0
    Last Post: October 1st, 2012, 07:26 AM
  4. Assignment Help - Need to Figure Out How to Integrate the Classes
    By joearness in forum Object Oriented Programming
    Replies: 6
    Last Post: March 7th, 2012, 08:39 AM
  5. Programming help with java assignment!
    By kami21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2011, 06:37 PM