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: Design Java Generic Container-please help!!!

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Design Java Generic Container-please help!!!

    Hi all,
    I am currently learning Java from a university course. I am stuck with one of my assignment. I am a database developer, object-oriented is not my thing. Please help out!

    The given Products.java class is following:

    abstract class Products {
    protected float price;

    // return the price of a particular product
    abstract float price();
    }

    //------------------------------------------------------------

    class ComputerPart extends Products {
    public ComputerPart(float p) {
    price = p;
    }

    public float price() { return price; }
    }

    class Motherboard extends ComputerPart {
    protected String manufacturer;
    public Motherboard(String mfg, float p) {
    super(p);
    manufacturer = mfg;
    }
    public String getManufacturer() { return manufacturer; }
    }

    class RAM extends ComputerPart {
    protected int size;
    protected String manufacturer;
    public RAM(String mfg, int size, float p) {
    super(p);
    this.manufacturer = mfg;
    this.size = size;
    }
    public String getManufacturer() { return manufacturer; }
    }

    class Drive extends ComputerPart {
    protected String type;
    protected int speed;
    public Drive(String type, int speed, float p) {
    super(p);
    this.type = type;
    this.speed = speed;
    }
    public String getType() { return type; }
    public int getSpeed() { return speed; }
    }


    class Peripheral extends Products {
    public Peripheral(float p) {
    price = p;
    }
    public float price() { return price; }
    }

    class Printer extends Peripheral {
    protected String model;
    public Printer(String model, float p) {
    super(p);
    this.model = model;
    }
    public String getModel() { return model; }
    }

    class Monitor extends Peripheral {
    protected String model;
    public Monitor(String model, float p) {
    super(p);
    this.model = model;
    }
    public String getModel() { return model; }
    }

    class Service extends Products {
    public Service(float p) {
    price = p;
    }
    public float price() { return price; }
    }

    class AssemblyService extends Service {
    String provider;
    public AssemblyService(String pv, float p) {
    super(p);
    provider = pv;
    }
    public String getProvider() { return provider; }
    }

    class DeliveryService extends Service {
    String courier;
    public DeliveryService(String c, float p) {
    super(p);
    courier = c;
    }
    public String getCourier() { return courier; }
    }

    //-------------------------------------------------------
    class Cheese extends Products {
    public Cheese(float p) {
    price = p;
    }
    public float price() { return price; }
    }

    class Cheddar extends Cheese {
    public Cheddar(float p) {
    super(p);
    }
    }
    class Mozzarella extends Cheese {
    public Mozzarella(float p) {
    super(p);
    }
    }

    class Fruit extends Products {
    public Fruit(float p) {
    price = p;
    }
    public float price() { return price; }
    }
    class Apple extends Fruit {
    public Apple(float p) {
    super(p);
    }
    }
    class Orange extends Fruit {
    public Orange(float p) {
    super(p);
    }
    }



    The first requirement is 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.

    Please help me with this in anyway you can think of, i am totally lost on this.

    Thanks in advance


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Design Java Generic Container-please help!!!

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/34687-java-generic-container-question-please-help.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    db


Similar Threads

  1. Class design
    By arithmetics in forum Object Oriented Programming
    Replies: 4
    Last Post: November 4th, 2010, 08:44 AM
  2. Not Generic; cannot be parameterized
    By javaoo in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2010, 09:53 AM
  3. HELP! Design Review & Risk Management topics (in java projects)required
    By gangestech in forum Java Theory & Questions
    Replies: 0
    Last Post: September 6th, 2010, 04:11 AM
  4. generic class
    By fireatmuself in forum Collections and Generics
    Replies: 4
    Last Post: November 17th, 2009, 06:06 AM
  5. Generic programming example
    By neo_2010 in forum Java Programming Tutorials
    Replies: 3
    Last Post: July 8th, 2009, 11:38 AM