Create a Ruby class Book1. Each book is characterized by the instance variables
ID: 3842252 • Letter: C
Question
Create a Ruby class Book1. Each book is characterized by the instance variables author and title. For this class create the initializer and the method show1 that displays the instance variable of the class Book1. Create the class Book2 that inherits properties from the class Book1 and adds a new instance variables publisher and price. Write the following Book2 methods read2 that prompts the user and reads from the keyboard all data for Book2. show2 that displays all instance variables of the class Book2. Write a main program that reads from the keyboard an array of 3 books (objects of Book2), and then displays all of them using show2.Explanation / Answer
import java.util.Scanner;
import java.util.*;
class Book1
{ String author,title;
public void show1(string name)
{
System.out.println("book name is ",+name);
}
class Book2 extends Book1
{
String publisher;
String bookName;
float price;
String authorName;
public void read2()
{
Scanner s= new Scanner(System.in);
System.out.println("Enter book name");
bookName=s.next();
System.out.println("enter author name");
authorName=s.next();
System.out.println("enter book price");
price=s.nextFloat();
}
public void show2()
{
System.out.println("book name "+bookName+"Publisher "+publisher+"Price"+price+"Authorname"+authorName);
}
}
}
public class HelloWorld{
public static void main(String []args){
Book2 b2 = new Book2();
b2.read2();
b2.show2();
}
}