Exercise (Solutions)


For a bookstore as described in the lesson, create Customer class. Every customer is identified by their name, lastName, gender and customerId which is a long number. Create a class to represent these customer information. Create a BookStore class and instantiate the Customer class and set values for two customers.


Extend the above problem, by creating OnlineCustomer and InStoreCustomer. OnlineCustomer should have an emailId field, and InStoreCustomer should have a mailing address. Instantiate these two classes in BookStore class and set some imaginary customer values.


You get compilation error on this program.

public class SomethingIsWrong {
   public static void main(String[] args) {
       Triangle myTriangle;
       myTriangle.base = 40;
       myTriangle.height = 50;
       System.out.println("My triangles area is " + myTriangle.area());

class Triangle{
    int base;
    int height;
    public int area(){
        return (this.base * this.height)/2;

Why are you not able to compile? How do you fix it?

results matching ""

    No results matching ""