SlideShare a Scribd company logo
BookCollectionHelper.java
package com.cg.helper;
import java.util.ArrayList;
import java.util.Iterator;
import com.cg.bean.BookSchema;
public class BookCollectionHelper {
private static ArrayList<BookSchema> bookList=null;
static
{
bookList=new ArrayList<BookSchema>();
BookSchema b1=new BookSchema(111,"See into the Sea of C",350);
BookSchema b2=new BookSchema(222,"Learning Java in 21 Days",450.50);
BookSchema b3=new BookSchema(333,"ASP.Net with C#", 250.75);
bookList.add(b1);
bookList.add(b2);
bookList.add(b3);
}
public BookCollectionHelper(){}
/*************Add New Book in ArrayList************/
public void addNewBookDetails(BookSchema book)
{
bookList.add(book);
}
public static ArrayList<BookSchema> getbookList() {
return bookList;
}
public static void setbookList(ArrayList<BookSchema> bookList) {
BookCollectionHelper.bookList = bookList;
}
/*************Fetch All Book Details ***********/
public static void displayBookCount()
{
Iterator<BookSchema> bookIt=bookList.iterator();
BookSchema tempBook=null;
int totalCount=0;
while(bookIt.hasNext())
{
totalCount++;
tempBook=bookIt.next();
System.out.println(tempBook);
}
System.out.println("Total Count of Books" + totalCount);
}
}
/************************************************************************************
/
BookCollectionHelperTest.java
package com.cg.junit;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import com.cg.bean.BookSchema;
import com.cg.exception.BookException;
import com.cg.helper.BookCollectionHelper;
public class BookCollectionHelperTest {
static BookCollectionHelper collectionHelper;
static BookSchema book=null;
@BeforeClass
public static void beforeClass()
{
collectionHelper=new BookCollectionHelper();
book =new BookSchema(888,"Neelima", 670.75);
}
@AfterClass
public static void afterClass()
{
collectionHelper=null;
book=null;
}
@Test
public void testAddNewBook() throws BookException
{
collectionHelper.addNewBookDetails(book);
//Assert.assertEquals(4, collectionHelper.getCustList().size());
Assert.assertNotNull(collectionHelper.toString());
}
}
/************************************************************************************
**********/
BookDataValidator.java
package com.cg.helper;
import java.util.regex.Pattern;
import com.cg.exception.BookException;
public class BookDataValidator {
public static boolean validateBookName(String bookName)throws BookException
{
String custPattern="[A-Za-z]{6,20}";
if(Pattern.matches(custPattern, bookName))
{
return true;
}
else
{
throw new BookException("Book Name should start with CAPITAL & Min 6 and
Max 20 characters Allowed");
}
}
public static boolean validateBookId(String bookId)throws BookException
{
String IdPattern="d{3}";
if(Pattern.matches(IdPattern, bookId))
{
return true;
}
else
{
throw new BookException("Only 3-digit BookID is Allowed");
}
}
public static boolean validateBookPrice(String bookPrice)throws BookException
{
String pricePattern="d{2,4}.?[0-9]{2}$";
if(Pattern.matches(pricePattern, bookPrice))
{
return true;
}
else
{
throw new BookException("Only numbers (and paise if any) is Allowed");
}
}
}
/************************************************************************************
*****************/
BookException.java
package com.cg.exception;
public class BookException extends Exception {
private static final long serialVersionUID = 1L;
public BookException()
{
super();
}
public BookException(String message, Throwable cause, boolean enableSuppression, boolean
writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace);
}
public BookException(String message, Throwable cause)
{
super(message, cause);
}
public BookException(String message)
{
super(message);
}
public BookException(Throwable cause)
{
super(cause);
}
}
/************************************************************************************
***************/
BookSchema.java
package com.cg.bean;
public class BookSchema {
private int bookId;
private String bookName;
private double bookPrice;
public BookSchema() { }
public BookSchema(int bookId, String bookName, double bookPrice) {
this.bookId = bookId;
this.bookName = bookName;
this.bookPrice = bookPrice;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public double getBookPrice() {
return bookPrice;
}
public void setBookPrice(double bookPrice) {
this.bookPrice = bookPrice;
}
@Override
public String toString() {
return "Book [bookId=" + bookId + ", bookName="
+ bookName + ", bookPrice=" + bookPrice + "]";
}
}
/************************************************************************************
***************/
BookUI.java
package com.cg.ui;
import java.util.Scanner;
import com.cg.bean.BookSchema;
import com.cg.exception.BookException;
import com.cg.helper.BookCollectionHelper;
import com.cg.helper.BookDataValidator;
public class BookUI {
static Scanner sc=new Scanner(System.in);
static BookCollectionHelper collectionhelper=null;
@SuppressWarnings("static-access")
public static void main(String[] args) {
// TODO Auto-generated method stub
int choice=0;
collectionhelper=new BookCollectionHelper();
while(true)
{
System.out.println("1:Add New Book n"+
"2:Find total count of books n3:Exit");
System.out.println("nEnter UR Choice: ");
choice=sc.nextInt();
switch(choice)
{
case 1: enterNewBookDetails();break;
case 2: collectionhelper.displayBookCount();break;
default:System.exit(0);
}
}
}
private static void enterNewBookDetails()
{
System.out.println("How many new Books ? ");
int bcount=sc.nextInt();
while (bcount!=0) {
System.out.println("Enter Book Id:");
String bookId=sc.next();
try
{
if(BookDataValidator.validateBookId(bookId))
System.out.println("Enter Book name:");
String bookName=sc.next();
if(BookDataValidator.validateBookName(bookName))
{
System.out.println("Enter Price ");
String bookPrice =sc.next();
if(BookDataValidator.validateBookPrice(bookPrice))
{
BookSchema book=new
BookSchema(Integer.parseInt(bookId), bookName, Double.parseDouble(bookPrice));
collectionhelper.addNewBookDetails(book);
}
}
}
catch (BookException e)
{
System.out.println(e.getMessage());
}
bcount--;
}
}
}
/************************************************************************************
**********************/
help file for Book.txt
Note:
1. Include the jar files required for junit.
2. The executable file is : BookUI.java
-------
Create files in the following sequence :
1. BookSchema
2. BookUI
3. BookDataValidator & BookCollectionHelper
4. BookException & bbokCollectionHelperTest

More Related Content

What's hot

MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talkMooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
Jose Luis Martínez
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
Stephane Belkheraz
 
MongoDB
MongoDBMongoDB
MongoDB
Steve Klabnik
 
Time Code: Automating Tasks in WordPress with WP-Cron
Time Code: Automating Tasks in WordPress with WP-CronTime Code: Automating Tasks in WordPress with WP-Cron
Time Code: Automating Tasks in WordPress with WP-Cron
Shawn Hooper
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
Walter Dal Mut
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
Will Button
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
MongoDB
 
Sequelize
SequelizeSequelize
Sequelize
Tarek Raihan
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
Amanda Gilmore
 
Couchdb
CouchdbCouchdb
Couchdb
Brian Smith
 
Google's Guava
Google's GuavaGoogle's Guava
Google's Guava
Robert Bachmann
 
Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012yantoit2011
 
Hadoop
HadoopHadoop
Java assgn
Java assgnJava assgn
Java assgnaa11bb11
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with Xamarin
Lorenz Cuno Klopfenstein
 
Getting Started With MongoDB
Getting Started With MongoDBGetting Started With MongoDB
Getting Started With MongoDB
Bill Kunneke
 
20190627 j hipster-conf- diary of a java dev lost in the .net world
20190627   j hipster-conf- diary of a java dev lost in the .net world20190627   j hipster-conf- diary of a java dev lost in the .net world
20190627 j hipster-conf- diary of a java dev lost in the .net world
Daniel Petisme
 
SQL, noSQL or no database at all? Are databases still a core skill?
SQL, noSQL or no database at all? Are databases still a core skill?SQL, noSQL or no database at all? Are databases still a core skill?
SQL, noSQL or no database at all? Are databases still a core skill?
Neil Saunders
 

What's hot (20)

MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talkMooseX::Datamodel - Barcelona Perl Workshop Lightning talk
MooseX::Datamodel - Barcelona Perl Workshop Lightning talk
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
MongoDB
MongoDBMongoDB
MongoDB
 
Time Code: Automating Tasks in WordPress with WP-Cron
Time Code: Automating Tasks in WordPress with WP-CronTime Code: Automating Tasks in WordPress with WP-Cron
Time Code: Automating Tasks in WordPress with WP-Cron
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
Latinoware
LatinowareLatinoware
Latinoware
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Sequelize
SequelizeSequelize
Sequelize
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
Couchdb
CouchdbCouchdb
Couchdb
 
Google's Guava
Google's GuavaGoogle's Guava
Google's Guava
 
Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012
 
Hadoop
HadoopHadoop
Hadoop
 
Java assgn
Java assgnJava assgn
Java assgn
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with Xamarin
 
Getting Started With MongoDB
Getting Started With MongoDBGetting Started With MongoDB
Getting Started With MongoDB
 
QTP
QTPQTP
QTP
 
20190627 j hipster-conf- diary of a java dev lost in the .net world
20190627   j hipster-conf- diary of a java dev lost in the .net world20190627   j hipster-conf- diary of a java dev lost in the .net world
20190627 j hipster-conf- diary of a java dev lost in the .net world
 
SQL, noSQL or no database at all? Are databases still a core skill?
SQL, noSQL or no database at all? Are databases still a core skill?SQL, noSQL or no database at all? Are databases still a core skill?
SQL, noSQL or no database at all? Are databases still a core skill?
 

Similar to Book integrated assignment

First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-entechbed
 
03 - Prototype Design Pattern - Slideshare.pptx
03 - Prototype Design Pattern - Slideshare.pptx03 - Prototype Design Pattern - Slideshare.pptx
03 - Prototype Design Pattern - Slideshare.pptx
SubhechhaMajumdar1
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
Andrea Iacono
 
Library Managment System - C++ Program
Library Managment System - C++ ProgramLibrary Managment System - C++ Program
Library Managment System - C++ Program
Muhammad Danish Badar
 
Save Repository From Save
Save Repository From SaveSave Repository From Save
Save Repository From Save
Norbert Orzechowicz
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
Corley S.r.l.
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
DEVTYPE
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com Jetpack
Nelson Glauber Leal
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
SHIVA101531
 
A class called Book is designed as shown in the class diagram. It co.docx
 A class called Book is designed as shown in the class diagram.  It co.docx A class called Book is designed as shown in the class diagram.  It co.docx
A class called Book is designed as shown in the class diagram. It co.docx
ajoy21
 
Using Azure Storage for Mobile
Using Azure Storage for MobileUsing Azure Storage for Mobile
Using Azure Storage for Mobile
Glenn Stephens
 
culadora cientifica en java
culadora cientifica en javaculadora cientifica en java
culadora cientifica en java
Jorge Llocclla Rojas
 
Intro to Dependency Injection - Or bar
Intro to Dependency Injection - Or bar Intro to Dependency Injection - Or bar
Intro to Dependency Injection - Or bar
DroidConTLV
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
영욱 김
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple Developers
Peter Friese
 

Similar to Book integrated assignment (20)

First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
03 - Prototype Design Pattern - Slideshare.pptx
03 - Prototype Design Pattern - Slideshare.pptx03 - Prototype Design Pattern - Slideshare.pptx
03 - Prototype Design Pattern - Slideshare.pptx
 
Week 1 assignment q2
Week 1 assignment q2Week 1 assignment q2
Week 1 assignment q2
 
Week 1 Assignment Q2 Solution
Week 1 Assignment Q2 SolutionWeek 1 Assignment Q2 Solution
Week 1 Assignment Q2 Solution
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
 
Library Managment System - C++ Program
Library Managment System - C++ ProgramLibrary Managment System - C++ Program
Library Managment System - C++ Program
 
Save Repository From Save
Save Repository From SaveSave Repository From Save
Save Repository From Save
 
API Design
API DesignAPI Design
API Design
 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com Jetpack
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
 
A class called Book is designed as shown in the class diagram. It co.docx
 A class called Book is designed as shown in the class diagram.  It co.docx A class called Book is designed as shown in the class diagram.  It co.docx
A class called Book is designed as shown in the class diagram. It co.docx
 
Using Azure Storage for Mobile
Using Azure Storage for MobileUsing Azure Storage for Mobile
Using Azure Storage for Mobile
 
culadora cientifica en java
culadora cientifica en javaculadora cientifica en java
culadora cientifica en java
 
Intro to Dependency Injection - Or bar
Intro to Dependency Injection - Or bar Intro to Dependency Injection - Or bar
Intro to Dependency Injection - Or bar
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple Developers
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
 

More from Akash gupta

Resume arti soni
Resume arti soniResume arti soni
Resume arti soni
Akash gupta
 
Resume
Resume Resume
Resume
Akash gupta
 
Chap3
Chap3Chap3
Chap2
Chap2Chap2
Chap1
Chap1Chap1
Answers to-500-istqb-sample-papers-2010-2011
Answers to-500-istqb-sample-papers-2010-2011Answers to-500-istqb-sample-papers-2010-2011
Answers to-500-istqb-sample-papers-2010-2011
Akash gupta
 
500 istqb-sample-papers-2010-2011
500 istqb-sample-papers-2010-2011500 istqb-sample-papers-2010-2011
500 istqb-sample-papers-2010-2011
Akash gupta
 
Istqb fl chap_6_edited
Istqb fl chap_6_editedIstqb fl chap_6_edited
Istqb fl chap_6_edited
Akash gupta
 
Istqb fl chap_5_edited
Istqb fl chap_5_editedIstqb fl chap_5_edited
Istqb fl chap_5_edited
Akash gupta
 
Istqb fl chap_4_edited
Istqb fl chap_4_editedIstqb fl chap_4_edited
Istqb fl chap_4_edited
Akash gupta
 
Istqb fl chap_3_edited
Istqb fl chap_3_editedIstqb fl chap_3_edited
Istqb fl chap_3_edited
Akash gupta
 
Istqb fl chap_1_edited
Istqb fl chap_1_editedIstqb fl chap_1_edited
Istqb fl chap_1_edited
Akash gupta
 
Istqb fl chap_2_edited
Istqb fl chap_2_editedIstqb fl chap_2_edited
Istqb fl chap_2_edited
Akash gupta
 
Chap6
Chap6Chap6
Chap5
Chap5Chap5
Chap4
Chap4Chap4
Capgemini resume template
Capgemini resume templateCapgemini resume template
Capgemini resume template
Akash gupta
 
Casestudy
CasestudyCasestudy
Casestudy
Akash gupta
 
Automation practice (my store) document
Automation practice (my store) documentAutomation practice (my store) document
Automation practice (my store) document
Akash gupta
 
Vehicle feedback
Vehicle feedbackVehicle feedback
Vehicle feedback
Akash gupta
 

More from Akash gupta (20)

Resume arti soni
Resume arti soniResume arti soni
Resume arti soni
 
Resume
Resume Resume
Resume
 
Chap3
Chap3Chap3
Chap3
 
Chap2
Chap2Chap2
Chap2
 
Chap1
Chap1Chap1
Chap1
 
Answers to-500-istqb-sample-papers-2010-2011
Answers to-500-istqb-sample-papers-2010-2011Answers to-500-istqb-sample-papers-2010-2011
Answers to-500-istqb-sample-papers-2010-2011
 
500 istqb-sample-papers-2010-2011
500 istqb-sample-papers-2010-2011500 istqb-sample-papers-2010-2011
500 istqb-sample-papers-2010-2011
 
Istqb fl chap_6_edited
Istqb fl chap_6_editedIstqb fl chap_6_edited
Istqb fl chap_6_edited
 
Istqb fl chap_5_edited
Istqb fl chap_5_editedIstqb fl chap_5_edited
Istqb fl chap_5_edited
 
Istqb fl chap_4_edited
Istqb fl chap_4_editedIstqb fl chap_4_edited
Istqb fl chap_4_edited
 
Istqb fl chap_3_edited
Istqb fl chap_3_editedIstqb fl chap_3_edited
Istqb fl chap_3_edited
 
Istqb fl chap_1_edited
Istqb fl chap_1_editedIstqb fl chap_1_edited
Istqb fl chap_1_edited
 
Istqb fl chap_2_edited
Istqb fl chap_2_editedIstqb fl chap_2_edited
Istqb fl chap_2_edited
 
Chap6
Chap6Chap6
Chap6
 
Chap5
Chap5Chap5
Chap5
 
Chap4
Chap4Chap4
Chap4
 
Capgemini resume template
Capgemini resume templateCapgemini resume template
Capgemini resume template
 
Casestudy
CasestudyCasestudy
Casestudy
 
Automation practice (my store) document
Automation practice (my store) documentAutomation practice (my store) document
Automation practice (my store) document
 
Vehicle feedback
Vehicle feedbackVehicle feedback
Vehicle feedback
 

Recently uploaded

Fashionista Chic Couture Mazes and Coloring AdventureA
Fashionista Chic Couture Mazes and Coloring AdventureAFashionista Chic Couture Mazes and Coloring AdventureA
Fashionista Chic Couture Mazes and Coloring AdventureA
julierjefferies8888
 
Fed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine ZorbaFed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine Zorba
mariavlachoupt
 
This is a certificate template for Daily Vacation Bible School Awards Can edi...
This is a certificate template for Daily Vacation Bible School Awards Can edi...This is a certificate template for Daily Vacation Bible School Awards Can edi...
This is a certificate template for Daily Vacation Bible School Awards Can edi...
RodilynColampit
 
Rishikesh @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
Rishikesh  @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model SafeRishikesh  @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
Rishikesh @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
hilij84961
 
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
zeyhe
 
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
iraqartsandculture
 
HOW TO USE PINTEREST_by: Clarissa Credito
HOW TO USE PINTEREST_by: Clarissa CreditoHOW TO USE PINTEREST_by: Clarissa Credito
HOW TO USE PINTEREST_by: Clarissa Credito
ClarissaAlanoCredito
 
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
taqyed
 
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdfWEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
AntonetteLaurio1
 
A Brief Introduction About Hadj Ounis
A Brief  Introduction  About  Hadj OunisA Brief  Introduction  About  Hadj Ounis
A Brief Introduction About Hadj Ounis
Hadj Ounis
 
Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)
SuryaKalyan3
 
Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)
SuryaKalyan3
 
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
zeyhe
 
