Question

Create a Book object using a Java program. This object should contain the following variables bookName,...

Create a Book object using a Java program. This object should contain the following variables bookName, bookAuthorName, bookGenre.

Now create 3 different book objects and store them in an array.

Finally iterate through this array and print out the book names.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Book{
   String bookName;
   String bookAuthorName;
   String bookGenre;
  
  
   Book(String book,String author,String genre){//Contructor
       bookName=book;      
       bookAuthorName=author;
       bookGenre=genre;
       }
      
      
   public static void main( String[] agrs){
       Book arr[]=new Book[3];
       arr[0]=new Book("to kill a mockingbird book","Harper Lee","Ficton");
       arr[1]=new Book("1984","George Orwell","political fiction");
       arr[2]=new Book("The Lord of the Rings","J.R.R Tolkein","Fantasy");
       for(int i=0;i<3;i++){
           System.out.println(arr[i].bookName);
       }
   }
  
}
​​​​​​

Add a comment
Know the answer?
Add Answer to:
Create a Book object using a Java program. This object should contain the following variables bookName,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredi...

    Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredients (an array of up to 10 ingredients, such as ham, capicola, American cheese, lettuce, tomato) -condiments (an array of up to 5 condiments, such as mayonnaise, oil, vinegar and mustard) Create a two argument constructor Write the getters and setters for the instance variables Override the toString method using the...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Please help me do these two programs in JAVA Program 1 Create a program that will...

    Please help me do these two programs in JAVA Program 1 Create a program that will create an ArrayList of Strings. Then input names until “quit” and use the enhanced for loop to print out the names. Program 2 Using enum and array of objects Use the enumerated type of: enum CarType { PORCHE, FERRARI, JAGUAR, UNKNOWN } And place it in its own file. Then make a Car class that has the following:             Make of CarType             Year,...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

  • JAVA program For this project you are to create an array of objects of your choice...

    JAVA program For this project you are to create an array of objects of your choice using java your Driver Class, Object Classes should all be named appropriately depending on what Classes and Objects you decide to create for this assignment. This project must give the user the ability to view and to change the elements of the array. Print your results (output) as a clear and informative statement. Your output should also include an explanation of what your program...

  • IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table...

    IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table class to hold employees and their ID numbers. You'll create an employee class to hold each person's key (id number) and value (name). Flow of the main program: Create an instance of your hash table class in your main method. Read in the Employees.txt file and store the names and ID numbers into Employee objects and store those in your hash table using the...

  • Design a personType class with the following attributes (variables), and behaviors (methods/functions). Private Variables string fName;...

    Design a personType class with the following attributes (variables), and behaviors (methods/functions). Private Variables string fName; string lName; string address: double height (inches) string DOB char: gender Public functions setters for all of your data members (variables) getters for all of your data members print. This function will print "All of the persons' information". equals which takes another personType object as a parameter and compares all its members. Returns true is identical. Create a driver program that creates 5 different...

  • In Java please create two classes. Racecar - Should contain: variables - color (string), id (string),...

    In Java please create two classes. Racecar - Should contain: variables - color (string), id (string), topSpeed (int), and efficiency (double between 0-1) getters & setters for each, but getSpeed should return topSpeed* efficiency Main - should instantiate 3 car objects (values up to you) and compare the top speeds. the 'winner' should be printed out as the following: "The [color] car, [id], is the winner!"

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT