character. For example if a book has [title=Treasure Island author=Robert Louis Stevenson content=To S.L.O., an American...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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", 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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Sherman Co. began operations on January 1, 2015, and completed several transactions during 2015 and 2016 that involved sales on credit, accounts receivable collections, and bad debts. These...
-
Leo Consulting enters into a contract with High gate University to restructure High gate's processes for purchasing goods from suppliers. The contract states that Leo will earn a fixed fee of $25,000...
-
Do you think that the use of social media for recruitment is an effective approach to recruit workers?
-
The adjusted trial balance shows a. amounts that may be out of balance. b. revenues and expenses only. C. assets, liabilities, and common stock only, d. amounts that are ready for the financial...
-
The U.S. Energy Department states that 60% of all U.S. households have ceiling fans. In addition, 29% of all U.S. households have an outdoor grill. Suppose 13% of all U.S. households have both a...
-
Research the following about Girl Scout of America: 1. How much is their total revenue for the most recent year reported? 2. How much of their revenue comes from governmental money? 3. What is their...
-
Find and classify the stationary values of the function f(x, y) = sin x cos y + 2 cos x sin y in the range 0xm, x y 0syn. fxy 2 fxxfyy-fxy Type f(x,y)
-
.4.32 The given table shows the preference schedule for an election with four candidates (A, B, C, and D). Use the plurality-with-elimination method to solve parts a and b Number of Voters 25 16 17...
-
What are the 8 aspects of the study of the Sociology of Law ? How does sociology of law contribute to the overall definition of criminology?
-
On December 31, 2020, Berclair Inc. had 420 million shares of common stock and 3 million shares of 9%, $100 par value cumulative preferred stock issued and outstanding. On March 1, 2021, Berclair...
-
In July, Dotilla Bedding is budgeting to produce 830 waterbeds. Each bed produced requires 4.5 hours of direct labor time. The direct labor rate is $12 per hour. Overhead costs are budgeted at $3.20...
-
A 6-year project is expected to generate annual sales of 8,900 units at a price of $76 per unit and a variable cost of $47 per unit. The equipment necessary for the project will cost $317,000 and...
-
Two resistors are connected in series, R =B 2 and R= DQ to a battery of 12 V. a. What is the voltage across R? b. What is the voltage across R? c. Calculate the current on the loop?
-
5. Aradio can tune into any station in the 7.5 MHz to 12MHz band. What is the corresponding 24 wavelength band?
-
One Way Cellular accountants have assembled the following data for the year ended September 30, 2014: Prepare the operating activities section using the indirect method for One Way Cellulars...
-
How can you remove a user account from Oracle 11g?
-
Suppose the user Juan creates a table called MYTABLE with four columns. The first column has a PRIMARY KEY constraint, the second column has a NOT NULL constraint, the third column has a CHECK...
-
Oracle 11g automatically creates an index for which type of constraints? a. NOT NULL b. PRIMARY KEY c. FOREIGN KEY d. UNIQUE KEY e. Mone of the above f. Only a and b g. Only b and d
-
A uniform circular disc is pivoted at point \(O\), as shown in Fig. 2.105. Find the natural frequency of the system. Also find the maximum frequency of the system by varying the value of \(b\). b...
-
Find the natural frequency of the traffic sign system described in Problem 2.79 in torsional vibration about the \(z\)-axis by considering the masses of both the post and the sign. The spring...
-
Solve Problem 2.99 by changing the material from steel to bronze for both the post and the sign. Material properties of bronze: \(ho\) (specific weight) \(=80.1 \mathrm{kN} / \mathrm{m}^{3}, E=111.0...
Study smarter with the SolutionInn App