Our first program will give you an opportunity to work with a simple class in Java. You
Question:
Specifications
In this project, I already made the simple program using OOP format that has two classes. One of the classes will be an object class. The object class will be used to define the attributes of a Book and it will contain all of the instance variables and methods needed to construct one instance of a Book. An instance of a Book could be such things as a novel or a textbook. The important thing is to think about what all of your books will have in common as well as what information you need to store about them. They should have at least 6 attributes, such as a name, genre and so on. All of the instance variables should be initialize in the constructor(s) and have both a getter & setter method. The user should be able to update all of the attributes (instance variables) using setter methods and at least two of the attributes should be numeric values. The numeric values should have at least one method each that contains a calculation. For example, the program could have an instance variable that keeps track of the pages read and there can be a method to add to or substract from the pages read.
The second required class is a Tester/Runner/Driver class that contains the main method. The specific functionality of the program is up to you, but the program must have at least 6 defined Book objects. The Book objects should be saved in an ArrayList and the getter/setter methods should use the ArrayList methods to access and update the attributes. The program must be interactive and ask the user for information that is used to display and update information about the books. The object class getter and setter methods should be used to display and manipulate the contents of the instance variables in the object class. There should be a menu that allows the user to interact with the program. At a minimum, the user should be able to display all the information about the book of the user's choice, update information about the book and use the calculation methods. Because this is your first program of the semester, please keep the scale of the program at a modest level. The purpose of this project is to give you a chance to code simple program in Java using objects. The program should loop until the user decides to exit from the program and selects the appropriate menu option. The ArrayList in the tester class should have 6 defined objects when the program launches with the option for the user to add more objects to the ArrayList.
While this is a relatively modest program, it is best practice to start by writing pseudocode. Plan out your program, what interactions you want the user to have with your Books and the types of output needed.
Program Requirements
This exercise is designed to be a short program that will give you a chance to refresh your Java skills as well as to give you a chance to practice with OOP design. The program must meet the following criteria:
- The program must be written entirely in JAVA.
- In the Object class:
- Instance variables must be properly declared and initialized.
- Constructor(s) must be properly declared.
- The must be at least 6 attributes for a Book and 2 of them must be numeric fields.
- There must be getter and setter methods for all instance variables.
- There are at least two methods used for calculations that update the numeric instance variables.
- In the Tester/Runner/Driver class:
- The variables must be properly declared and initialized.
- There should be at least 6 Book objects saved in an ArrayList when the program launches with the option for the user to add more.
- An object instance should be used to access all methods in the Object class (no static methods, variables or public variables in the object class).
- The program must use at least one loop. The type of loop(s) is up to you but the program must run until the user ends it.
- The user must be able to enter information that is used in the program.
- A menu allowing the user to make selections must be presented.
- The user must be able to display all of the information about a book of the user's selection and update the attributes of a book.
- You must properly comment and document your code(see the documentation about commenting code in the first modules of the course or ask me if you have any questions)
- You may name your program and files with any reasonable names of your choosing but I should be able to clearly identify the Tester class and the Object class. Names such as BookTester for the tester and Book for the object are good options.
Please note that while(true) loops are not acceptable. Using a while(true) loop will result in a 25 point penalty on any assignment.
Here's my name code I created need some creating the tester for it
import java.lang.Class;
class Book {
private String title;
private int price;
private String author;
private String genre;
private String publisher;
private int numPages;
// the projetc requires a specific number of instances varibles of attrbuuites // of a Book. Here is the instances varibles
public Book(String title, String author, int numPages, int price, String genre, String publisher) {
this.title = title;
this.price = price;
this.author = author;
this.genre = genre;
this.publisher = publisher;
this.numPages = numPages;
}
// this area is meant for this constructor and the variable instances thus is // required to be input to the get instance constructored outcome for the BOOk
// The default state is initialized with this method.
public Book() {
this.title = "Absalom";
this.author = "William";
this.genre = "Bible";
this.publisher = "Howard";
this.numPages = 150;
this.price = 250;
}
// Syntax... Setter and Getters of the variables instances thus As a programmer, // you can choose how variables are created and modified
public String getTitle() // accessor methods for the title
{
return title;
}
public String getAuthor() // accessor methods for the author
{
return author;
}
public String getGenre() // accessor methods for the genre
{
return genre;
}
public String getPublisher() // accessor methods for the publisher
{
return publisher;
}
public int getPrice() // accessor methods for the price
{
return price;
}
public int getNumPages() { // accessor methods for the numPages
return numPages;
}
// An object's value can be set or updated with the setter method. The syntax of // a setter should be used to retrieve
// and update the value of a variable outside of the enclosing class.
public void setTitle(String title) // mutator methods for the title
{
this.title = title;
}
public void setAuthor(String author) // mutator methods for the author
{
this.author = author;
}
public void setPublisher(String publisher) // mutator methods for the publisher
{
this.publisher = publisher;
}
public void setGenre(String genre) // mutator methods for the genre
{
this.genre = genre;
}
public void setPrice(int price) { // mutator methods for the price
this.price = price;
}
public void setNumpage(int numpage) {
this.numPages = numpage;
}
// reference for this part geeksforgeeks.org/string-tostring-method-in-java/
// Using this method, we are able to return the String representation of the // object.
public String toString() {
return "Title: " + title + " Publisher: " + publisher + " Author: " + author + " Price: " + price + " Numpages: " + numPages + " Genre: " + genre + " ";
}
public static void main(String[] args) { // Create the Book object and calling default constructor Book book1 = new Book(); System.out.println(book1.toString());
// Create the Book object and calling parameterize constructor Book book2 = new Book("Java Programming", "Georesh", 15, 1020, "Thriller", "Jaico"); System.out.println(book2.toString());
// Create the Book object and set value using setter and getter Book book3 = new Book(); book3.setTitle("Corn"); book3.setPublisher("Alfred"); book3.setAuthor("John"); book3.setPrice(300); book3.setNumpage(120); book3.setGenre("Alien"); System.out.println(book3.toString());
}
}
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel