Create an abstract class named Book Include a String field f

Create an abstract class named Book. Include a String field for the book’s title and a double field for the book’s price. Within the class, include a constructor that requires the book title, and add two get methods—one that returns the title and one that returns the price. Include an abstract method named setPrice(). Create two child classes of Book: Fiction and NonFiction. Each must include a setPrice() method that sets the price for all Fiction Books to $24.99 and for all NonFiction Books to $37.99. Write a constructor for each subclass, and include a call to setPrice() within each. Write an application demonstrating that you can create both a Fiction and a NonFiction Book and display their fields. Save the files as Book.java, Fiction.java, NonFiction.java, and UseBook.java. Also, write an application named BookArray in which you create an array that holds 10 Books, some Fiction and some NonFiction. Using a for loop, display details about all 10 books. Save the file as BookArray.java. Program 1 Submission Template Fields: Strategy for coding the program (Provide informal explanation as to how you approached the problem. What were your given information (input) and expected output? What Java libraries did you need to use): ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________

Sample output (Provide screenshots of it running):

Source code (Provide all Java code you have written.):

Solution

public abstract class Book

{

private String bookTitle;

  private double bookPrice;

  public Book(String title)

  {

    bookTitle = title;

  }

  public String getBookTitle(

  {

    return bookTitle;

  }

  public double getBookPrice()

  {

    return bookPrice;

  }

  public abstract void setBookPrice();

}

// Child class//

public class Fiction extends Book

{

  double fictionPrice;

  public Fiction(String title)

  {

    super(title);

    setBookPrice();

  }

  public void setBookPrice()

  {

    fictionPrice = 24.99;

  }   

}

// Second child class//

public class NonFiction extends Book

{

  double nonFictionPrice;

  public NonFiction(String title)

  {

    super(title);

    setBookPrice();

  }

  public void setBookPrice()

  {

    nonFictionPrice = 37.99;

  }

}

// Books and displaying their fields//

public class UseBook

{

  public static void main(String[] args)

  {

    Fiction fbook = new Fiction(\"Oliver Twist\");

    NonFiction nbook = new NonFiction(\"Making of the West\");

    System.out.println(fbook.getBookTitle() + \" \" + fbook.getBookPrice());

    System.out.println(nbook.getBookTitle() + \" \" + nbook.getBookPrice());

  }

}

public abstract class Book

Create an abstract class named Book. Include a String field for the book’s title and a double field for the book’s price. Within the class, include a constructo
Create an abstract class named Book. Include a String field for the book’s title and a double field for the book’s price. Within the class, include a constructo
Create an abstract class named Book. Include a String field for the book’s title and a double field for the book’s price. Within the class, include a constructo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site