Question
Setting up Book.java and a BookList.java files. Need to make sure the code in BookList is doing the correct stuff. How do I write a
Setting up Book.java and a BookList.java files. Need to make sure the code in BookList is doing the correct stuff. How do I write a JUnit test for the BookList add method?
public class BookList implements Iterable {
//variables
public Book[] list; //list of books to draw from "underlying array"
public int size; //number of books in collection
//default constructor, initializing variables
public BookList() {
list = new Book[10];
size = 0; }
//alternate constructor creates bookList of books available to sell
public BookList(Book[] bookList) {
//does this work - in an alternate constructor, copying array?
//need to do for(int i = 0; i < list.length; i++) with copy[i] = list[i]?
list = bookList; size = list.length; }
//adds a book to the underlying array
public void add(Book book) {
if (size == list.length) {
ensureCapacity(); }
list[size] = book; size++; }
}
Code for Book.java:
public class Book {
String title; String author; double price; //price customer pays to buy the book from store owner double minPrice = 57.00; //minimum price? what use is this?
//default constructor method, initializing variables public Book() { title = ""; author = ""; price = 0.0; }
//alternate constructor method...modify to instantiate any new variables //created so they are not auto-initialized with inappropriate values public Book(String newTitle, String newAuthor, double newPrice) { title = newTitle; author = newAuthor; price = newPrice; }
public String getTitle() { return title; }
public String getAuthor() { return author; }
//price customer pays to buy the book from store owner public double getPrice() { return price; }
//cost to store owner to get the book in store? //public double getCost() { // return cost; //}
public String toString() { return ("Title: " + title + "\t" + "Author: " + author + "\t" + "Price: " + price);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started