Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3599338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:19+00:00 2026-05-18T20:21:19+00:00

I have a Assignment question about Java Generics. The given class is Product.java. It

  • 0

I have a Assignment question about Java Generics. The given class is Product.java. It has abstract class Product, then ComputerPart, Peripheral, Fruit, Cheese, and Service extends Product.

  1. Carefully study the class structure in Products.java.
  2. Design a generic container called GenericOrder that acts as a collection of an arbitrary number of objects in Products.java. Design a mechanism that gives each instance of the container a unique identifier. Implement as many methods as necessary. You must use Java generics features.
  3. Design and implement a subclass of GenericOrder called ComputerOrder that takes an arbitrary number of different classes of ComputerPart objects, Peripheral objects, and Service objects. Implement as many methods as necessary.
  4. Design and implement a subclass of GenericOrder called PartyTrayOrder that takes an arbitrary number of different classes of Cheese objects, Fruit objects, and Service objects. Implement as many methods as necessary.
  5. Design and implement a class called OrderProcessor. You must implement at least the following methods:

    accept; // this method accepts a GenericOrder or any of its subclass objects and stores it in any internal collection of OrderProcessor.
    
    
    process; // this method sorts all accepted orders in the internal collection of GenericOrder into collections of ComputerPart, Peripheral, Cheese, Fruit, and Service. You must associate each object with the unique identifier. You may refer to the TwoTuple.java example in the text book.
    
    
    dispatchXXX; // this method simulates the dispatch of the sorted collections. For example, the method dispatchComputerParts() should produce this output:
    
    
    Motherboard  name=Asus, price=$37.5, order number=123456
    
    
    Motherboard  name=Asus, price=$37.5, order number=987654
    
    
    RAM  name=Kingston, size=512, price=$25.0, order number=123456
    
    
    You may overload each of the above methods as you think necessary.
    
  6. Create a client class to test OrderProcessor. You will need to create a datagenerator for testing purpose. It is not mandatory but you may use a variation of Data Generator in TIJ pages 637 to 638.

  7. Pack the above codes into one single zip file and send it to your tutor.

I have done the 1 requirment, but I have trouble to understand 2nd one. Here is the code I did:

public class GenericOrder<T> {
    private static long counter = 1;
    private final long id = counter++;
    private List<T> products;
    private T theClass;

    public GenericOrder() 
    {
        products = new ArrayList<T>();
    }

    public long getId() {
        return id;
    }

    public void addProduct(T newProduct) {
        products.add(newProduct);

    }

    public int getNumberOfProducts() {
        return products.size();
    }

    public List<T> getProducts()
    {
        return products;
    }

    public void setProducts(List<T> products)
    {
        this.products = products;
    }

    public T get()
    {
        return theClass;
    }

    public void set(T theClass)
    {
        this.theClass = theClass;
    }
}
public class ComputerOrder<T> extends GenericOrder<T> {
    private List<T> products; 
    private T theClass;

    public ComputerOrder() 
    {
        products = new ArrayList<T>();
    }


    public void addProduct(T newProduct) {
        products.add(newProduct);

    }

    public int getNumberOfProducts() {
        return products.size();
    }

    public List<T> getProducts()
    {
        return products;
    }

    public void setProducts(List<T> products)
    {
        this.products = products;
    }

    public T get()
    {
        return theClass;
    }

    public void set(T theClass)
    {
        this.theClass = theClass;
    }
}

Please help me out here, see if anyone understand 2nd requirement better than I do.
Thanks all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:21:20+00:00Added an answer on May 18, 2026 at 8:21 pm

    I think part two is looking for a class that has an upper bound type restriction, so perhaps something like this:

    public class ComputerOrder<T extends Product> extends GenericOrder<T> {
        // etc...
    }
    

    Edit

    I missed the Fruit and Cheese classes. In order for type bounding to work, you would most likely need to code your computer products to an interface and use the following:

    public class ComputerOrder<T implements MyInterface> extends GenericOrder<T> {
        // etc...
    }
    

    For more information on bounded type parameters, read here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Assignment question about Java Generics. The given class is Product.java. It
I'm new to Java and have a question about a warning: My general code:
I have an assignment in a language-independent class, and part of it is using
I have to write a multiplayer pacman game in Java for a university assignment
I'm taking a class on JSP and I have an assignment... we have to
I have a question about using attr_accessible in Rails. I sometimes want to set
I have a assignment question. How to integrate Sql Server Reporting Service (SSRS) with
I've a question about initialization of inherited members in constructor of derived class. Example
So I am being taught assembly and we have an assignment which is to
For my assignment I have been assigned the task of creating a DTD for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.