Question
Specific Requirements for the Transaction Class 1. The Transaction class should have a constructor with two parameters. The first is an integer containing the customer's
Specific Requirements for the Transaction Class
1. The Transaction class should have a constructor with two parameters. The first is an integer containing the customer's ID and the second is a String containing the customer's name.
2. There should be a method to allow the addition of a line item to the transcript. The three parameters for the addLineItem method will be (1) the item name, (2) the quantity, and (3) the single item price.
3. There should be a method to allow the updating of a line item already in the transaction. Notice that updating an item means changing the quantity or price (or both). The parameters for the updateItem method are also (1) the item name, (2) the quantity, and (3) the single item price. Notice that the updating of a 2014 Laureate Education, Inc. Page 3 of 4 specific line item requires a search through the ArrayList to find the desired item. Anytime a search is done, the possibility exists that the search will be unsuccessful. It is often difficult to decide what action should be taken when such an "exception" occurs. Since exception handling is not covered until later in this textbook, make some arbitrary decisions for this project. If the item to be updated is not found, take the simplest action possible and do nothing. Do not print an error message to the screen. Simply leave the transaction unchanged.
4. The transaction class needs a method called getTotalPrice to return the total price of the transaction.
5. There should also be a method to return information about a specific line item. It should return a single String object in the same format described for the LineItem class:
Colgate Toothpaste qty 2 @ $2.99 $5.98
Again, the possibility exists that the search for a specific line item will fail. In thisinstance, you should return a string containing a message similar to this:
Colgate Toothpaste not found.
6. The final method needed is a toString method. It should return the transaction information in a single String object. It should use the following format:
Customer ID : 12345
Customer Name : John Doe
Colgate Toothpaste qty 2 @ $2.99 $5.98
Bounty Paper Towels qty 1 @ $1.49 $1.49
Kleenex Tissue qty 1 @ $2.49 $2.49
Transaction Total $9.96
Notice that a newline character " " can be inserted into the middle of a string.
Ex.
int age = 30;
String temp = "John Doe is " + age + " " + " years old";
The output would be:
John Doe
is 30
years old
Notice also that " " is a single character and could actually go inside single or double quotes, depending on the circumstances.
Here is a UML diagram for the Transaction class as described above. Notice that private instance variables and methods may be added, as needed. For all public methods use exactly the name given below.
Transaction
- lineItems : ArrayList - customerID : int
- customerName : String
+ Transaction( int, String )
+ addLineItem( String, int, double )
+ updateItem( String, int, double )
+ getTotalPrice( ) : double
+ getLineItem( String ) : String
+ toString( ) : String
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