Cream and Brown Illustrative Food Journal Presentation.pptx
Cream and Brown Illustrative Food Journal Presentation.pptxCream and Brown Illustrative Food Journal Presentation.pptx
Cream and Brown Illustrative Food Journal Presentation.pptx
cndywjya001
 
Codes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new newCodes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new new
ZackSpencer3
 
Complete Lab 123456789123456789123456789
Complete Lab 123456789123456789123456789Complete Lab 123456789123456789123456789
Complete Lab 123456789123456789123456789
vickyvikas51556
 
Investors Data Sample containing data.csv.pdf
Investors Data Sample containing data.csv.pdfInvestors Data Sample containing data.csv.pdf
Investors Data Sample containing data.csv.pdf
danielses2
 
Caffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire WilsonCaffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire Wilson
ClaireWilson398082
 

Recently uploaded (18)

Fashionista Chic Couture Mazes and Coloring AdventureA
Fashionista Chic Couture Mazes and Coloring AdventureAFashionista Chic Couture Mazes and Coloring AdventureA
Fashionista Chic Couture Mazes and Coloring AdventureA
 
Fed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine ZorbaFed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine Zorba
 
This is a certificate template for Daily Vacation Bible School Awards Can edi...
This is a certificate template for Daily Vacation Bible School Awards Can edi...This is a certificate template for Daily Vacation Bible School Awards Can edi...
This is a certificate template for Daily Vacation Bible School Awards Can edi...
 
Rishikesh @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
Rishikesh  @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model SafeRishikesh  @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
Rishikesh @ℂall @Girls ꧁❤Book❤꧂@ℂall @Girls Service Vip Top Model Safe
 
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
 
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
 
HOW TO USE PINTEREST_by: Clarissa Credito
HOW TO USE PINTEREST_by: Clarissa CreditoHOW TO USE PINTEREST_by: Clarissa Credito
HOW TO USE PINTEREST_by: Clarissa Credito
 
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
 
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdfWEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
WEEK 11 PART 1- SOULMAKING (ARTMAKING) (1).pdf
 
A Brief Introduction About Hadj Ounis
A Brief  Introduction  About  Hadj OunisA Brief  Introduction  About  Hadj Ounis
A Brief Introduction About Hadj Ounis
 
Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)
 
Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)
 
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
 
Cream and Brown Illustrative Food Journal Presentation.pptx
Cream and Brown Illustrative Food Journal Presentation.pptxCream and Brown Illustrative Food Journal Presentation.pptx
Cream and Brown Illustrative Food Journal Presentation.pptx
 
Codes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new newCodes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new new
 
Complete Lab 123456789123456789123456789
Complete Lab 123456789123456789123456789Complete Lab 123456789123456789123456789
Complete Lab 123456789123456789123456789
 
