Results 1 to 6 of 6
  1. #1
    richlan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default OOP Objects and Classes help

    Hello I am totally new to Programming, I'm in my 2nd semester and I've just started with Object Oriented Programming. As a first assignment we have been asked to create a library type system.
    Here is my assignment:
    Write a main function that creates some Book, Reader as well as Librarian objects and performs borrow and return operations.
    We were given 3 classes Book, Address and Person (this class consisting of two subclasses: Reader and Librarian).
    That look like this respectively:

    public class Book {

    private String title, author, publisher, ISBN;

    public Book(){

    }

    public Book(String title, String author, String publisher, String ISBN){

    }

    public String getTitle() {
    return title;
    }

    public String getAuthor() {
    return author;
    }

    public String getPublisher() {
    return publisher;
    }

    public String getISBN() {
    return ISBN;
    }

    public void setTitle(String title){
    this.title=title;
    }

    public void setAuthor(String author){
    this.author=author;
    }

    public void setPublisher(String publisher){
    this.publisher=publisher;
    }

    public void setISBN(String ISBN){
    this.ISBN=ISBN;
    }

    }

    If you need the other classes too, then I will post them.

    I stress I am a total beginner and have but one semester of experience in Java, so please please if you understand my question don't just give me a code or tell me that it is really easy, but some sort of explanation. I have no idea how I would even think to create a book from a main function somewhere!

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What exactly is your question, what are you having trouble with?

  3. #3
    richlan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Sorry, my exact question is how can I write a main function that creates some Book, Reader as well as Librarian objects and performs borrow and return operations?

    I managed to write the classes, but I don't know how to create a main function that can use my classes to create something!

    Hope that makes sense!

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    you created all the classes?

    Do you know how to create instances of a class?

    Java Code:
    Dog d = new Dog();
    this does three things, creates a reference named d of type dog, creates a dog object on the heap, and links them together so d points to the newly created dog object

    Now to get into main. Every class can have a main method, and when you run code it first starts running main which calls other methods or creates objects, etc.


    Here is a sample
    Java Code:
    public class C{
      public static void main(String[] args){
        System.out.println("hello");
      }
    }
    Last edited by sunde887; 03-05-2011 at 06:08 PM.

  5. #5
    richlan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Yes I created all the classes (Book, Address, Person, Reader extends Person and Librarian extends Person)! Would you like me to post them?
    I'm using Eclipse, so I created all the classes on a different sheet, but they are all in the same library!

    We haven't covered the instance thing in class yet, but I know how it works from reading up on the internet!

    With the main thing, would I need to put that into one of my already created classes or make a new sheet and write it there using instances? Sorry for the beginner questions!

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I don't mind the beginner questions, I come here to help people out with what I can. As far as your question, it's really up to you where you want to create the main method, you can either make a new class that simply has a main and runs everything or slap it in an existing class. I don't need you to post the code, however; if you run into more problems, i may need to see it.

Similar Threads

  1. classes and creating objects
    By Latanyar in forum New To Java
    Replies: 4
    Last Post: 11-01-2010, 08:14 PM
  2. Accessing objects between classes
    By bikashg in forum New To Java
    Replies: 7
    Last Post: 05-06-2010, 01:05 PM
  3. Classes and Objects Help
    By collin389 in forum New To Java
    Replies: 1
    Last Post: 12-14-2009, 01:44 AM
  4. classes as objects
    By kroiz in forum New To Java
    Replies: 4
    Last Post: 07-25-2009, 06:22 AM
  5. Objects and Classes
    By Aleve in forum New To Java
    Replies: 8
    Last Post: 12-31-2007, 09:05 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
  •