Question: IN JAVA(NetBeans IDE 8.2) The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesnt have a
IN JAVA(NetBeans IDE 8.2)
The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesnt have a parameter. It assigns to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public.
1. Define the Book.java class. 2. define another class named BookApp.java which has a main() method. 3. create a Book object, named b1, by calling the first Book constructor. Then using the object b1 to call setTitle() and setPrice() methods to assign John Doe to title and 8.1 to price. using b1 to call toString() method and print the returned value from the toString() method. create another Book object, named b2, by calling the second Book constructor and passing Ann Smith as the first argument and 9.2 as the second argument. using b2 to call toString() method and print the returned value from the toString() method.
I need help on #3, I tried this code but did not work:
package book;
public class BookApp { public static void main(String[] args) { Book b1 = new Book(); b1.setTitle("John Doe"); b1.setPrice(8.1); System.out.println(b1.toString()); Book b2 = new Book("Ann Smith", 9.2); System.out.println(b2.toString()); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
