question archive 1) Explain in a short note on Java Abstract class and give a situation in which it will be useful

1) Explain in a short note on Java Abstract class and give a situation in which it will be useful

Subject:Computer SciencePrice:3.86 Bought15

1) Explain in a short note on Java Abstract class and give a situation in which it will be useful. 

2.    A police licensing department software is mainly based on a database of driving licences and vehicle licences. However, sometimes some complicated checking needs to be done concerning offences and so some of the data is loaded into an object-oriented program. Each licence has a file number, payment status, renewal date and date of first being granted. A vehicle licence has a vehicle description, a vehicle category, a current owner and a list of previous owners with dates of ownership. An owner is either a person or a company. A driver licence has a licensee (which is a person) and a list of categories of vehicles which they are allowed to drive. Each owner and each licensee has a name, address, list of vehicles currently owned, list of vehicles owned in the past and list of past (and present) offences. An offence has a date, offender (owner or licensee), and penalty.

           Present a good design for the arrangement of classes for the object-oriented          program. You can make other reasonable assumptions about the details. Explain your         assumptions and the reasons behind your design decisions. Include the data members and            their types, and important methods for each class. 

           List of items to be delivered: 

                       1. Key classes

                       2. Their main attributes (field variables) and methods

                       3. The relationships between the classes, eg you can write Class 1 inherits from                            Class 2; Class A is a Composition part in Class B and it is a one to many                                              relationship etc. 

                       4. You do not need to supply a drawing design of UML.

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Short note on Java Abstract class

Java Abstract Classes are the classes marked with the keyword abstract and they cannot be instantiated which simply means you cannot create an object of an abstract class. They may or may not provide implementation for their methods.

 

Situation in which they are useful

 

They help in code reusability between related classes among other things. For example, all kinds of shapes have an area, so one can define an abstract class called Shape and then define the area() method, and then the subclasses of class Shape such as Circle, Rectangle and Square can provide their own implementations for area() method by simply overriding it. Now, instead of creating multiple classes with their own area() methods, you provide one through the Shape abstract class that can be shared by all the subclasses.

 

Now, let's go through the second question :) I am using a small portion of your question here to highlight the process of extracting useful information from your question.

 

```A police licensing department software is mainly based on a database of driving licences and vehicle licences. However, sometimes some complicated checking needs to be done concerning offences and so some of the data is loaded into an object-oriented program.

 

Each licence has a file number, payment status, renewal date and date of first being granted. [done for you]

 

A vehicle licence has a vehicle description, a vehicle category, a current owner and a list of previous owners with dates of ownership. [done for you]

 

An owner is either a person or a company. [done for you]

 

A driver licence has a licensee (which is a person) and a list of categories of vehicles which they are allowed to drive. [done for you]

 

Each owner and each licensee has a name, address, list of vehicles currently owned, list of vehicles owned in the past and list of past (and present) offences. [done for you]

 

An offence has a date, offender (owner or licensee), and penalty.

```

 

Now, closely pay attention to the nouns such as licence, owner, offence and the clauses such as `has a` and `is a`. Roughly, `has a` means Composition & `is a` means Inheritance.

 

Also, there are two types of licences and it says all licence have a file number, payment status...

 

So, the first thing you do is to define a class Licence with attributes file number, payment status...

 

class Licence {

    private int fileNumber;
    private PaymentStatus paymentStatus;
    private Date renewalDate;
    private Date grantingDate;
}

 

Also, pay attention to owner is either a person or company...

 

So, in code or in Java this means

 

class Owner {
    private String name;
    private String address;
    private Date dateOfOwnership;
    private Vehicle[] ownedInPast;
    private Offence[] allOffences;
}

class Person extends Owner{
}

class Company extends Owner{
}

 

Now lets, define other key classes VehicleLicence and DrivingLicence

 

class VehicleLicence extends Licence {
    private String vehicleDescription;
    private String vehicleCategory;
    private Owner currentOwner;
    private Owner[] previousOwners;
}

class DrivingLicence extends Licence {
    private Person Licensee;
    private Category[] vehiclesAllowed;
}

 

Now, I leave the last part for you to figure out with the help of above, don't worry you can do it. :-)