SlideShare a Scribd company logo
1 of 13
Download to read offline
Book.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg2;
/**
*
* @author MDR
*/
public class Book {
private static int booksCount,checkedIn;
private int classNumber;
private double bookNumber;
private String author;
private String title;
private boolean checked;
public Book()
{
this.classNumber=000;
this.bookNumber=000.000;
this.author="Doe, John";
this.checked=true;
this.title="Book Title";
booksCount++;
checkedIn++;
}
public Book(int cn,double bn,String au,String title,boolean checked)
{
this.classNumber=cn;
this.bookNumber=bn;
this.author=au;
this.title=title;
this.checked=checked;
booksCount++;
checkedIn++;
}
public void setClassNo(int cn)
{
this.classNumber=cn;
}
public void setBookNo(double bn)
{
this.bookNumber=bn;
}
public void setAuthor(String au)
{
this.author=au;
}
public void setTitle(String title)
{
this.title=title;
}
public void setChecked(boolean checked)
{
this.checked=checked;
if(checked==true)
checkedIn++;
else
checkedIn--;
}
public int getClassNo()
{
return this.classNumber;
}
public double getBookNo()
{
return this.bookNumber;
}
public String getAuthor()
{
return this.author;
}
public String getTitle()
{
return this.title;
}
public boolean getChecked( )
{
return this.checked;
}
public int getBooksCount()
{
return this.booksCount;
}
public int getCheckedCount()
{
return this.checkedIn;
}
}
MyLIbrary.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg2;
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class MyLibrary {
public static void main(String []args)
{
int op=1;
ArrayList books=new ArrayList(0);
Scanner scan=new Scanner(System.in);
Book book;
while(op==1)
{
book=createBook();
books.add(book);
System.out.println("do you want create a Book press 1 otherwise press any key");
op=scan.nextInt();
}
System.out.println("Books Count:"+books.get(0).getBooksCount());
System.out.println("Books Checked in Count:"+books.get(0).getCheckedCount());
for(int i=0;i=000.000 &&bookNumber<=999.999)
book=new Book(classNumber,bookNumber,author,title,checked);
else
book=new Book();
return book;
}
}
Output:
run:
please enter class number of book:
115
please enter book number:
115.225
please enter book author:
kiran
please enter book title:
ABC
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
225
please enter book number:
225.365
please enter book author:
taj
please enter book title:
DEF
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
556
please enter book number:
556.357
please enter book author:
SAGAR
please enter book title:
GHI
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
755
please enter book number:
755.896
please enter book author:
DURGA
please enter book title:
JKL
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
998
please enter book number:
998.658
please enter book author:
MAHESH
please enter book title:
MNO
do you want create a Book press 1 otherwise press any key
0
Books Count:5
Books Checked in Count:5
Book Class Number:115
Book BoookNumber :115.225
Book author:kiran
Book Title:ABC
Book is Checked:true
Book Description:
Philosophy and psychology
Book Class Number:225
Book BoookNumber :225.365
Book author:taj
Book Title:DEF
Book is Checked:true
Book Description:
Religion
Book Class Number:556
Book BoookNumber :556.357
Book author:SAGAR
Book Title:GHI
Book is Checked:true
Book Description:
Pure Science
Book Class Number:755
Book BoookNumber :755.896
Book author:DURGA
Book Title:JKL
Book is Checked:true
Book Description:
Arts & recreation
Book Class Number:998
Book BoookNumber :998.658
Book author:MAHESH
Book Title:MNO
Book is Checked:true
Book Description:
History & geography
After checked out one book
Books Count:5
Books Checked in Count:4
BUILD SUCCESSFUL (total time: 3 minutes 4 seconds)
Solution
Book.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg2;
/**
*
* @author MDR
*/
public class Book {
private static int booksCount,checkedIn;
private int classNumber;
private double bookNumber;
private String author;
private String title;
private boolean checked;
public Book()
{
this.classNumber=000;
this.bookNumber=000.000;
this.author="Doe, John";
this.checked=true;
this.title="Book Title";
booksCount++;
checkedIn++;
}
public Book(int cn,double bn,String au,String title,boolean checked)
{
this.classNumber=cn;
this.bookNumber=bn;
this.author=au;
this.title=title;
this.checked=checked;
booksCount++;
checkedIn++;
}
public void setClassNo(int cn)
{
this.classNumber=cn;
}
public void setBookNo(double bn)
{
this.bookNumber=bn;
}
public void setAuthor(String au)
{
this.author=au;
}
public void setTitle(String title)
{
this.title=title;
}
public void setChecked(boolean checked)
{
this.checked=checked;
if(checked==true)
checkedIn++;
else
checkedIn--;
}
public int getClassNo()
{
return this.classNumber;
}
public double getBookNo()
{
return this.bookNumber;
}
public String getAuthor()
{
return this.author;
}
public String getTitle()
{
return this.title;
}
public boolean getChecked( )
{
return this.checked;
}
public int getBooksCount()
{
return this.booksCount;
}
public int getCheckedCount()
{
return this.checkedIn;
}
}
MyLIbrary.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg2;
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class MyLibrary {
public static void main(String []args)
{
int op=1;
ArrayList books=new ArrayList(0);
Scanner scan=new Scanner(System.in);
Book book;
while(op==1)
{
book=createBook();
books.add(book);
System.out.println("do you want create a Book press 1 otherwise press any key");
op=scan.nextInt();
}
System.out.println("Books Count:"+books.get(0).getBooksCount());
System.out.println("Books Checked in Count:"+books.get(0).getCheckedCount());
for(int i=0;i=000.000 &&bookNumber<=999.999)
book=new Book(classNumber,bookNumber,author,title,checked);
else
book=new Book();
return book;
}
}
Output:
run:
please enter class number of book:
115
please enter book number:
115.225
please enter book author:
kiran
please enter book title:
ABC
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
225
please enter book number:
225.365
please enter book author:
taj
please enter book title:
DEF
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
556
please enter book number:
556.357
please enter book author:
SAGAR
please enter book title:
GHI
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
755
please enter book number:
755.896
please enter book author:
DURGA
please enter book title:
JKL
do you want create a Book press 1 otherwise press any key
1
please enter class number of book:
998
please enter book number:
998.658
please enter book author:
MAHESH
please enter book title:
MNO
do you want create a Book press 1 otherwise press any key
0
Books Count:5
Books Checked in Count:5
Book Class Number:115
Book BoookNumber :115.225
Book author:kiran
Book Title:ABC
Book is Checked:true
Book Description:
Philosophy and psychology
Book Class Number:225
Book BoookNumber :225.365
Book author:taj
Book Title:DEF
Book is Checked:true
Book Description:
Religion
Book Class Number:556
Book BoookNumber :556.357
Book author:SAGAR
Book Title:GHI
Book is Checked:true
Book Description:
Pure Science
Book Class Number:755
Book BoookNumber :755.896
Book author:DURGA
Book Title:JKL
Book is Checked:true
Book Description:
Arts & recreation
Book Class Number:998
Book BoookNumber :998.658
Book author:MAHESH
Book Title:MNO
Book is Checked:true
Book Description:
History & geography
After checked out one book
Books Count:5
Books Checked in Count:4
BUILD SUCCESSFUL (total time: 3 minutes 4 seconds)

More Related Content

More from aptcomputerzone

AnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
AnsTriploidy is a desirable trait in all angiosperms except orchi.pdfAnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
AnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
aptcomputerzone
 
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdfa) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
aptcomputerzone
 
A pivot table is a table which is used to store the summary of a cer.pdf
A pivot table is a table which is used to store the summary of a cer.pdfA pivot table is a table which is used to store the summary of a cer.pdf
A pivot table is a table which is used to store the summary of a cer.pdf
aptcomputerzone
 
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
aptcomputerzone
 
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
aptcomputerzone
 
1. what is the central dogma of geneticsans Central dogma of gen.pdf
1. what is the central dogma of geneticsans Central dogma of gen.pdf1. what is the central dogma of geneticsans Central dogma of gen.pdf
1. what is the central dogma of geneticsans Central dogma of gen.pdf
aptcomputerzone
 
A group of isotopes representing various stages of radioactive decay.pdf
  A group of isotopes representing various stages of radioactive decay.pdf  A group of isotopes representing various stages of radioactive decay.pdf
A group of isotopes representing various stages of radioactive decay.pdf
aptcomputerzone
 
n should be 5 here Calcium sulfate (or calcium su.pdf
                     n should be 5 here Calcium sulfate (or calcium su.pdf                     n should be 5 here Calcium sulfate (or calcium su.pdf
n should be 5 here Calcium sulfate (or calcium su.pdf
aptcomputerzone
 
How many ml of .20 M NaOh are required to neutral.pdf
                     How many ml of .20 M NaOh are required to neutral.pdf                     How many ml of .20 M NaOh are required to neutral.pdf
How many ml of .20 M NaOh are required to neutral.pdf
aptcomputerzone
 
Why does one would like all of this social control stuff the most g.pdf
Why does one would like all of this social control stuff the most g.pdfWhy does one would like all of this social control stuff the most g.pdf
Why does one would like all of this social control stuff the most g.pdf
aptcomputerzone
 
The race industry and its elite enablers take it as self-evident tha.pdf
The race industry and its elite enablers take it as self-evident tha.pdfThe race industry and its elite enablers take it as self-evident tha.pdf
The race industry and its elite enablers take it as self-evident tha.pdf
aptcomputerzone
 

More from aptcomputerzone (20)

Answer1.To print the size of my home directory $HOME we usee.pdf
Answer1.To print the size of my home directory $HOME we usee.pdfAnswer1.To print the size of my home directory $HOME we usee.pdf
Answer1.To print the size of my home directory $HOME we usee.pdf
 
AnswerAcidithiobacillusExplanationMany greenhouse gases occu.pdf
AnswerAcidithiobacillusExplanationMany greenhouse gases occu.pdfAnswerAcidithiobacillusExplanationMany greenhouse gases occu.pdf
AnswerAcidithiobacillusExplanationMany greenhouse gases occu.pdf
 
AnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
AnsTriploidy is a desirable trait in all angiosperms except orchi.pdfAnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
AnsTriploidy is a desirable trait in all angiosperms except orchi.pdf
 
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdfa) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
a) Rotenone is an isoflavone used as insecticide and pesticide. It w.pdf
 
A pivot table is a table which is used to store the summary of a cer.pdf
A pivot table is a table which is used to store the summary of a cer.pdfA pivot table is a table which is used to store the summary of a cer.pdf
A pivot table is a table which is used to store the summary of a cer.pdf
 
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
26. DNA molecule contains deoxyribose and is double stranded.27. B.pdf
 
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
(A) Current Ratio = Current AssetsCurrent LiabilitiesCurrent Asse.pdf
 
1. what is the central dogma of geneticsans Central dogma of gen.pdf
1. what is the central dogma of geneticsans Central dogma of gen.pdf1. what is the central dogma of geneticsans Central dogma of gen.pdf
1. what is the central dogma of geneticsans Central dogma of gen.pdf
 
Phosphorous reacts readily with hydrogen to form hydrides; with halo.pdf
  Phosphorous reacts readily with hydrogen to form hydrides; with halo.pdf  Phosphorous reacts readily with hydrogen to form hydrides; with halo.pdf
Phosphorous reacts readily with hydrogen to form hydrides; with halo.pdf
 
A group of isotopes representing various stages of radioactive decay.pdf
  A group of isotopes representing various stages of radioactive decay.pdf  A group of isotopes representing various stages of radioactive decay.pdf
A group of isotopes representing various stages of radioactive decay.pdf
 
n should be 5 here Calcium sulfate (or calcium su.pdf
                     n should be 5 here Calcium sulfate (or calcium su.pdf                     n should be 5 here Calcium sulfate (or calcium su.pdf
n should be 5 here Calcium sulfate (or calcium su.pdf
 
Molarity = moles Litres of solution. Work out .pdf
                     Molarity = moles  Litres of solution.  Work out .pdf                     Molarity = moles  Litres of solution.  Work out .pdf
Molarity = moles Litres of solution. Work out .pdf
 
How many ml of .20 M NaOh are required to neutral.pdf
                     How many ml of .20 M NaOh are required to neutral.pdf                     How many ml of .20 M NaOh are required to neutral.pdf
How many ml of .20 M NaOh are required to neutral.pdf
 
It looks like you have two molecules there. CH3C.pdf
                     It looks like you have two molecules there.  CH3C.pdf                     It looks like you have two molecules there.  CH3C.pdf
It looks like you have two molecules there. CH3C.pdf
 
In H3O+ ion there are four electronpairs on the v.pdf
                     In H3O+ ion there are four electronpairs on the v.pdf                     In H3O+ ion there are four electronpairs on the v.pdf
In H3O+ ion there are four electronpairs on the v.pdf
 
     According to periodic properties Theatomic radius is increases .pdf
     According to periodic properties Theatomic radius is increases .pdf     According to periodic properties Theatomic radius is increases .pdf
     According to periodic properties Theatomic radius is increases .pdf
 
Why does one would like all of this social control stuff the most g.pdf
Why does one would like all of this social control stuff the most g.pdfWhy does one would like all of this social control stuff the most g.pdf
Why does one would like all of this social control stuff the most g.pdf
 
We know that absorbance , A = log ( Io It ) Where Io = intensity.pdf
We know that absorbance , A = log ( Io  It ) Where Io = intensity.pdfWe know that absorbance , A = log ( Io  It ) Where Io = intensity.pdf
We know that absorbance , A = log ( Io It ) Where Io = intensity.pdf
 
(19)D. All of the choices are correct.Explanation enzymes. ; fl.pdf
(19)D. All of the choices are correct.Explanation enzymes. ; fl.pdf(19)D. All of the choices are correct.Explanation enzymes. ; fl.pdf
(19)D. All of the choices are correct.Explanation enzymes. ; fl.pdf
 
The race industry and its elite enablers take it as self-evident tha.pdf
The race industry and its elite enablers take it as self-evident tha.pdfThe race industry and its elite enablers take it as self-evident tha.pdf
The race industry and its elite enablers take it as self-evident tha.pdf
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

Book.java To change this license header, choose License Hea.pdf

  • 1. Book.java: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chegg2; /** * * @author MDR */ public class Book { private static int booksCount,checkedIn; private int classNumber; private double bookNumber; private String author; private String title; private boolean checked; public Book() { this.classNumber=000; this.bookNumber=000.000; this.author="Doe, John"; this.checked=true; this.title="Book Title"; booksCount++; checkedIn++; } public Book(int cn,double bn,String au,String title,boolean checked) { this.classNumber=cn; this.bookNumber=bn; this.author=au;
  • 2. this.title=title; this.checked=checked; booksCount++; checkedIn++; } public void setClassNo(int cn) { this.classNumber=cn; } public void setBookNo(double bn) { this.bookNumber=bn; } public void setAuthor(String au) { this.author=au; } public void setTitle(String title) { this.title=title; } public void setChecked(boolean checked) { this.checked=checked; if(checked==true) checkedIn++; else checkedIn--; } public int getClassNo() { return this.classNumber; } public double getBookNo()
  • 3. { return this.bookNumber; } public String getAuthor() { return this.author; } public String getTitle() { return this.title; } public boolean getChecked( ) { return this.checked; } public int getBooksCount() { return this.booksCount; } public int getCheckedCount() { return this.checkedIn; } } MyLIbrary.java: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chegg2; import java.io.*; import java.util.Scanner;
  • 4. import java.util.ArrayList; public class MyLibrary { public static void main(String []args) { int op=1; ArrayList books=new ArrayList(0); Scanner scan=new Scanner(System.in); Book book; while(op==1) { book=createBook(); books.add(book); System.out.println("do you want create a Book press 1 otherwise press any key"); op=scan.nextInt(); } System.out.println("Books Count:"+books.get(0).getBooksCount()); System.out.println("Books Checked in Count:"+books.get(0).getCheckedCount()); for(int i=0;i=000.000 &&bookNumber<=999.999) book=new Book(classNumber,bookNumber,author,title,checked); else book=new Book(); return book; } } Output: run: please enter class number of book: 115 please enter book number: 115.225 please enter book author: kiran
  • 5. please enter book title: ABC do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 225 please enter book number: 225.365 please enter book author: taj please enter book title: DEF do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 556 please enter book number: 556.357 please enter book author: SAGAR please enter book title: GHI do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 755 please enter book number: 755.896 please enter book author: DURGA please enter book title: JKL do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 998
  • 6. please enter book number: 998.658 please enter book author: MAHESH please enter book title: MNO do you want create a Book press 1 otherwise press any key 0 Books Count:5 Books Checked in Count:5 Book Class Number:115 Book BoookNumber :115.225 Book author:kiran Book Title:ABC Book is Checked:true Book Description: Philosophy and psychology Book Class Number:225 Book BoookNumber :225.365 Book author:taj Book Title:DEF Book is Checked:true Book Description: Religion Book Class Number:556 Book BoookNumber :556.357 Book author:SAGAR Book Title:GHI Book is Checked:true Book Description: Pure Science Book Class Number:755 Book BoookNumber :755.896 Book author:DURGA Book Title:JKL Book is Checked:true
  • 7. Book Description: Arts & recreation Book Class Number:998 Book BoookNumber :998.658 Book author:MAHESH Book Title:MNO Book is Checked:true Book Description: History & geography After checked out one book Books Count:5 Books Checked in Count:4 BUILD SUCCESSFUL (total time: 3 minutes 4 seconds) Solution Book.java: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chegg2; /** * * @author MDR */ public class Book { private static int booksCount,checkedIn; private int classNumber; private double bookNumber; private String author; private String title; private boolean checked; public Book()
  • 8. { this.classNumber=000; this.bookNumber=000.000; this.author="Doe, John"; this.checked=true; this.title="Book Title"; booksCount++; checkedIn++; } public Book(int cn,double bn,String au,String title,boolean checked) { this.classNumber=cn; this.bookNumber=bn; this.author=au; this.title=title; this.checked=checked; booksCount++; checkedIn++; } public void setClassNo(int cn) { this.classNumber=cn; } public void setBookNo(double bn) { this.bookNumber=bn; } public void setAuthor(String au) { this.author=au; } public void setTitle(String title) { this.title=title;
  • 9. } public void setChecked(boolean checked) { this.checked=checked; if(checked==true) checkedIn++; else checkedIn--; } public int getClassNo() { return this.classNumber; } public double getBookNo() { return this.bookNumber; } public String getAuthor() { return this.author; } public String getTitle() { return this.title; } public boolean getChecked( ) { return this.checked; } public int getBooksCount() { return this.booksCount; } public int getCheckedCount()
  • 10. { return this.checkedIn; } } MyLIbrary.java: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chegg2; import java.io.*; import java.util.Scanner; import java.util.ArrayList; public class MyLibrary { public static void main(String []args) { int op=1; ArrayList books=new ArrayList(0); Scanner scan=new Scanner(System.in); Book book; while(op==1) { book=createBook(); books.add(book); System.out.println("do you want create a Book press 1 otherwise press any key"); op=scan.nextInt(); } System.out.println("Books Count:"+books.get(0).getBooksCount()); System.out.println("Books Checked in Count:"+books.get(0).getCheckedCount()); for(int i=0;i=000.000 &&bookNumber<=999.999) book=new Book(classNumber,bookNumber,author,title,checked); else
  • 11. book=new Book(); return book; } } Output: run: please enter class number of book: 115 please enter book number: 115.225 please enter book author: kiran please enter book title: ABC do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 225 please enter book number: 225.365 please enter book author: taj please enter book title: DEF do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 556 please enter book number: 556.357 please enter book author: SAGAR please enter book title:
  • 12. GHI do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 755 please enter book number: 755.896 please enter book author: DURGA please enter book title: JKL do you want create a Book press 1 otherwise press any key 1 please enter class number of book: 998 please enter book number: 998.658 please enter book author: MAHESH please enter book title: MNO do you want create a Book press 1 otherwise press any key 0 Books Count:5 Books Checked in Count:5 Book Class Number:115 Book BoookNumber :115.225 Book author:kiran Book Title:ABC Book is Checked:true Book Description: Philosophy and psychology Book Class Number:225 Book BoookNumber :225.365 Book author:taj Book Title:DEF
  • 13. Book is Checked:true Book Description: Religion Book Class Number:556 Book BoookNumber :556.357 Book author:SAGAR Book Title:GHI Book is Checked:true Book Description: Pure Science Book Class Number:755 Book BoookNumber :755.896 Book author:DURGA Book Title:JKL Book is Checked:true Book Description: Arts & recreation Book Class Number:998 Book BoookNumber :998.658 Book author:MAHESH Book Title:MNO Book is Checked:true Book Description: History & geography After checked out one book Books Count:5 Books Checked in Count:4 BUILD SUCCESSFUL (total time: 3 minutes 4 seconds)