a class called book that encapsulates a book i already have
a class called book that encapsulates a book, i already have most of the code
The book class must not allow a negative pageNumber or cost, test these values with an if statement. If a negative number occurs print an error message telling where the negative number occured and use System.exit(0); to end the program
package classes;
import java.util.Scanner;
public class Book {
    private String title;
    private String category;
    private double cost;
    private int pageNumber;
    public void readBookData(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println(\"What is the title?\");
        title = keyboard.nextLine();
        System.out.println(\"What is the category?\");
        category = keyboard.nextLine();
        System.out.println(\"What is the cost?\");
        cost = keyboard.nextDouble();
        System.out.println(\"What is the page number?\");
        pageNumber = keyboard.nextInt();
    }
   public String getTitle(){
        return title;
    }
    public double getCost(){
        return cost;
    }
    public String getCategory(){
        return category;
    }
    public int pageNumber(){
        return pageNumber;
    }
    public void setTitle(String title){
        this.title = title;
    }
    public void setCategory(String category){
        this.category = category;
    }
    public void setCost(double cost){
        this.cost = cost;
    }
    public void setPageNumber(int pageNumber){
        this.pageNumber = pageNumber;
    }
    public void setBook(Book n){
       this.title = n.title;
        this.category = n.category;
        this.pageNumber = n.pageNumber;
        this.cost = n.cost;
    }
    public void setBook(String title, String category, int pageNumber, double cost){
        this.title = title;
        this.category = category;
        this.pageNumber = pageNumber;
        this.cost = cost;
    }
    public Book add(Book x){
        Book answer = new Book();
        answer.title = x.title;
        answer.category = x.category;
        answer.cost = x.cost;
        answer.pageNumber = x.pageNumber;
        return answer;
    }
    public String toString(){
       
        return \"\ Title\" + title + \"\ \" + \"Category\" + category + \"\ \" + \"Cost\" + cost + \"\ Page numbers\" + pageNumber;
    }
   
   
    public boolean equals(Book n){
        return this.
                //compares w new title
    }
 }
also i don\'t know how to implement my code into this:
public class BookDemo
 {//*** There has to be a program that uses the Book class.
    public static void main(String[] args)
    {
        //*** Four instances of Books are created.
        //*** new is used to give the Book instances memory.
        Book schoolBook = new Book( );
        Book bedReadingBook = new Book( );
        Book cookBook = new Book( );
        Book newBook = new Book();
        newBook.setBook(\"Computers\",\"IT\", 10, 200);
        System.out.println(\"newBook is. \"+ newBook);
        System.out.println(\"Enter school book information.\");
        //*** The method readBookData() is called.
        //*** An instance of Book is needed to connect this Demo
        //*** program with the Book class.
        schoolBook.readBookData( );
        System.out.println(\"Enter bed reading book information.\");
        bedReadingBook.readBookData( );
        System.out.println(\"Enter cookbook information.\");
        cookBook.readBookData( );
        //*** schoolBook calls its getBookCost() method. A double is
        //*** returned and converted to a String and printed.
        System.out.println(\"The cost of your school book is $\"
                + schoolBook.getBookCost());
        //*** The Book toString() method is invoked automatically in a
        //*** System.out.println() method.
        //*** Could invoke it with bedReadingBook.toStirng().
        System.out.println(\"Your bed reading book is \" + bedReadingBook);
        //*** schoolBook invokes its equals()method.
        //*** bedReadingBook is brought in and the instance variables are
        //*** compared. If they are equal the method returns true
        if(schoolBook.equals(bedReadingBook))
        {
            System.out.println(\"The school and bed reading books are the
                    same!\");
        }
        else
        {
            System.out.println(\"Your school book is not the same as your bed
                    reading book!\" );
        }
        //*** The add() method is called. A new instance of Book is created.
        //*** The add operations dictated by the method
        //*** body are performed on bedReadingBook and cookBook.
        //*** The new instance of Book is returned and assigned to newBook.
        newBook = bedReadingBook.add(cookBook);
        System.out.println(\"Creating a new book from the bed reading \"
                + \"book added to the cookbook is\  \" + newBook);
    }
 }
Solution
import java.util.Scanner;
public class Book {
    private String title;
    private String category;
    private double cost;
    private int pageNumber;
   public void readBookData() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(\"What is the title?\");
        title = keyboard.nextLine();
        System.out.println(\"What is the category?\");
        category = keyboard.nextLine();
        System.out.println(\"What is the cost?\");
        cost = keyboard.nextDouble();
        if (cost < 0) {
            System.out.println(\"Invalid cost\");
            System.exit(0);
        }
        System.out.println(\"What is the page number?\");
        pageNumber = keyboard.nextInt();
        if (pageNumber < 0) {
            System.out.println(\"Invalid page Number\");
            System.exit(0);
        }
    }
   public String getTitle() {
        return title;
    }
   public double getCost() {
        return cost;
    }
   public String getCategory() {
        return category;
    }
   public int pageNumber() {
        return pageNumber;
    }
   public void setTitle(String title) {
        this.title = title;
    }
   public void setCategory(String category) {
        this.category = category;
    }
   public void setCost(double cost) {
        this.cost = cost;
    }
   public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }
   public void setBook(Book n) {
        this.title = n.title;
        this.category = n.category;
        this.pageNumber = n.pageNumber;
        this.cost = n.cost;
    }
   public void setBook(String title, String category, int pageNumber,
            double cost) {
        this.title = title;
        this.category = category;
        this.pageNumber = pageNumber;
        this.cost = cost;
    }
   public Book add(Book x) {
        Book answer = new Book();
        answer.title = x.title;
        answer.category = x.category;
        answer.cost = x.cost;
        answer.pageNumber = x.pageNumber;
        return answer;
    }
public String toString() {
       return \"\ Title\" + title + \"\ \" + \"Category\" + category + \"\ \" + \"Cost\"
                + cost + \"\ Page numbers\" + pageNumber;
    }
   public boolean equals(Book n) {
        return true;
        // compares w new title
    }
 }
public class BookDemo {// *** There has to be a program that uses the Book
                        // class.
    public static void main(String[] args) {
        // *** Four instances of Books are created.
        // *** new is used to give the Book instances memory.
        Book schoolBook = new Book();
        Book bedReadingBook = new Book();
        Book cookBook = new Book();
        Book newBook = new Book();
        newBook.setBook(\"Computers\", \"IT\", 10, 200);
        System.out.println(\"newBook is. \" + newBook);
        System.out.println(\"Enter school book information.\");
        // *** The method readBookData() is called.
        // *** An instance of Book is needed to connect this Demo
        // *** program with the Book class.
        schoolBook.readBookData();
        System.out.println(\"Enter bed reading book information.\");
        bedReadingBook.readBookData();
        System.out.println(\"Enter cookbook information.\");
        cookBook.readBookData();
        // *** schoolBook calls its getBookCost() method. A double is
        // *** returned and converted to a String and printed.
        System.out.println(\"The cost of your school book is $\"
                + schoolBook.getCost());
        // *** The Book toString() method is invoked automatically in a
        // *** System.out.println() method.
        // *** Could invoke it with bedReadingBook.toStirng().
        System.out.println(\"Your bed reading book is \" + bedReadingBook);
        // *** schoolBook invokes its equals()method.
        // *** bedReadingBook is brought in and the instance variables are
        // *** compared. If they are equal the method returns true
        if (schoolBook.equals(bedReadingBook)) {
            System.out
                    .println(\"The school and bed reading books are the same!\");
        } else {
            System.out
                    .println(\"Your school book is not the same as your bed reading book!\");
        }
        // *** The add() method is called. A new instance of Book is created.
        // *** The add operations dictated by the method
        // *** body are performed on bedReadingBook and cookBook.
        // *** The new instance of Book is returned and assigned to newBook.
        newBook = bedReadingBook.add(cookBook);
        System.out.println(\"Creating a new book from the bed reading \"
                + \"book added to the cookbook is\  \" + newBook);
    }
 }
OUTPUT 1:
newBook is.
 TitleComputers
 CategoryIT
 Cost200.0
 Page numbers10
 Enter school book information.
 What is the title?
 book1
 What is the category?
 It
 What is the cost?
 -21
 Invalid cost
OUTPUT 2:
newBook is.
 TitleComputers
 CategoryIT
 Cost200.0
 Page numbers10
 Enter school book information.
 What is the title?
 bOOK2
 What is the category?
 IT
 What is the cost?
 322
 What is the page number?
 -21
 Invalid page Number
OUTPUT 3:
newBook is.
 TitleComputers
 CategoryIT
 Cost200.0
 Page numbers10
 Enter school book information.
 What is the title?
 Book3
 What is the category?
 IT
 What is the cost?
 2111
 What is the page number?
 32
 Enter bed reading book information.
 What is the title?
 Book4
 What is the category?
 IT
 What is the cost?
 21
 What is the page number?
 32
 Enter cookbook information.
 What is the title?
 Book5
 What is the category?
 IT
 What is the cost?
 211
 What is the page number?
 43
 The cost of your school book is $2111.0
 Your bed reading book is
 TitleBook4
 CategoryIT
 Cost21.0
 Page numbers32
 The school and bed reading books are the same!
 Creating a new book from the bed reading book added to the cookbook is
 
 TitleBook5
 CategoryIT
 Cost211.0
 Page numbers43






