Share
Explore BrainMass

Java Book Console Application

I need a complete Java code for the following beginner-level assignment. The code does not have to be pretty as long as it works... So here's the assignment:

You run a small library. Ask the user to provide information for several books. The information must include the author, title and publisher of each book. Create a book class which stores the information and implements the following methods:

getAuthor() (returns author's name)

getTitle() (returns the title)

getPublisher() (returns the publisher of the book)

Finally print all the stored information to the user.

Tip 1: Remember the constructor.
Tip 2: You can use an arraylist.

This is how it should look like:

Do you want to input a new book (y/n)?

y

Author:

Jacob Smith

Book title:

Investment Banking

Publisher:

Oxford Press

Do you want to input a new book (y/n)?

y

Author:

Mary Dickins

Book title:

Advanced Econometrics

Publisher:

London Publishing House

Do you want to input a new book (y/n)?

n

The library contains:

2 books

Books:

Jacob Smith, Investment Banking, Oxford Press

Mary Dickins, Advanced Econometrics, London Publishing House

Solution Preview

This assignment may be accomplished with little coding and I will walk you through it. Always remember there is more than one way to accomplish something in Java. This sounds like a console application so I will keep it limited to the console, examples are listed here and included in a text file.

Imports in Java allow your application to use classes form the Java standard library. In this application you need to use a Scanner so your application may collect user input. this is done by using:

import java.util.*;

Thinking of the Book class, the properties needed are author, title, and publisher. The constructor of the class will help to declare and initialize these properties.

public class Book{

String Author;
String Title;
String Publisher;

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

Author = author;
Title = title;
Publisher = publisher;

}
public String toString()
{
return this.Author+" ,"+ this.Title+" ...

Solution Summary

This lesson will explain how to create a console application in java that uses the scanner class, array list, anonymous class, and an enhanced for loop to iterate through the array list.

$2.19