CODE IN JAVA:
Book.java file:
public class Book {
String title ;
int numOfPages ;
public Book(String title, int numOfPages) {
this.title = title;
this.numOfPages = numOfPages;
}
public String getTitle() {
return title;
}
public int getNumOfPages() {
return numOfPages;
}
public boolean isLong() {
return numOfPages > 300 ;
}
public char firstChar() {
return title.charAt(0);
}
@Override
public String toString() {
return "Book [title=" + title + ",
numOfPages=" + numOfPages + "]";
}
}
Library.java file:
import java.util.ArrayList;
public class Library {
ArrayList<Book> bookShelf ;
Library(){
bookShelf = new
ArrayList<Book>();
bookShelf.add(new Book("Amrutham
Kurisina ratri", 240));
bookShelf.add(new Book("Rich dad
poo dad", 400));
bookShelf.add(new Book("Half girl
friend", 320));
bookShelf.add(new Book("Fountain
head", 180));
bookShelf.add(new Book("Amaravathi
kathalu", 640));
}
String allBooks() {
StringBuffer str = new
StringBuffer("");
for(Book b : bookShelf) {
str.append(b);
str.append("\n");
}
return str.toString() ;
}
Book shortestBook() {
Book shortBook =
bookShelf.get(0);
for(Book b : bookShelf) {
if(b.getNumOfPages() < shortBook.getNumOfPages())
shortBook = b ;
}
return shortBook ;
}
void printBookSelection(int num, char character)
{
for(Book b : bookShelf) {
if(b.getNumOfPages() > num && b.getTitle().charAt(0) ==
character) {
System.out.println(b);
}
}
}
ArrayList<Book> longBooks(){
ArrayList<Book> resultList =
new ArrayList<Book>();
for(Book b : bookShelf) {
if(b.isLong())
resultList.add(b);
}
return resultList ;
}
}
Tester.java file:
import java.util.ArrayList;
import java.util.Scanner ;
public class Tester {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
Library library = new
Library();
System.out.println("Below are the
all books of library : ");
System.out.println(library.allBooks());
System.out.println("\nShortest book
: " + library.shortestBook());
int num;
char c ;
System.out.print("Enter the number
:");
num = sc.nextInt();
System.out.print("Enter the
character:");
c = sc.next().charAt(0);
System.out.println("Below are the
books having pages greater than number and title starting with your
character : ");
library.printBookSelection(num,
c);
ArrayList<Book> longBooks =
library.longBooks();
System.out.println("Below are the
long books: ");
for(Book b : longBooks)
System.out.println(b);
}
}
OUTPUT:
Programming language: Java Design an application that has three classes. The first one, named Book describes...
You need to program a simple book library system. There are three java classes Book.java // book object class Library.java //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...
C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
Design and implement a Java data structure class named BookShelf which has an array to store books and the size data member. The class should have suitable constructors, get/set methods, and the toString method, as well as methods for people to add a book, remove a book, and search for a book. Design and implement a Java class named Book with two data members: title and price. Test the two classes by creating a bookshelf object and five book objects....
Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...
cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...
Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....
Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...
Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...
JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...