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

Write Full java program to that define Book class contents: ISBN int. BookName S

ID: 3815014 • Letter: W

Question

Write Full java program to that define Book class contents: ISBN int. BookName String. Author String. Edition double. Default constructor to assign default values for variables. Constructor to receive and assign values to variables. Method named view() to print all variables. Method named getCharFroinBookName(int), to return charter in specified index of book name. Method named getLastIndexFromAuthor(char), to get returns index of last occurrence of specified character. Main method to test all methods.

Explanation / Answer

Book.java

import java.util.Scanner;

public class Book {
   //Declaring variables
private int ISBN;
private String bookName;
private String author;
private double edition;

//Zero argumented constructor
public Book() {
   super();
   ISBN = 0;
   this.bookName = "NULL";
   this.author = "NULL";
   this.edition = 0.0;
}

//parameterized constructor
public Book(int iSBN, String bookName, String author, double edition) {
   super();
   ISBN = iSBN;
   this.bookName = bookName;
   this.author = author;
   this.edition = edition;
}

//Displaying the Book Info
public void view()
{
   System.out.println("ISBN :"+ISBN);
   System.out.println("Book Name :"+bookName);
   System.out.println("Author :"+author);
   System.out.println("Edition :"+edition);
}


//This method will return the char at index
public char getCharFromBookname(int index)
{
   return bookName.charAt(index);
}

//This method will return the index when last occurrence of that character
public int getLastIndexFromAuthor(char ch)
{
   for(int i=author.length()-1;i>=0;i--)
   {
       if(author.charAt(i)==ch)
       {
           return i;
       }
   }
   return 0;
}

public static void main(String args[])
{
   int isbn;
   String bookName;
   String author;
   double edition;
   //Scanner object is used to get the inputs entered by the user
   Scanner sc=new Scanner(System.in);
  
   System.out.print("Enter the ISBN :");
   isbn=sc.nextInt();
   sc.nextLine();
   System.out.print("Enter the BookName :");
   bookName=sc.nextLine();
   System.out.print("Enter the Author Name :");
   author=sc.nextLine();
   System.out.print("Enter the Edition :");
   edition=sc.nextDouble();
  
   Book b=new Book(isbn, bookName, author, edition);
   b.view();
   int len=bookName.length()-1;
   System.out.print("Enter the index Number between 0 and "+len+":");
   int index=sc.nextInt();
   char ch1=b.getCharFromBookname(index);
   System.out.println("The Character at Index "+index+" is '"+ch1+"'");
   System.out.print("Enter a Character :");
   char ch=sc.next(".").charAt(0);
   int num1=b.getLastIndexFromAuthor(ch);
   System.out.println("The Last Index is :"+num1);
  
   }
}

__________________

Output:

Enter the ISBN :1234
Enter the BookName :IntroDuction to Java Programming
Enter the Author Name :Malik
Enter the Edition :7.1
ISBN :1234
Book Name :IntroDuction to Java Programming
Author :Malik
Edition :7.1
Enter the index Number between 0 and 31:23
The Character at Index 23 is 'o'
Enter a Character :l
The Last Index is :2

____________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote