Question

3. Define a class License. A License has a license number and an suggest using java.time.LocalDate, but there are other possi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.


package License;

import java.util.Date;


public class License {
private String _LicenseNo ;
private Date _ExpiryDate ;
  
/**
*
* @param LicNo
* @param ExpDate
*/
public License(String LicNo,Date ExpDate)
{
this._LicenseNo = LicNo;
this._ExpiryDate = ExpDate;
}
  
public String getLicenseNo()
{
return this._LicenseNo;
}
  
public Date getExpiryDate()
{
return this._ExpiryDate;
}
  
public Boolean Expired()
{
if( new Date().after(_ExpiryDate))
{
return true;
}
return false;
}
/*
Check the current instance license number with passed license instance
if equal then returns true otherwise return false
*/
public Boolean equals(License lic)
{
if(lic.getLicenseNo().equals(this._LicenseNo))
{
return true;
}
return false;
}
  
public String toString()
{
return "License No :"+this._LicenseNo+", ExpiryDate : "+this._ExpiryDate;
}
  
  
}

2.


package License;

import java.util.Date;


public class DriversLicense extends License {
private String _State;
public DriversLicense(String LicNo, Date ExpDate, String State) {
super(LicNo, ExpDate);
this._State = State;
}
@Override
public Boolean equals(License lic)
{
if((this._State.equals(((DriversLicense)lic)._State)) && (this.getLicenseNo().equals(lic.getLicenseNo())))
{
return true;
}
return false;
}
  
public String getState()
{
return this._State;
}
  
public String toString()
{
return "License No:"+this.getLicenseNo()+", State : "+this._State+", ExpiryDate :"+this.getExpiryDate();
}
}

3.


package License;

import java.util.Date;


public class TruckDriversLicense extends DriversLicense {
  
public TruckDriversLicense(String LicNo, Date ExpDate, String State) {
super(LicNo, ExpDate, State);
}
@Override
public String toString()
{
return "Truck Drivers License No:"+this.getLicenseNo()+", State : "+this.getState()+", ExpiryDate :"+this.getExpiryDate();
}
}

4.


package License;

import java.util.Date;

/**
*
* @author Gajendra
*/
public class FishingLicense extends License {
private String _Type;

public FishingLicense(String LicNo, Date ExpDate, String Type) {
super(LicNo, ExpDate);
this._Type =Type;
}
  
@Override
public String toString()
{
return "Fishing License No:"+this.getLicenseNo()+", Type : "+this._Type+", ExpiryDate :"+this.getExpiryDate();
}
  
}

5.

package License;

import java.util.Date;

public class LicenseTest {

public static void main(String[] args) {
Date d1 = new Date();

License l1 = new License("001", d1);
License l2 = new License("002", d1);
System.out.println(l1.equals(l2));
License l3 = new License("001", d1);
System.out.println(l1.equals(l3));

TruckDriversLicense t1 = new TruckDriversLicense("0001", d1, "MP");
TruckDriversLicense t2 = new TruckDriversLicense("0001", d1, "MP");
System.out.println(t1.equals(t2));
TruckDriversLicense t3 = new TruckDriversLicense("0001", d1, "UP");
System.out.println(t1.equals(t3));
System.out.println(t1.toString());
  
FishingLicense f1 = new FishingLicense("0001", d1, "Fish");
System.out.println(f1.toString());
  
}
}

output:

run:
false
true
true
false
Truck Drivers License No:0001, State : MP, ExpiryDate :Sun Jun 09 13:47:21 IST 2019
Fishing License No:0001, Type : Fish, ExpiryDate :Sun Jun 09 13:47:21 IST 2019
BUILD SUCCESSFUL (total time: 1 second)

Add a comment
Know the answer?
Add Answer to:
3. Define a class License. A License has a license number and an suggest using java.time.LocalDate, but there are o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define...

    Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Define an abstract class GeometricShape with a color (string), filled (boolean), and dateCreated (java.util.Date) GeometricShape has...

    Define an abstract class GeometricShape with a color (string), filled (boolean), and dateCreated (java.util.Date) GeometricShape has getter/setter methods for each attribute, along with a getArea, a getPerimeter, and toString method that returns the shape information in a formatted string including class name, color, filled, dimensions (if available), area, perimeter, and date created Additionally GeometricShape implements the Java Comparable interface and defines a static method max used to find the larger of two GeometricShapes based on their area

  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in...

    Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author fenghui */ public class Course {     private String cName;     private ArrayList<Subject> cores;     private ArrayList<Major> majors;     private ArrayList<Subject> electives;     private int cCredit;          public Course(String n, int cc){         cName = n;         cCredit = cc;         cores = new ArrayList<Subject>(0);         majors =...

  • CappedChecking – represents a checking account that disallows a balance above a particular maximum value. Class...

    CappedChecking – represents a checking account that disallows a balance above a particular maximum value. Class CappedChecking - deposit - deposits a given amount into the account as described previously link - given an account acct, link this account with acct account will be labeled as Filterable.That is,you must appropriately define an abstract class or interface representing the filterable notion. Each such filterable class must implement the method boolean accept() which returns true or false based on the following criteria:...

  • Java Time Class Class declarations are one of the ways of defining new types in Java....

    Java Time Class Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows. int getHours(): returns the number of hours int getMinutes(): returns the number of minutes int getSeconds(): returns the number of seconds String toString(): returns a String representation boolean equals(Time other): returns true if and only if other designates an object that has the...

  • Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a...

    Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import    java.time.temporal.ChronoUnit; public class LibraryCard {    private String id;    private String cardholderName;   ...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT