Problem B Now we are going to use the design pattern for collecting objects. We are going to create two classes, a class AmazonOrder that models Amazon orders and a class Item that models items in Amazon orders. An item has a name and a price, and the name is unique. The Item class has a constructor that takes name and price, in that order. The class also has getters and setters for the instance variables. This is the design pattern for managing properties of objects. The setName() method should do nothing if the parameter is the empty string, and the setPrice() method should do nothing if the parameter is not positive. The class also has a toString() method that returns a string representation for the item in the format “Item[Name:iPad,Price:399.99]”. For simplicity, we assume an Amazon order can have at most 5 items, and class AmazonOrder has two instance variables, an array of Item with a length of 5 and an integer numOfItems to keep track of the number of items in the order. Provide a constructor that takes no parameters to initialize the two instance variables. Use a constant for the array length 5. The class has five public methods and one private method: • public void add(Item item) Adds the specified item to the end of this order. No effect if the item is in this order already or this order has 5 items already. • public void remove(Item item) Removes the specified item from this order and maintains the order of all remaining items. No effect if the item is not in this order. • public double totalCost() Finds the total cost of this order and returns 0 if this order has no items. • public Item lastMostExpensive() Finds the last most expensive item of this order and returns null if this order has no items. • Public String toString() Gets a string representation for this order in the format “[Item[...], Item[...], . . ., Item[...]]”, where each Item[...] is the string returned by method toString() of an item in this order. Do not use an if statement inside the for loop. • private int indexOf (Item item) Gets the index of item in this order and returns NOT_FOUND (-1) if item is not in this order. Note: Call the private method indexOf() inside methods add() and remove(). If the return value is NOT_FOUND, the item is not in this order.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Problem B Now we are going to use the design pattern for collecting objects. We are going to create two classes, a class AmazonOrder that models Amazon orders and a class Item that models items in Amazon orders. An item has a name and a price, and the name is unique. The Item class has a constructor that takes name and price, in that order. The class also has getters and setters for the instance variables. This is the design pattern for managing properties of objects. The setName() method should do nothing if the parameter is the empty string, and the setPrice() method should do nothing if the parameter is not positive. The class also has a toString() method that returns a string representation for the item in the format “Item[Name:iPad,Price:399.99]”. For simplicity, we assume an Amazon order can have at most 5 items, and class AmazonOrder has two instance variables, an array of Item with a length of 5 and an integer numOfItems to keep track of the number of items in the order. Provide a constructor that takes no parameters to initialize the two instance variables. Use a constant for the array length 5. The class has five public methods and one private method: • public void add(Item item) Adds the specified item to the end of this order. No effect if the item is in this order already or this order has 5 items already. • public void remove(Item item) Removes the specified item from this order and maintains the order of all remaining items. No effect if the item is not in this order. • public double totalCost() Finds the total cost of this order and returns 0 if this order has no items. • public Item lastMostExpensive() Finds the last most expensive item of this order and returns null if this order has no items. • Public String toString() Gets a string representation for this order in the format “[Item[...], Item[...], . . ., Item[...]]”, where each Item[...] is the string returned by method toString() of an item in this order. Do not use an if statement inside the for loop. • private int indexOf (Item item) Gets the index of item in this order and returns NOT_FOUND (-1) if item is not in this order. Note: Call the private method indexOf() inside methods add() and remove(). If the return value is NOT_FOUND, the item is not in this order.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY