For this question, we want to implement the basic
java classes to support the concept of an Online Store and a
shopping cart.
Consider an e-store with various types of items: books, flowers,
gift cards, etc... and we like to be able to support the ability to
handle a shopping cart that can contain various types of items.
For this question you are asked to create the following classes:
abstract class: “Item”
every item has a unique item_id (a positive integer,
auto-incremented for each new item), a price (double, 0 or
positive), and quantity (integer, 0 or positive), Title (String,
cannot be empty).Every item can be “Display()”, an abstract method,
and “Purchase()” (that is removed from the inventory).
concrete class: “Book”
a Book is-an item. It adds the attributes “author”, “title” and
“year”.
concrete class: “GiftCard”
a GiftCard is-an item. It adds the attributes “label”, and
“manufacturer”.
concrete class: “Shoe”
a Shoe is-an item. It adds the attributes “colour” (a String one of
these colours: white, silver, red, beige, brown, blue, black,
pink), and “size” (double).
Write an application that maintains a list of items entered from
the user by means of an interactive menu.
The user can:
Add item to the inventory, entering its type (book or gift card, etc), and necessary attributes along with quantity.
Display all items.
Display only books sorted by author name.
Display only gifts sorted by label.
Display only shoes sorted by sizeDelete an item by item_id
Purchase an item by removing the purchased quantity from the inventory
You should: Save items to a file, and
loading them back, using object serialization.
You should: use a linked list to enable dynamic
size for the e-store, instead of array object .
Write all necessary classes and methods to ensure the
responsibility driven assignment of classes in a pure
object-oriented approach enforcing all business rules. Document all
the rules and classes using Javadoc compatible documentation.
Answer: I have written an abstract class Item along with concrete classes Book, GiftCard, Shoe as demanded in the question using object orientated techniques.
Note: You may refer to screenshots below to have better understanding of the indentation.
Code:
import java.util.LinkedList;
abstract class Item{
private static int count = 0;
protected int itemID;
protected double price;
protected int quantity;
protected String title;
public abstract void display();
public abstract void purchase();
public Item()
{
itemID = ++count;
}
}
class Book extends Item{
private String author;
private int year;
private String bookTitle;
public Book(String title, double price, int
quantity, String author,String bookTitle, int year)
{
this.price = price;
this.quantity = quantity;
this.title = title;
this.author = author;
this.bookTitle = bookTitle;
this.year = year;
}
@Override
public void display() {
System.out.println("Book id: " +
itemID + ", Price: " + price + ", Quantity: " + quantity + ",
Author: " + author + ", year: " + year);
}
@Override
public void purchase() {
quantity = quantity - 1;
}
}
class GiftCard extends Item{
private String label;
private String manufacturer;
public GiftCard(String title, double price, int
quantity, String label, String manufacturer)
{
this.price = price;
this.quantity = quantity;
this.title = title;
this.label = label;
this.manufacturer =
manufacturer;
}
@Override
public void display() {
System.out.println("GiftCard id: "
+ itemID + ", Price: " + price + ", Quantity: " + quantity + ",
Label: " + label + ", Manufacturer: " + manufacturer);
}
@Override
public void purchase() {
quantity = quantity - 1;
}
}
class Shoe extends Item{
private String color;
private double size;
public Shoe(String title, double price, int quantity,
String color, double size)
{
this.price = price;
this.quantity = quantity;
this.title = title;
this.color = color;
this.size = size;
}
@Override
public void display() {
System.out.println("Shoe id: " +
itemID + ", Price: " + price + ", Quantity: " + quantity + ",
Color: " + color + ", Size: " + size);
}
@Override
public void purchase() {
quantity = quantity - 1;
}
}
public class ShoppingCart2 {
// create a list object to store the items
static LinkedList<Item> items = new
LinkedList<Item>();
public static void main(String[] args) {
Item i1 = new
Shoe("Shoe",50,10,"black",6);
Item i2 = new
Book("Book",10.0,20,"Dan Brown","Deception Point", 2001);
Item i3 = new
Shoe("Shoe",100,5,"pink",8);
Item i4 = new
GiftCard("GiftCard",2,50,"Friends","abc");
Item i5 = new
Book("Book",6.0,15,"Famous", "fRIENDS",1990);
//add items in the list
items.add(i1);
items.add(i2);
items.add(i3);
items.add(i4);
items.add(i5);
//display all items
System.out.println("All items in
the store: ");
for (Item item : items) {
item.display();
}
//display books
System.out.println("\nBooks in the
store: ");
for(Item item : items) {
if(item.title ==
"Book") {
item.display();
}
}
//display gifts
System.out.println("\nGifts in the
store: ");
for(Item item : items) {
if(item.title ==
"GiftCard") {
item.display();
}
}
//display shoes
System.out.println("\nShoes in the
store: ");
for(Item item : items) {
if(item.title ==
"Shoe") {
item.display();
}
}
}
}
Output:

Screenshots of the code:



For this question, we want to implement the basic java classes to support the concept of an...
JAVA
i need write java program
Object Classes: designing Shopping Cart
1.Shopping Cart , build a checkout system for a shop which sells
items (i.e., products say Bread, Milk, and Bananas). A shopping
cart that can have multiples. Costs of the products are : Bread -
$1, Milk - $0.60 and Banana - $0.40. A system should displays the
order total.
2.The heart of a shopping cart can be represented in three
classes: a cart class an order class, and...
DESCRIPTION You have to design an e-commerce shopping cart. These require classes Item, Electronics, Food, Dress, Cart and Main. ITEM CLASS Your Item class should contain: Attributes (protected) String name - name of the Item double price - price of the item Methods (public) void setName(String n) - sets the name of Item void setPrice(double p) - sets the price of Item String getName() - retrieves name double getPrice() - retrieves price String formattedOutput() returns a string containing detail of...
Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...
Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...
Problem Description to implement a Java application, called ShoppingApplication, that can be used in a retail store. You are asked to implement three classes: Item, Invoice, and InvoiceDriver. Each of these classes is described below. Item class The Item class represents of an item that is being sold in the retail store (e.g., book or pencil) where an item is identified by three instance variables: name (of type Sring), weight (of type double), price (of type double), and currentDiscount (of...
Need help solving this qestion related to object and item classes involving arrays in PYTHON. Classes and Object - Inventory Item as Object In this assignment the idea is to use an Item class to capture what you need for recording and displaying the details of an order from an online store like Amazon. This is a Class and Object assignment. For the assignment you must define and implement the Item class so that the code shown immediately below can...
Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of the class of the objects to be sorted. Several methods can be written for comparing the objects according to different criteria. Specifically, write three classes, DescriptionComparator, FirstOccComparator, and LastOccComparator that implement the interface java.util.Comparator. DescriptionComparator implements the interface Comparator. The method compare compares the description of two objects. It returns a negative value if the description of the first object comes before the description...
Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...
After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...