Results 1 to 5 of 5
  1. #1
    umairrockx is offline Member
    Join Date
    Jul 2011
    Location
    Universe
    Posts
    5
    Rep Power
    0

    Arrow newbie: Getting started with java, need help on this

    Hello,

    so basically i am getting started with java.. I am doing work on eclipse, i am making a library project as a sample..

    The library project includes the class of person and books..

    here is my sample class of person:
    Java Code:
    package Library;
    
    public class person {
    	private String name;
    	private int maxBooks;
    	
    public person(){
    	name = "unknown name";
    	maxBooks = 0;	
    }
    
    public String getName(){
    	return name;
    	
    }
    
    public int getMaxBooks() {
    	return maxBooks;
    }
    
    public void setMaxBooks(int maxBooks) {
    	this.maxBooks = maxBooks;
    }
    
    public void setName(String name) {
    	this.name = name;
    }
    
    }
    I have done this, but now i need code by which a user will enter his maxBooks and Name, and also a code that will output name and maximum books of the person, it may be like this?
    system.out.println(getPerson.name)
    ?

    I have only taken two classes of java yet, sorry for this noob question.
    Thanks for reading.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,764
    Rep Power
    7

    Default

    You should abide by Java naming standards. Your class should be Person not person.

    You need to write another test class. In the main method create a Person object and call some of the methods of the Person class. Add a bunch of print statements (should be System not system as per your example) to see what is happening. If you don't know about calling methods and passing parameters then read a tutuorial online (there should be plenty) or a book. Once you have done that, attempted to write some code and get stuck come back here and ask a specific question. "It doesn't work" is not specific nor a question.

  3. #3
    umairrockx is offline Member
    Join Date
    Jul 2011
    Location
    Universe
    Posts
    5
    Rep Power
    0

    Arrow

    okay I follow the java naming convention as per your instructions, i have read some tutorials, and trying to call the Person.java in the Books.java.
    Books.java records the book title, author and person(person.java needs to be called).

    here is books.java
    Java Code:
    package Library;
    
    public class Books {
    
    	private String title;
    	private String author;
    	private String person;
    	
    public void books(){
    	title = "unknown title";
    	author = "unknown author";
    	person = "getPerson.name";
    }
    
    public String getTitle() {
    	return title;
    }
    
    public void setTitle(String title) {
    	this.title = title;
    }
    
    public String getAuthor() {
    	return author;
    }
    
    public void setAuthor(String author) {
    	this.author = author;
    }
    
    	
    }
    I am calling person.java, so need to add some code in it, i.e, when someone runs the books.java, it shows the name of the person who own it.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,764
    Rep Power
    7

    Default

    Quote Originally Posted by umairrockx View Post
    trying to call the Person.java in the Books.java.
    Why?

    Pick up any book, look very carefully at it and ask yourself "Does the book know anything about me?", "Does the book need to know anything about me?".

    What does need to know information about Book and Person is a Library. The Library will hold information about Books, Persons and what Books have been borrowed by which Persons.

  5. #5
    umairrockx is offline Member
    Join Date
    Jul 2011
    Location
    Universe
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    what Books have been borrowed by which Persons.
    This is what i am trying to do, can't get on it..

Similar Threads

  1. Replies: 2
    Last Post: 11-29-2009, 12:37 PM
  2. New to JAVA and need some help getting a started
    By SMHouston in forum New To Java
    Replies: 45
    Last Post: 09-05-2009, 09:55 AM
  3. How Does One Get Started Learning Java?
    By Wataru in forum New To Java
    Replies: 29
    Last Post: 08-08-2009, 10:45 AM
  4. Just started with Java
    By javades in forum New To Java
    Replies: 2
    Last Post: 07-24-2008, 06:39 AM
  5. Just getting started with java
    By DuceDuceExplorer in forum Introductions
    Replies: 4
    Last Post: 06-29-2008, 06:13 AM

Posting Permissions

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