Hello guys. I have a school assignment and Im having a trouble doing it. I will ask for help.

I have a class Product and I need to make 2 subclasses Chocolate and Whine.
Each product has a name, barcode, price and tax.
Each product has a method for calculating the price.
Each product has an attribute wich defines the product weight.
In Chocolate and Whine class I need to create a constructor for object creation.
In each class I need to define a method ToString for object information.
Finally I need to creaty one of each object for every class wich shows product information.

Thanks in advance.

public class Product {
    private String barcode;
    private String name;
    private double price;
        private double tax;




    public Product(String barcode, String name, double price
                   ) {
        this.barcode=barcode;
        this.name=name;
        this.price=price;
                this.tax=tax;


    }

        @Override
    public String toString() {
        return name;
    }

    public String getBarcode() {
        return barcode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

        public double getTax() {
        return tax;
    }


    public String getInfo() {
        return barcode+" "+name+" "+price;
    }


    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

}

2.Each product has a method for calculating the price.
5.In each class I need to define a method ToString for object information.
6.Finally I need to creaty one of each object for every class wich shows product information.
I need help with this

What have you tried so far? Have you created the subclasses like the tutorial I linked?

Yes I have subclasses and constructors created

Sorry, I don't understand what help you need - you have created your classes, you have created various methods, including overridden methods, so now all you need is a bit more of the same. You already know how to do it all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.