Develop a program to emulate a purchase transaction at a


1. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual line item of merchandise that a customer is purchasing. The Transaction class will combine several LineItem objects and calculate an overall total price for the line item within the transaction. There will also be two test classes, one for the LineItem class and one for the Transaction class.

2. Design and build a LineItem class. This class will have three instance variables. There will be an itemName variable that will hold the identification of the line item (such as, "Colgate Toothpaste"); a quantity variable that will hold the quantity of the item being purchased; and a price variable that will hold the retail price of the item. The LineItem class should have a constructor, accessors for the instance variables, a method to compute the total price for the line item, a method to update the quantity, and a method to convert the state of the object to a string. Using Unified Modeling Language (UML), the class diagram looks like this:

LineItem
- itemName : String
- quantity : int
- price : double

+ LineItem( String, int, double )
+ getName( ) : String
+ getQuantity( ) : int
+ getPrice( ) : double
+ getTotalPrice( ) : double
+ setQuantity( int )
+ setPrice( double )
+ toString( ) : String

a. The constructor will assign the first parameter to the instance variable itemName, the second parameter to the instance variable quantity, and the third parameter to the instance variable price.

b. The class will have three accessor methods-getName( ), getQuantity( ), and getPrice( )-that will return the value of each respective instance variable.

c. The class will have two mutator methods, setQuantity( int ) and setPrice( double ), that will update the quantity and price, respectively, of the item associated with the line of the transaction.

d. The method getTotalPrice( ) handles the conversion of the quantity and price into a total price for the line item.

e. The method toString( ) allows access to the state of the object in a printable or readable form. It converts the variables to a single string that is neatly formatted.

Note: Refer to the textbook for a discussion of escape sequences. These are characters that can be inserted into strings and, when printed, will format the display neatly. An escape sequence for the tab character can be inserted to get a tabular form when printing. This tab character is "\t".

The LineItem class will have a toString( ) method that concatenates itemName, quantity, price, and total price-separated by tab characters-and returns this new string. When printing an object, the toString( ) method will be implicitly called, which in this case, will print a string that will look something like:

Colgate Toothpaste    qty    2   @   $2.99             $5.98

3. Build a Transaction class that will store information about the items being purchased in a single transaction. It should include a customerID and customerName. It should also include an ArrayList to hold information about each item that the customer is purchasing as part of the transaction Note: You must use an ArrayList, not an array.

4. Build a TransactionTest class to test the application. The test class should not require any interaction with the user. It should verify the correct operation of the constructor and all methods in the Transaction class.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Develop a program to emulate a purchase transaction at a
Reference No:- TGS01146417

Now Priced at $35 (50% Discount)

Recommended (95%)

Rated (4.7/5)