Investors Data Sample containing data.csv.pdf
Investors Data Sample containing data.csv.pdfInvestors Data Sample containing data.csv.pdf
Investors Data Sample containing data.csv.pdf
 
Caffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire WilsonCaffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire Wilson
 

Book integrated assignment

  • 1. BookCollectionHelper.java package com.cg.helper; import java.util.ArrayList; import java.util.Iterator; import com.cg.bean.BookSchema; public class BookCollectionHelper { private static ArrayList<BookSchema> bookList=null; static { bookList=new ArrayList<BookSchema>(); BookSchema b1=new BookSchema(111,"See into the Sea of C",350); BookSchema b2=new BookSchema(222,"Learning Java in 21 Days",450.50); BookSchema b3=new BookSchema(333,"ASP.Net with C#", 250.75); bookList.add(b1); bookList.add(b2); bookList.add(b3); } public BookCollectionHelper(){} /*************Add New Book in ArrayList************/ public void addNewBookDetails(BookSchema book) { bookList.add(book); }
  • 2. public static ArrayList<BookSchema> getbookList() { return bookList; } public static void setbookList(ArrayList<BookSchema> bookList) { BookCollectionHelper.bookList = bookList; } /*************Fetch All Book Details ***********/ public static void displayBookCount() { Iterator<BookSchema> bookIt=bookList.iterator(); BookSchema tempBook=null; int totalCount=0; while(bookIt.hasNext()) { totalCount++; tempBook=bookIt.next(); System.out.println(tempBook); } System.out.println("Total Count of Books" + totalCount); } }
  • 3. /************************************************************************************ / BookCollectionHelperTest.java package com.cg.junit; import junit.framework.Assert; import org.junit.Test; import org.junit.AfterClass; import org.junit.BeforeClass; import com.cg.bean.BookSchema; import com.cg.exception.BookException; import com.cg.helper.BookCollectionHelper; public class BookCollectionHelperTest { static BookCollectionHelper collectionHelper; static BookSchema book=null; @BeforeClass public static void beforeClass()
  • 4. { collectionHelper=new BookCollectionHelper(); book =new BookSchema(888,"Neelima", 670.75); } @AfterClass public static void afterClass() { collectionHelper=null; book=null; } @Test public void testAddNewBook() throws BookException { collectionHelper.addNewBookDetails(book); //Assert.assertEquals(4, collectionHelper.getCustList().size()); Assert.assertNotNull(collectionHelper.toString()); } } /************************************************************************************ **********/
  • 5. BookDataValidator.java package com.cg.helper; import java.util.regex.Pattern; import com.cg.exception.BookException; public class BookDataValidator { public static boolean validateBookName(String bookName)throws BookException { String custPattern="[A-Za-z]{6,20}"; if(Pattern.matches(custPattern, bookName)) { return true; } else { throw new BookException("Book Name should start with CAPITAL & Min 6 and Max 20 characters Allowed"); } } public static boolean validateBookId(String bookId)throws BookException { String IdPattern="d{3}"; if(Pattern.matches(IdPattern, bookId)) { return true; }
  • 6. else { throw new BookException("Only 3-digit BookID is Allowed"); } } public static boolean validateBookPrice(String bookPrice)throws BookException { String pricePattern="d{2,4}.?[0-9]{2}$"; if(Pattern.matches(pricePattern, bookPrice)) { return true; } else { throw new BookException("Only numbers (and paise if any) is Allowed"); } } } /************************************************************************************ *****************/ BookException.java
  • 7. package com.cg.exception; public class BookException extends Exception { private static final long serialVersionUID = 1L; public BookException() { super(); } public BookException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public BookException(String message, Throwable cause) { super(message, cause); } public BookException(String message) { super(message); } public BookException(Throwable cause) { super(cause); } }
  • 8. /************************************************************************************ ***************/ BookSchema.java package com.cg.bean; public class BookSchema { private int bookId; private String bookName; private double bookPrice; public BookSchema() { } public BookSchema(int bookId, String bookName, double bookPrice) { this.bookId = bookId; this.bookName = bookName; this.bookPrice = bookPrice; } public int getBookId() { return bookId; } public void setBookId(int bookId) { this.bookId = bookId; } public String getBookName() { return bookName;
  • 9. } public void setBookName(String bookName) { this.bookName = bookName; } public double getBookPrice() { return bookPrice; } public void setBookPrice(double bookPrice) { this.bookPrice = bookPrice; } @Override public String toString() { return "Book [bookId=" + bookId + ", bookName=" + bookName + ", bookPrice=" + bookPrice + "]"; } } /************************************************************************************ ***************/ BookUI.java
  • 10. package com.cg.ui; import java.util.Scanner; import com.cg.bean.BookSchema; import com.cg.exception.BookException; import com.cg.helper.BookCollectionHelper; import com.cg.helper.BookDataValidator; public class BookUI { static Scanner sc=new Scanner(System.in); static BookCollectionHelper collectionhelper=null; @SuppressWarnings("static-access") public static void main(String[] args) { // TODO Auto-generated method stub int choice=0; collectionhelper=new BookCollectionHelper(); while(true) { System.out.println("1:Add New Book n"+ "2:Find total count of books n3:Exit"); System.out.println("nEnter UR Choice: "); choice=sc.nextInt();
  • 11. switch(choice) { case 1: enterNewBookDetails();break; case 2: collectionhelper.displayBookCount();break; default:System.exit(0); } } } private static void enterNewBookDetails() { System.out.println("How many new Books ? "); int bcount=sc.nextInt(); while (bcount!=0) { System.out.println("Enter Book Id:"); String bookId=sc.next(); try { if(BookDataValidator.validateBookId(bookId)) System.out.println("Enter Book name:"); String bookName=sc.next(); if(BookDataValidator.validateBookName(bookName)) { System.out.println("Enter Price "); String bookPrice =sc.next(); if(BookDataValidator.validateBookPrice(bookPrice))
  • 12. { BookSchema book=new BookSchema(Integer.parseInt(bookId), bookName, Double.parseDouble(bookPrice)); collectionhelper.addNewBookDetails(book); } } } catch (BookException e) { System.out.println(e.getMessage()); } bcount--; } } } /************************************************************************************ **********************/ help file for Book.txt
  • 13. Note: 1. Include the jar files required for junit. 2. The executable file is : BookUI.java ------- Create files in the following sequence : 1. BookSchema 2. BookUI 3. BookDataValidator & BookCollectionHelper 4. BookException & bbokCollectionHelperTest