1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rasek [7]
3 years ago
9

Write a class named Book that has fields to hold the following data: Title Author Year published ISBN number In the Book class,

also include A mutator method for each field to set the value for the field An accessor method for each field to get the value for the field Write a separate demo program that Utilizies the class by creating three instances of the class.
Computers and Technology
1 answer:
Hatshy [7]3 years ago
3 0

Answer:

public class Book {

   private String title;

   private String author;

   private int yearPublished;

   private long ISBN;

   //The Constructor for all the feilds

   public Book(String title, String author, int yearPublished, long ISBN) {

       this.title = title;

       this.author = author;

       this.yearPublished = yearPublished;

       this.ISBN = ISBN;

   }

   //Mutator methods (set) to Set values of all the fields

   public void setTitle(String title) {

       this.title = title;

   }

   public void setAuthor(String author) {

       this.author = author;

   }

   public void setYearPublished(int yearPublished) {

       this.yearPublished = yearPublished;

   }

   public void setISBN(long ISBN) {

       this.ISBN = ISBN;

   }

   //Accessor Methods (getters) for all the feilds

   public String getTitle() {

       return title;

   }

   public String getAuthor() {

       return author;

   }

   public int getYearPublished() {

       return yearPublished;

   }

   public long getISBN() {

       return ISBN;

   }

}

// The Demo Class creating three instances of this class

class BookDemo{

   public static void main(String[] args) {

       Book bookOne = new Book("The Lion and the Princess","David A.",2000,12334556);

       Book bookTwo = new Book ("Me and You", "Jane G.", 2001, 4567342);

       Book bookThree = new Book("together forever", "Baneely H.",2019,34666);

   }

}

Explanation:

  • Please pay attention to the comments provided in the solution
  • Using Java Programming Language
  • The class Book is created with the required fields
  • The constructor is created to initialize the values of the fields
  • Getter methods are created
  • Setter Methods are Created
  • A demo Class BookDemo that creates three objects of the Book class is the created (This can be in the same file as the Book class but cannot start with the keyword public or in a separate file with the keyword public class BookDemo)
  • Inside BookDemo class, three instances of the Book class are created and initialized.
You might be interested in
Which is currently the most common cellular network?<br> 4G<br> 4G LTE<br> 5G<br> 5G LTE
Misha Larkins [42]

Answer:

4GLte

Explanation:

8 0
3 years ago
JAVVVAAAAAA HELPPPP EDHESIVE ​
Mekhanik [1.2K]

Answer:

Here's some really bad code that works:

public static double average(int a, int b, int c, int d, int e)

{

return (((double)a + b + c + d + e) / 5);

}

5 0
3 years ago
The most popular battery type used in today’s electronic devices is __________.
Lena [83]

Answer:

Lithium Ion batterys

Explanation:

4 0
3 years ago
Is it bad to leave external hard drive on for hours
alexandr402 [8]
Yes, because it can cause fires and electrical problems
8 0
3 years ago
Paul is a baker who wants to improve his recipe for muffins because they turn out with a greasy flavor. What ingredient should h
Sergio039 [100]
Butter to Margarine

Cakes baked with butter usually always turns out to be greasy and heavy.

Hope this helps, good luck! (:
3 0
3 years ago
Read 2 more answers
Other questions:
  • Difference between multiterm access and single term access for webassign
    11·1 answer
  • The columns of a spreadsheet data source are A. form letters. B. the mailing list. C. data points. D. fields.
    12·1 answer
  • Using Visio, create a Local Area Network (LAN) consisting of 12 computers, a switch, and three printers. The switch should be in
    11·1 answer
  • Difference between a software package and Integrated software and why users would choose one over the other
    8·1 answer
  • What type of software testing is generally used in Software Maintenance?
    11·1 answer
  • The small flash memory used in<br>protable device like Laptop<br><br>​
    10·1 answer
  • Write a program that (a) generates a vector with 20 random integer elements with integers between -29 and 30, (b) replaces all t
    13·1 answer
  • Which kind of image is indispensable and needs added text to go with ?
    12·1 answer
  • Which of the following is NOT a reason we use subprograms?
    7·1 answer
  • Consider sending a stream of packets from host a to host b using ipsec. typically, a new sa will be established for each packet
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!