rite Java Classes In this problem, you will create a shopping cart that will help a user keep track of bought items and their prices. To do so, you will first create an Item class, a ShoppingCart class and finally a driver class in which you will read items’ information from a text file and print the bill to the user.   A. Item Class  1. The item class is defined by the following properties: a. Name. b. Price (Representing the unit price). c. Quantity (Representing the number of units). 2. Add a constructor that takes as argument the name, price and quantity of the food item. Initialize your variables accordingly.

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
Write Java Classes
In this problem, you will create a shopping cart that will help a user keep track of bought items and their prices. To do so, you will first create an Item class, a ShoppingCart class and finally a driver class in which you will read items’ information from a text file and print the bill to the user.
 
A. Item Class 
1. The item class is defined by the following properties:
a. Name.
b. Price (Representing the unit price).
c. Quantity (Representing the number of units).
2. Add a constructor that takes as argument the name, price and quantity of the food item. Initialize your variables accordingly.
3. You will need to retrieve all the properties of the class later on. Add the appropriate methods.
4. Add the following methods:
a. A toString method that returns a properly formatted summary of the: name of the item, unit price (in U.S dollars) and the quantity as shown below:
Bread 00.69$ * 3
b. A getTotalPrice method that returns the total price based on the items in the cart.
 
 
B. Shopping Cart Class 
1. The ShoppingCart class is defined by the following properties:
a. An array of items to keep track of the items in the cart.
b. Item count representing the number of items in the cart.
c. Total Price representing the total price of cart based on the items.
2. Add a constructor that takes no arguments. Your constructor must initialize all your variables. Consider that the original capacity is 5 items.
3. Add the following method to your class:
 
a. increaseSize: a method that increases the capacity of the cart by 3. The method must preserve the food items already stored. This method will only be called from within the ShoppingCart class.
b. addToCart: a method that takes as argument an Item object and adds it to the cart. This method should also update all class variables accordingly upon the addition of an item.
c. Since the item capacity is initialized to 5, you must make sure that the capacity is not full. If the cart is full, use the appropriate method to increase the size of the cart before adding the item.
d. toString: the toString method should return a summary of the cart as shown in the sample below:
 
Cart items:
Bread 00.69 $ * 3
Cheese 01.24 $ * 2
Chicken 01.49 $ * 10
Total Price: 19.45 $
 
 
C. Driver Class 
1. Copy and paste the information below in a text file called “Items.txt”
Item                Unit price ($)                quantity (100 grams)
Bread             0.69                             3
Cheese          1.24                             2
Chicken         1.49                             10
2. Using the information in the text file create a ShoppingCart of Items.
3. Print a summary of the cart for the user.
  1.  
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 7 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