Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. a. Design a class named Book that holds a stock number, author, title, price,

ID: 3633965 • Letter: 1

Question

1. a. Design a class named Book that holds a stock number, author, title, price, and number of pages for a book. Include methods to get and set the values for each data field. Create the class diagram and write the pseudocode that defines the class.

The class should have a method called displayBookDetails() that displays the values of the book attributes.

b. Design an application (main program)that declares two Book objects and sets and displays their values.

2. a. Design a class named TextBook that is a child class of Book you designed in part 1 above. Include a new data field for the grade level of the book and get and set methods for the new field.

b. Design an application that instantiates an object of each class (book and textbook) and demonstrates all the methods.

Explanation / Answer

public class Book {
private int stockNumber;
private String author;
private String title;
private double price;
private int pages;

public Book( int s,String a,String t,double p, int g)
{
stockNumber=s;
author=a;
title=t;
price=p;
pages=g;
}
public Book( )
{
}

public String getAuthor( ) {
return author;
}
public String getTitle( ) {
return title;
}
public int getStockNumber( ) {
return stockNumber;
}
public double getPrice( ) {
return price;
}
public int getPages( ) {
return pages;
}

public void setAuthor(String a)
{author=a;
}
public void setTitle(String a)
{title=a;
}
public void setStockNumber(int a)
{stockNumber=a;
}
public void setPages(int a)
{pages=a;
}
public void setPrice(double a)
{price=a;
}
}

-------------------------------------

import java.util.*;
public class BookShelf
{
public static void main(String[] args)
{Scanner input = new Scanner(System.in);
Book b1=new Book();
Book b2=new Book();
getdata(b1,input);
getdata(b2,input);
System.out.println("stock number author title price pages");

printdata(b1);
printdata(b2);


}
public static void getdata(Book b,Scanner input)
{String title,author;
double price;
int pages,stockNumber;

System.out.print("Enter stock Number: ");
stockNumber=input.nextInt();
input.nextLine();
b.setStockNumber(stockNumber);
System.out.print("Enter title: ");
title=input.nextLine();
b.setTitle(title);
System.out.print("Enter author: ");
author=input.nextLine();
b.setAuthor(author);
System.out.print("Enter price: ");
price=input.nextDouble();
b.setPrice(price);
System.out.print("Enter number of pages: ");
pages=input.nextInt();
b.setPages(pages);
}
public static void printdata(Book b)
{String title,author;
double price;
int pages,stockNumber;

title=b.getTitle();
stockNumber=b.getStockNumber();
author=b.getAuthor();
price=b.getPrice();
pages=b.getPages();
System.out.println(stockNumber+" "+author+" "+title+" $"+price+" "+pages);
}
}

Please post the next question as a separate post