Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Please help me write this program to simulate a shopping cart

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Please help me write this program to simulate a shopping cart

    You will design and implement items of a Shopping Cart.

    An item in the shopping cart could be one of the following types: Food, Apparel, Beverage, Hardware. You will design and implement the set of classes that define various types of items. Each class should have a constructor which initializes all of the attributes values and appropriate set/get methods. You will write a toString method in order to print the attributes of the item as well.
    Shopping Cart Item Types The following item types may exist in a shopping cart: Food, Apparel, Beverage, Hardware. Descriptions and attributes you should store for each type are listed below. You should write separate classes for each item type and arrange these into an acceptable class hierarchy for the sake of modularity and code re-use.
    • Food: Food type has a title field (string), a price field (double), a brand field (string) and type field(string). Type may be one of the following "meat","snack","dairy product","canned food" etc...
    • Apparel: Apparel type has a title field (string), a price field (double), a brand (string), a season field (string). Season may be "Winter", "Summer" etc.
    • Beverage: Beverage type has a title field (string), a price field (double), a brand (string) and a boolean field which specifies whether it is an alcoholic drink or not.(i.e. isAlcoholic)
    • Hardware: Hardware type has a title field (string), a price field (double), a brand (string), and an integer field for warranty period.
    You will design and implement a class that simulates a shopping cart as an ArrayList of items.
    ShoppingCart class should have an ArrayList instance as a container for items.
    The methods are as follows:
    • Constructor: initializes the ShoppingCart, instantiates a new ArrayList of items.
    • addItem: This method should add the item to the cart.
    • toString: as usual returns a String which holds all the Items, the total number of items and the total price.
    Write a program that simulates shopping. Instantiate a number of items of type Food, Apparel, Beverage and Hardware. Add these items to a ShoppingCart instance. Display stored items by calling toString method of the ShoppingCart.
    Last edited by keyna_laure; June 4th, 2020 at 09:29 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help me write this program to simulate a shopping cart

    Ok, what have you tried? What problems are you having?
    Do you have any specific questions?

    Be sure to wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Default Write a Java program to simulate an online shopping cart.
    By aldos7 in forum What's Wrong With My Code?
    Replies: 36
    Last Post: December 16th, 2013, 06:45 AM
  2. Write a Java program to simulate an online shopping cart.
    By aldos7 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 15th, 2013, 12:53 AM
  3. Write a Java program to simulate an online shopping cart.
    By astjeanos in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 11th, 2013, 04:32 PM
  4. Shopping cart application
    By ashkrish in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 28th, 2012, 12:08 PM
  5. Replies: 1
    Last Post: February 8th, 2012, 05:16 PM