Answer to Question #280836 in Java | JSP | JSF for ksjsps

Question #280836

Create a class called Book that contains instance variables like

BKName, BKId and BKAuthor, a parameterized constructor to

initialize its instance variables, a method BKUpdateDetails(String

name, int id, String author), that accepts new values for name, Id and

author as parameters and updates the corresponding instance variable

values of that object and another method BKDisplay() to display the

book details. Create a class BookDemo and provide main method for

instantiate a Book object, display the original book details, update its

details with new values, and display the updated book details.


1
Expert's answer
2021-12-17T14:01:21-0500


class Book {
	private String BKName;
	private int BKId;
	private String BKAuthor;


	/**
	 * Constructor
	 * 
	 * @param BKName
	 * @param BKId
	 * @param BKAuthor
	 */
	public Book(String BKName, int BKId, String BKAuthor) {
		this.BKName = BKName;
		this.BKId = BKId;
		this.BKAuthor = BKAuthor;
	}


	public void BKUpdateDetails(String name, int id, String author) {
		this.BKName = name;
		this.BKId = id;
		this.BKAuthor = author;
	}


	public void BKDisplay() {
		System.out.println("BKName: " + this.BKName);
		System.out.println("BKId: " + this.BKId);
		System.out.println("BKAuthor: " + this.BKAuthor);
	}
}


public class BookDemo {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		// main method for instantiate a Book object, display the original book details,
		// update its
		Book newBook = new Book("C++", 45456, "Peter Smith");
		// details with new values, and display the updated book details.
		newBook.BKDisplay();
		newBook.BKUpdateDetails("Java", 2326, "Mary Clark");
		newBook.BKDisplay();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog