Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The old program Objective: Class composition In an online shopping web application, the user views several items to buy. Each item can be added to

image text in transcribed
image text in transcribed
The old program
image text in transcribed
image text in transcribed
Objective: Class composition In an online shopping web application, the user views several items to buy. Each item can be added to the shopping cart. When the user check-out, all the items in the shopping cart are listed and the total price is computed. A. Design and Implement aclass which can hold up to 20 Items. Use a normal array as a container for the items. The ShoppingCart class must have the following attributes and methods: Class attributes: All items must be declared private a. itemList defined as 1 dimensional array composed of the previously user defined Item data type (class) and holds a maximum size of 20 items.(refer to lab 4) numltems an integer represents the total number of items currently in the shopping cart defaulted to zero. b. Class constructors Only a default constructor should be defined to create an empty shopping cart. When this constructor is called, it should initialize the array itemList and set the numltems to zero ShoppingCart Class methods: a. Class Methods a. addltem(ltem anltem): this method take anlTem as input and add it to the itemList array. Each time an item is added, the numitem must be incremented. This methods returns nothing (void). removeltem(String itemname): this method takes an item name and remove it from the shopping cart itemList. If the item was removed correctly, this methods return true Boolean value. If the item is not in the itemList, it should return false Boolean value. b. c. checkout0: this method will print out a list of all items in the shopping cart and count and print the total items price. Note: you have to apply good programming style and documentation in developing and maintaining your codes. B. Use the previously implemented Class to test by doing the following 1. 2. 3. 4. Define a ShoppingCart Add the items to the shopping cart Remove one item from the shopping cart Checkout and display the total of the items in the cart. Note: you have to apply good programming style and documentation in developing and maintaining your codes public class Item ( private String code private String name private double price; public ItemO ( code name price 0.0; public Item(String code, String name, double price) ( this.code code; this.name name; this.price price; public void setCode(String code)( this.code code; public void setName(String name) ( this.name name public void setPrice(double price) this.price price public String getCode0 return code public String getNamel ( public String getName0 ( return name public double getPrice)( return price; public String toString0 return "Item code:" +code+"name: name+"price:"+ price class OnlineShopping ( public static void main(String] args) ( Item i- new Item("001", "lphone, 3000.00); System.out.println(); i.setName lphoneX) System.out.println(i.getCode0): System.out.println() Item j new Item0 j.setCodef"O02") j.setName("Nexus); j.setPrice(2000.00); System.out.println(j.getCode0) System.out.println(j.getName0) System.out.printlnG. System.out.println): getPrice0

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago

Question

1. Organize and support your main points

Answered: 1 week ago

Question

3. Move smoothly from point to point

Answered: 1 week ago

Question

5. Develop a strong introduction, a crucial part of all speeches

Answered: 1 week ago