954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Urgent ...

If user enter all these then i need to use what to store it in a same group (many different group)

import java.util.Scanner;
class addBook
{
	public static void book()
	{

		int isbn;
		Scanner inputDevice = new Scanner (System.in);
		System.out.println("Enter ISBN ...\n");
		isbn = inputDevice.nextInt();

		int title;
		System.out.println("Enter TITLE ...\n");
		title = inputDevice.nextInt();

		int author;
		System.out.println("Enter AUTHOR NAME ...\n");
		author = inputDevice.nextInt();

		int pub;
		System.out.println("Enter Publisher ...\n");
		pub = inputDevice.nextInt();

		int pubDate;
		System.out.println("Enter DATE OF PUBLICATION ...\n");
		author = inputDevice.nextInt();



		}
}
lalaZai
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

create an Object which hold all this information in it's instance variables, and create either an array or list of objects of that type.

ps: this is not 'urgent' to most of us (well, none of us, except you maybe) and it's also very basic, you should be able to do this on your own.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

1. You will need to create a class Book where you will have various set() and get() methods like:
setISBN()
getISBN()
don't forget constructor(s)

2.A class Libray which extends Book methods here:
super(...);
readData();
Furthermore make a search for:
a)Generics
b)ArrayList

If you have any questions post here or send me a Private Message.

kyriacos1986
Light Poster
42 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

1. You will need to create a class Book where you will have various set() and get() methods like: setISBN() getISBN() don't forget constructor(s)

2.A class Libray which extends Book methods here: super(...); readData(); Furthermore make a search for: a)Generics b)ArrayList

If you have any questions post here or send me a Private Message.

unless you want to see your teacher burst out in a laughing fit when you hand in your code, don't do that.
as far as I am aware, a library HAS books it is not a SUBTYPE of book.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

^ yes.
And why setISBN? A book's ISBN never changes. Declare it final and require it as a parameter in the constructor(s).
Finally DaniWeb Member Rules include:
"Do not ask anyone (member or moderator) for help by email or PM"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
post your questions in the forum so others can help answer it and more people can learn from it.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

Hi James. If we have to create objects of type Book for a bookstore or a library, we don't need to create set methods to store different values(String, int, etc.) when is needed? Otherwise we will not be able to create object. I am quite new with java and still learning.

kyriacos1986
Light Poster
42 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

For values that can change, yes. But if you have something like ISBN every book must have one, and it never changes, so the best way is to require it as a parameter in the constructor (so you can't create a book without an ISBN), and don't have a setISBN method so nobody can change it. The same is true of title and author. But if you have, for example, which shelf the book is on then you need set and get methods for that because the book can be moved to a different shelf, similar for price, becuase the price can change.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 
Hi James. If we have to create objects of type Book for a bookstore or a library, we don't need to create set methods to store different values(String, int, etc.) when is needed? Otherwise we will not be able to create object. I am quite new with java and still learning.

as JamesCherrill pointed out: an ISBN number, just like a title or author, of a book will NEVER change once it has been set. about the only thing that can change is the price, so that is the only variable you actually need a setter for.

all the other information can be set using the constructor.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You