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();



		}
}

Edited 4 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

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.

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.

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.

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.

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.

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.

This article has been dead for over six months. Start a new discussion instead.