Given the following class, Book, Write code for the following:
1. [2 pts) a constructor with one parameter for price
2. [2 pts] a copy constructor
3. [2 pts] a getter for price
4. [2 pts) a setter for author
5. [2 pts) a toString() method that returns a string with the author and price.
public class Book{
private int price;
private String author;
// your code here
}

Given the following class Book Write code for the following 1 2 pts a constructor with one parameter for price 2 2 pts a copy constructor 3 2 pts a getter for p class=

Respuesta :

Using the knowledge in computational language in JAVA it is possible to write a code that can organize the books in price and author classes.

Writing the code in JAVA we have:

class Book{

   private int price;

   private String author;

   public Book(int p){

       price=p;

   }

   public Book(Book b){

       price=b.price;

       author=b.author;

   }

   public int getPrice(){

       return price;

   }

   public void setAuthor(String a){

       author=a;

   }

   public String toString(){

       return author+" "+Integer.toString(price);

   }

}

public class Main

{

public static void main(String[] args) {

    Book b=new Book(450);

    b.setAuthor("Jack");

    Book b1=new Book(b);

    System.out.println(b1.toString());

}

}

See more about JAVA at brainly.com/question/18502436

#SPJ1

Ver imagen lhmarianateixeira