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