Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Practice 1.15 through Exercise 1.19, you are asked to describe a class desig

ID: 3910445 • Letter: F

Question

For Practice 1.15 through Exercise 1.19, you are asked to describe a class design. In each case, clearly specify the following aspects of your design:

• Give a list of attributes, describing the purpose of each.

• Give a list of supported behaviors, clearly indicating the action that takes place and whether or not this behavior has any effect on the state information. Also indicate the purpose of any parameters and the purpose of a return value, if applicable.

Exercise 1.19: Describe an initial design for a ShoppingCart class, as used by a typical online merchant.

Explanation / Answer

We will design a BankAccount class:

List of Attributes for BankAccount class

1.AccountNumber: A unique 4 digit number to identify an account.The type is int
2.Balance :This holds the balance information. The type is double
3.Name : Name of the customer. The type is string
4.Address: Address of the customer. The type is string

Behaviour of the BankAccount class

1.BankAccount(accountNumber,balance,name, address): This creates an object of BankAccount class
2.setAccountNumber() : This sets the account number. Yes it affects the state
3.getAccountNumber() : This gets the account number. No it has no effect on the state
4.setBalance() : This sets the balance.Yes it affects the state
5.getBalance() : This gets the balance.No it has no effect on the state
6.setName() : This sets the name .Yes it affects the state
7.getName() : This gets the balance.No it has no effect on the state
8.setAddress() : This sets the address .Yes it affects the state
9.getAddress() : This gets the balance.No it has no effect on the state
10.deposit(amount) : This deposits the amount to the account.The amount should not be negative.The amount gets added to the balance.It affects the state.
11.withdrawl(amount) : This withdraws the amount from the account.The amount should not be negative.The amount gets reduced from the balance.
                       It does not perform the operation if balance is less than the withdrawl amount.It generates appropriate message.It affects the state.


All the behviors access will be public while all the attributes will have private access


Shopping Cart Class (Initial Design)


List of Attributes for BankAccount class

1.Identity Number: A unique 3 digit number to identify a shopping cart .The type is int
2.Number of Items :This holds the number of items in the shopping cart. The type is int.
3.Name : Name of the customer. The type is string
4.List of Items: This holds the list of items in the shopping cart. The type is an array of items
5.List of Prices: This holds the list of unit prices of the items. It is a kind of the parallel array such that i index of this array gives the price of
                  of the item present in the ith index of list of the item.
6.Quantity list : This is the list of quantities of items. Again this is a parrallel array similar to list of prices described above.

Behaviour of the Shopping Cart:

1.AddItem(item, number of items) : This adds item to the List of items in shopping cart.This also makes an entry in list of unit prices and Quantity list.
                                   This affects state.
2.DeleteItem (Item, number of items):This deletes item from the quantity list of items in shopping cart.If the number of items to be deleted is equal to the number
                                     of items in the shopping cart, then other relevant entries in the unit price list and the item list is also removed.This
                                     affects state.
3.CalculatePrice(): This calculates total price by using unit price list and quantity list.
4.IsEmpty() : This checks whether shopping cart is empty or not. It checks the item list for that.No effect on the state
5.IsFull(): This checks if the shopping cart is full.Again this checks the limit of the item list.No effect on the state.

   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote