Write Full java program to that define Book class contents a) ISBN int. b) BookN
ID: 3817836 • Letter: W
Question
Write Full java program to that define Book class contents a) ISBN int. b) BookName String. c) Author String. d) Edition double. e) Default constructor to assign default values for variables. f) Constructor to receive and assign values to variables. g) Method named view() to print all variables. h) Method named getCharFromBookName(int), to return charter in specified index of book name. i) Method named getLastIndexFromAuthor(char), to get returns index of last occurrence of specified character. j) Main method to test all methods.Explanation / Answer
public class Book {
public int ISBN;
public String BookName;
public String Author;
public double Edition;
public Book() {};
public Book(int ISBN,String BookName,String Author,double Edition)
{
this.ISBN = ISBN;
this.BookName = BookName;
this.Author = Author;
this.Edition = Edition;
}
public void view() {
System.out.println(this.ISBN);
System.out.println(this.BookName);
System.out.println(this.Author);
System.out.println(this.Edition);
}
public char getCharFromBookName(int x)
{
return BookName.charAt(x);
}
public int getLastIndexFromAuthor(char ch)
{
return Author.lastIndexOf(ch);
}
public static void main(String args[]) {
Book ob = new Book(1,"Java Programing"," Balagurusamy",4);
ob.view();
System.out.println("Char at specified index is :" + ob.getCharFromBookName(3));
System.out.println("Last Index of specified char is :" +ob.getLastIndexFromAuthor('r'));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.