Question: character. For example if a book has [title=Treasure Island author=Robert Louis Stevenson content=To S.L.O., an American gentleman... and edition=1 then we'd expect its toString()

character. For example if a book has [title="Treasure Island" author="Robert Louis Stevenson" content="To S.L.O., an American gentleman..." and edition=1 then we'd expect its toString() method to return the following string (without any space characters at the end of lines!) Title: Treasure Island Author: Robert Louis Stevenson Edition: 1 Part 2. A vending machine for books Write a class called "Vending Machine" that can sell books to customers. The price each book sells for will depend on the size of the book but also on some "location factor" that allows us to sell books at higher prices in posher areas. For instance, a book with 500 pages sells for 500*0.01 = 5.0 GBP from a vending machine with location factor 0.01. Requirements Your Vending Machine class should store books on shelves, which are to be modelled as a list of books, i.e., there is a private attribute called "shelf" that has type List . In addition, there should be private attributes "locationFactor" (a double), "cassette" (a double) to hold coins while buying a book "safe" (a double) to hold all coins resulting from sales "password" (a String), that is used to open it to collect the money from the safe and restock. Your class must have a constructor method that takes exactly two parameters, namely the location factor (a double), and a password (a String). public Vending Machine (double locationFactor, String password) These items should be stored in the vending machine in the private attributes (of the same name and type) to be accessed later. The constructor should also initialise the "cassette" and "safe" attributes to zero, and initialise the shelf to an appropriate collection object. The class should have public methods as follows. 1. a method called "getCassette" public double getCassette() a simple getter method for the "cassette" attribute. 2. a method called "insertCoin" public void insertCoin (double coin) that adds the value of is parameter to the cassette. This method should throw an IllegalArgumentException if the given coin is not of the right denomination. Acceptable values are 0.01), (0.02), 0.05, 0.1, 0.2, 0.5, 1, and 2. 3. a method called "returnCoins" public double returnCoins () that empties the cassette (sets it to zero) and returns its original value. 4. a method called "restock", 4. a method called "restock", public void restock (List books, String password) that restocks the vending machine's bookshelf. If the given password matches the one stored in the "password" attriobute then the books from the first argument are copied onto the "shelf" attribute of the vending machine. Otherwise, if the passwords don't match, this method should throw an (unchecked) exception of type Invalid PasswordException. This type of exception does not exist in the Java standard library and needs to be defined as a new subclass of RuntimeException. 5. a method called "emptySafe", public double emptySafe (String password) that resets the value of the "safe" attribute to zero, and returns its former value, if the given password parameter matches the one stored in the "password" attribute. Otherwise, if the passwords don't match, this method should throw an (unchecked) exception of type Invalid PasswordException just like the restock method. 6. a method called "getCatalogue" public List getCatalogue() that returns a list of Strings that describe the books on the shelf. That is, the length of the returned List should be the same as the internal shelf, and each string should be the return value of the tostring() method of the corresponding book at that position. 7. a method called "getPrice" public double getPrice(int index) that returns the price of the book with the given index on the shelf. The price of the book should be the number of its pages times the location factor of the vending machine. If the parameter index is not a valid (there is no book at this shelf index) then this should throw an IndexOutOfBounds Exception. 8. a method called "buyBook" public Book buyBook(int index) that sells a book with the given index on the shelf. It should check if the price of the book is at most the value of cassette. The price of the book is the number of pages multiplied by the location factor of the vending machine. If the cassette contains enough money then the method removes the book from the shelf, reduces cassette, and increases safe by the price of the book and returns the book. The buyBook method should also be able to throw (unchecked) exceptions for the following two scenarios: 1. If the parameter (index) is not a valid (there is no book at this shelf index) then this should throw an IndexOutOfBounds Exception. 2. If the price of the book exceeds the value of the cassette then the method should throw a CassetteException. This type of exception is of course special to our application and you should define it yourself as a new type of RuntimeException). Part 3: The Press Write a class called 'hat can be used to create books. The books we'll create. going to be re-prints of famous volumes whose copyright has expired. We can get them as (UTF8 encoded) text files from Project Gutenberg and a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
