Results 1 to 13 of 13
  1. #1
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Help with Bicycle class

    Ive been stuck on this for awhile now about 2 hrs combined of trying to figure this one out

    Im trying to set an Expiration date to a library card

    Library Card
    Java Code:
    import java.text.*;
    class LibraryCard{
    
    
    	//Data Members
    	private String GregorianCalendar,
    					 date;
    	private int 	expYear,
    					expDate,
    					 expMonth,
    					 expDay;
    	//student owner of this card
    	private Student owner;
    	
    	//number of books borrowed
    	private int borrowCnt;
    	
    
    	//Constructor
    	public LibraryCard( ){
    		owner = null;
    		borrowCnt = 0;
    	}
    	//numOfBooks are checked out
    	public void checkOut(int numOfBooks) {
    		borrowCnt = borrowCnt + numOfBooks;
    	} 
    	//set the expiration date
    	public void setExpDate(GregorianCalendar date){
    	 date = expYear + expMonth + expDay;
    	}	
    	//returns the expiration year
    	public int getExpYear(int ){
    		return expYear;
    	}
    	//returns the exp month
    	public int getExpMonth(int ){
    		return expMonth;
    	}
    	//returns the ecp day
    	public int getExpDay (int ){
    		return expDay;
    	}
    
    	//Returns the number of books borrowed
    	public int getNumberOfBooks( ) {
    		return borrowCnt;
    	}	
    	
    	//Returns the name of the owner of this card
    	public String getOwnerName( ){
    		return owner.getName( );
    	}
    	//set owner of this card to student
    	public void setOwner(Student student){
    		owner = student;
    	}
    	//Returns the string representation of this card
    	public String toString( ){
    		return "Expiration Date" + expDate + "Owner Name:		" + owner.getName( ) + "\n" + "		Email:	" + owner.getEmail( ) + "\n" +"Age:	"+owner.getAge( ) +"\n" + "Books Borrowed: " + borrowCnt;
    	}
    }
    Java Code:
    [CENTER]Librarian[/CENTER]
    /**
     * @(#)Librarian.java
     *
     * Librarian application
     *
     * @author 
     * @version 1.00 2013/1/24
     */
     import java.util.*;
    public class Librarian {
        
        public static void main(String[] args) {
        	
        	Student		student1, student2;
        	LibraryCard card1, card2;
        	
        	student1 = new Student ( );
        	student1.setName("Jon Java");
        	student1.setEmail("jj@javauniv.edu");
        	student1.setAge("22");
        	
        	student2 = new Student ( );
        	student2.setName("Bailey PenisFace");
        	student2.setEmail("baileylangford@att.net");
        	student2.setAge("28");
        	
        	card1 = new LibraryCard( );
        	card1.setOwner(student1);
        	card1.checkOut(3);
        	card1.expDay(25);
        	card1.expMonth(12);
        	card1.expYear(2012);
        	
        	card2 = new LibraryCard ( );
        	card2.setOwner(student2);
        	card2.checkOut(130);
        	
        	System.out.println("Card1 Info:");
        	System.out.println(card1.toString() + "\n");
        	
        	System.out.println("Card2 Info:");
        	System.out.println(card2.toString() +"\n");	
        }
    }
    Last edited by easyeatlanta; 02-06-2013 at 07:11 PM.

  2. #2
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with Bicycle class

    i keep getting that it can't find the GregorianCalendar and then I added int and messed other stuff up

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Help with Bicycle class

    What does the code and question have to do with a Bicycle class? Can you edit your post and correct this? Also please add [code] [/code] tags so your code may be readable. Please read the link in my signature links below for more on this.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Help with Bicycle class

    Also what is the purpose of your having a String field called "GregorianCalendar" as that doesn't make sense. Also, are you sure that you want to use a Calendar object and not a Date field?

  5. #5
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with Bicycle class

    My text book problem specifically listed that I was to use
    public void setExpDate(GregorianCalendar date){...}

  6. #6
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with Bicycle class

    and as far as making a string
    I have really just gotten to the point where I am going to try everything i can think of

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Help with Bicycle class

    Yeah, get rid of the String bit as that won't work. You will need to import the GregorianCalendar class in order to be able to use it. Also and again, what does this question have to do with a Bicycle class?

  8. #8
    jp_armystrong is offline Member
    Join Date
    Jan 2013
    Location
    Stockton, CA
    Posts
    2
    Rep Power
    0

    Default Re: Help with Bicycle class

    use eclipse it will point out the classes to import

  9. #9
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with Bicycle class

    I thought that when using seperate classes it was called a bicycle method or at least that was the example used in the book

    and I did just download eclispse so i will try that out

  10. #10
    easyeatlanta is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help with Bicycle class

    i changed it to this and still cant find my expDate, expMonth, expYear variables

    Java Code:
    import java.text.*;
    class GregorianCalendar{
    class LibraryCard{
    
    
    	//Data Members
    	
    	//student owner of this card
    	private Student owner;
    	
    	//number of books borrowed
    	private int borrowCnt;
    	
    
    	//Constructor
    	public LibraryCard( ){
    		owner = null;
    		borrowCnt = 0;
    	}
    	//numOfBooks are checked out
    	public void checkOut(int numOfBooks) {
    		borrowCnt = borrowCnt + numOfBooks;
    	} 
    	//set the expiration date
    	public void setExpDate(GregorianCalendar date){
    	 date = expYear + expMonth + expDay;
    	}	
    	//returns the expiration year
    	public int getExpYear( ){
    		return expYear;
    	}
    	//returns the exp month
    	public int getExpMonth( ){
    		return expMonth;
    	}
    	//returns the ecp day
    	public int getExpDay ( ){
    		return expDay;
    	}
    
    	//Returns the number of books borrowed
    	public int getNumberOfBooks( ) {
    		return borrowCnt;
    	}	
    	
    	//Returns the name of the owner of this card
    	public String getOwnerName( ){
    		return owner.getName( );
    	}
    	//set owner of this card to student
    	public void setOwner(Student student){
    		owner = student;
    	}
    	//Returns the string representation of this card
    	public String toString( ){
    		return "Expiration Date" + expDate + "Owner Name:		" + owner.getName( ) + "\n" + "		Email:	" + owner.getEmail( ) + "\n" +"Age:	"+owner.getAge( ) +"\n" + "Books Borrowed: " + borrowCnt;
    	}
    }
    }

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help with Bicycle class

    Quote Originally Posted by easyeatlanta View Post
    i changed it to this and still cant find my expDate, expMonth, expYear variables
    Neither can I; do you mind showing us their declaration?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Help with Bicycle class

    No.
    You import GregorianCalendar.
    It's a standard Java class.
    Please do not ask for code as refusal often offends.

  13. #13
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    748
    Rep Power
    2

    Default Re: Help with Bicycle class

    This will not work:
    Java Code:
    class GregorianCalendar{
    class LibraryCard{
    In your first example you nearly had it right. It should say:
    Java Code:
    private GregorianCalendar date;
    without the String part (as already pointed out by others)

    I think the use of the setter method setExpDate(GregorianCalendar date) should not be what you have:
    Java Code:
    public void setExpDate(GregorianCalendar date){
      date = expYear + expMonth + expDay;
    }
    This works the other way around. The method gets a GergorianCalendar object as parameter and you are supposed (I assume) to extract a date, month and year into the corresponding variables. GregorianCalendar has methods for that. If I am not mistaken, it should be something like date.get(Calendar.DATE); (See Java Platform SE 6)
    Something along the lines of this:
    Java Code:
    public void setExpDate(GregorianCalendar date){
      expYear = date.get(Calendar.YEAR);
      ....
    }

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2012, 03:06 AM
  2. Replies: 1
    Last Post: 11-29-2012, 09:46 AM
  3. Replies: 0
    Last Post: 12-07-2011, 11:55 AM
  4. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  5. Replies: 5
    Last Post: 01-26-2011, 06:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •