Develop a program to emulate a purchase transaction

Assignment Help JAVA Programming
Reference no: EM131290933

Retail Transaction Programming Project

Project Requirements:

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.

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 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 this instance, 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 "\n" can be inserted into the middle of a string.

Ex.
int age = 30;
String temp = "John Doe \n is " + age + "\n" + " years old";

The output would be:

John Doe is 30 years old

Notice also that "\n" 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<LineItem>

- customerID : int

- customerName : String

 

+ Transaction( int, String )

+ addLineItem( String, int, double )

+ updateItem( String, int, double )

+ getTotalPrice( ) : double

+ getLineItem( String ) : String

+ toString( ) : String

Reference no: EM131290933

Questions Cloud

Is the futures overpriced or underpriced : Assuming annual compounding, suppose the risk-free rate is 5.96 percent, and the future value of dividends on the index is $5.27. Is the futures overpriced or underpriced?
Laws to promote and protect unions : Do you think it is still necessary for laws to promote and protect unions? What would you change regarding union laws? Justify your answer.
Resist labor-management partnerships : Why do you think unions might resist labor-management partnerships? Why might employers resist labor-management partnerships? Justify your answer.
Make critical marketing decisions without marketing research : In the business world of the 21st century, will it be possible to make critical marketing decisions without marketing research? Why or why not?
Develop a program to emulate a purchase transaction : 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.
Describe a motivational policy-action : Thinking of either a school or job example, describe a motivational policy/action that was used with students/workers. What theory seems to best explain the policy/action?  Explain how the policy/action is effective in motivating students/employee..
Identify any arbitrage and explain how it would be captured : Assume a standard deviation of 8 percent, and use the Black model to determine if the call option in problem 18 is correctly priced. If not, suggest a riskless hedge strategy ?
Understand deming profound knowledge : Failure to understand the components of Deming's profound knowledge can create some severe problems. Answer the following three questions to relating Peter Scholtes's observations about the failure to understand Deming's profound knowledge.
Comment on the given statements : Comment on the information research process serves as a blueprint for reducing risks in making marketing decisions.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Days alive calculator

The context for this assignment (all parts) is a ‘Days Alive Calculator' - a small desktop application for calculating the number of days someone has been alive based on the date of birth and a second date, which may be today's date or some other ..

  Create an application that demonstrates the use of the class

Create an application that demonstrates the use of the classes. Save the files as Player.java, Child.java, Actor.java, Musician.java, and UsePlayer.java.

  Implement one class called parking meter

Implement one class called parking meter, that is a simple model of a coin operated parking meter

  Critics of american often that teacher''s unions represent

Which organization has proposed a set of standards for both elementary level and secondary-level teachers? According to the latest info.,  teachers will be most needed in which of the following areas: Critics of American often argue that teacher's un..

  Define output operators for clock and travelclock

Define output operators for Clock and TravelClock. Modify the classes Clock and TravelClock to declare the output operators as friends.

  Develop a java program that simulates the queues in a bank

Develop a java program that simulates the queues in a bank. Implement the event-driven simulation of a bank. A queue of arrival events will represent the line of customers in the bank.

  Write a program that will calculate monthly pay

Write a program that will calculate monthly pay and expenses for a commercial utility sales person. Sales employees in this company are paid monthly. Each employee is paid a base pay of $1,000 and 9½ % commission on sales. The company deducts 18% of..

  Display a list of entries in a jtextarea or jtable

Create a GUI-based program to accept name of donor, name of charity, and amount of pledge from the user. Display a list of entries in a JTextArea or JTable

  Implement a generic stack and queue classes

CMSC 350 Project - Implement a generic stack and queue classes (StackUMUC and QueueUMUC , named to avoid confusion with the classes already defined in the JDK)- Create a set of tests demonstrating that your classes work correctly.

  Compute the amount of money earned

If you invest the amount of P at R% interest rate annually. In N years, your investment will be P[1-(R/100)N+1] / (1 – R/100). Accepts the input of P, R and N and compute the amount of money earned after N years using computer currency forma..

  Write program to keep track of a hardware stores inventory

Write a program to keep track of a hardware store's inventory. The store sells various items. For each item in the store, the following information is kept: item ID, item name, number of pieces in stock, manufacturer's price of the item, and the s..

  Write down a java program that implements a stack of

write a java program which implements a stack of integers. an integer should only be pushed into the stack if it is

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd