Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Account class has an integer instance variable, amount, to represent the available fund. The canAfford() method takes an integer parameter being a cost of an

Account class has an integer instance variable, amount, to represent the available fund. The canAfford() method takes an integer parameter being a cost of an order item and returns if there is enough fund in the account to afford that. The spendAmount() method takes also an integer parameter being a cost of an order item and deducts the amount by that cost. Order class uses an object of Account class. It should have a list of OrderItem objects. The addOrderItem() method takes an object of OrderItem as the parameter. It calls the account object to check if there is enough fund to cover the cost of the order item. If so, it invokes the spendAmount() on the account object, stores the order item in a list and returns true. Otherwise, it returns false. The getTotal() method returns the total cost of all order items in the order. The printOrderItems() method prints information about each order item. OrderItem class has a String upc, an integer quantity and an integer price. The getCost() method returns the multiplication of its quantity and price. Introduce a Project2 class as a test driver. It should execute as follows:

a. Create an Account object with a random amount between 100 to 200 inclusive. b. Create an Order object and pass to it the account reference. i. Prompt the user to enter the UPC code for the item or done to quit. ii. While the user enter a UPC (anything other than done), prompt for and read the quantity. You may assume the user enters a valid input, that is, an integer. iii. Generate a random number from 50 to 100 for the price. iv. Create an OrderItem object with UPC, quantity and price. v. Invoke the addOrderItem() method on the order reference with the order item just created. If it returns false, it means there is not enough fund in the account, so break the loop. vi. Continue the loop until either user enters done or account can no longer afford a new order item.

c. Print out all the order items and the total cost.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

Is conflict always bad?

Answered: 1 week ago

Question

I Which of your reasons (if any) were not under your controli>

Answered: 1 week ago

Question

LO12.5 Discuss the economic effects of monopoly.

Answered: 1 week ago

Question

LO12.1 List the characteristics of pure monopoly.

Answered: 1 week ago