In PartA of this project, you will be creating BOOKItem class that will act as a template to store all of the data needed by the BIGGEST BARGAIN BOOKS, Inc to categorize its inventory. In Part2, you will be creating an application to test your new class to be certain all of its methods are doing what you expect.
Call the class BOOKItem.java
Call the Use Application Project7.java
Objective:Implement a class (which is a user defined data type) and an application to use it
Project Description: You will implement a BOOKItem class which will contain specific information about the books available in the store, then you will write an application to test your class.
PART 1 - GETTING STARTED THE CLASS DEFINITION:
Define the BOOKItem class
BOOKItem object will contain as private instance variables (data members):
- an integer bookID
- an integer numberInStock
- a double price
- a double totalValueOfStock
The BOOKItem class has as member methods:
- A default constructor that just initializes all of the members to 0 values
- A non default constructor that takes 4 parameters: an int id, int number in stock, an integer code and double price It will assign these values to the private data members by calling the set methods below and the calcTotalValue method below. If either the bookID, numberInStock or the price contain 0 values after the set methods have been called, set all values to 0 to indicate that the data was bad
- A method called setNumberInStock that takes as a parameter an int number in stock value and assigns it to the number in stock private data member, the number in stock is greater or equal to 1 and less than or equal to 5000, if not, assign 0
- A method called setID that takes as a parameter an int id and assigns it to the bookID private data member, if the id passed in is greater or equal to 11 and less than or equal to 111111. if not, assign a 0
- A method called setPrice that takes as a parameter a double price value and assigns it to the price private data Member, if the price is greater or equal to 1.0 and less than or equal to 150.0, if not, assign 0.0
- A method called getID that takes no parameters but just returns the int bookID
- A method called getNumberInStock that takes no parameters but just returns the int number in stock
- A method called getCode that takes no parameters but just returns the int code
- A method called getPrice that takes no parameters but just returns the double price
- A method called calcTotalValue that takes no parameters. It calculates the total value of stock for all of these movie books by mulitplying the number in stock times the price
- A method called getTotalValue that takes no parameters but just returns the total value
- A method called display that outputs the 5 data members onto the DOS screen in one line pass in parameters: Use formatting to print:
ID: 111 Numberinstock: 010 Price: $20.00 Total Value: $200.00
HOW TO FORMAT
- add the import statement you need to use the DecimalFormat class to the class definition
- just above the private instance variables you defined, create 2 objects of the DecimalFormat class
- one to format integers with 3 zero placeholders
- one to format decimals with a $ and commas, and 1 zero placeholders to the left of the decimal point and 2 zero placeholders to the right of the decimal point
- include in the display output statement the formats for int and double
- you will need a conditional to evaluate the code to print the correct category
Part 2: Write the Use Application written for Project 7 to allow input from the user . You will need to add 2 import statements
- One to allow you to use the Scanner
- One to allow you to use the JOptionPane
In the Project7B user application, you will be testing all methods of the BOOKItem class including testing the set methods with bad data. With BAD data, the display should reveal all 0 values Finally, try with all good data and you should see that reflected in the output to the JOptionPane
1) in the main method
a) Declare FOUR objects of the BOOKItem class, BOOK1, BOOK2, BOOK3, BOOK4
FOR BOOK1: call the default constructor to create the first, BOOK1
- print the message: BOOK1 created using default constructor
- call display for BOOK1 (you should see all 0 values)
A.Use System.out message to prompt the user for 3 integers and a decimal value for the pin, number in stock, quality and price. Enter a bad ID (< 11 or >111111)
- use the set methods on BOOK1 to assign the values input by the user
- print the message: BOOK1 after calling set methods
- call display for BOOK1 (you should see values you entered)
- call the calcTotalValue method
- print the message: BOOK1 after calling calculate method
- call display for BOOK1 (you should see only a zero value for id)
FOR BOOK2: call the NON-default constructor to create the second, BOOK2 after the user has input the data from the Scanner as shown in B below
B.Use System.out message to prompt the user for 3 integers and a decimal value for the pin, number in stock, quality and price. Enter a bad number in stock (>5000)
- print the message: BOOK2 created using non-default constructor
- call display for BOOK2 (you should see all 0 values)
FOR BOOK3: call the NON_default constructor to create the second, BOOK3 after the user has input the data from the Scanner as shown in C below
C.Use System.out message to prompt the user for 3 integers and a decimal value for the pin, number in stock, quality and price. Enter a bad price(>150.0)
- print the message: BOOK3 created using non-default constructor
- call display for BOOK3 (you should see all 0 values
FOR BOOK4: call the NON-default constructor to create the second, BOOK4 after the user has input the data from the Scanner as shown in D below
D. Prompt the user to put in all good data in the order: id, number in stock, quality and price. Create BOOK4 using the non-default constructor and the values input by the user. PROMPT FOR ALL GOOD DATA WHEN TESTING
- print the message: BOOK4 created using non-default constructor
- call display for BOOK4 (you should see values you input)
- print the message: BOOK4 values using get methods
- call each get method on BOOK4 and print the value returned This time, print all values using a System.out message AND a JOptionPane output dialog box. Format as follows:
- print all values returned from calling the get (accessor) methods in System.out.println statements with no formatting
- print money values in the JOptionPane formatted using money format (US Locale)
check all calculated values by calculating by hand see image.