Results 1 to 6 of 6
Thread: OOP Objects and Classes help
- 03-05-2011, 04:31 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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!
- 03-05-2011, 04:45 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What exactly is your question, what are you having trouble with?
- 03-05-2011, 04:49 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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!
- 03-05-2011, 05:02 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
you created all the classes?
Do you know how to create instances of a class?
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 objectJava Code:Dog d = new Dog();
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 05:08 PM.
- 03-05-2011, 05:12 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
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!
- 03-05-2011, 05:50 PM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
-
classes and creating objects
By Latanyar in forum New To JavaReplies: 4Last Post: 11-01-2010, 07:14 PM -
Accessing objects between classes
By bikashg in forum New To JavaReplies: 7Last Post: 05-06-2010, 12:05 PM -
Classes and Objects Help
By collin389 in forum New To JavaReplies: 1Last Post: 12-14-2009, 12:44 AM -
classes as objects
By kroiz in forum New To JavaReplies: 4Last Post: 07-25-2009, 05:22 AM -
Objects and Classes
By Aleve in forum New To JavaReplies: 8Last Post: 12-31-2007, 08:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks