165k views
3 votes
Define the missing method. licenseNum is created as: (100000 * customID) + licenseYear. Sample output: Dog license: 77702014

Here is the code already in the program:

// ===== Code from file DogLicense.java =====
public class DogLicense {
private int licenseYear;
private int licenseNum;

public void setYear(int yearRegistered) {
licenseYear = yearRegistered;
return;
}

// FIXME: Write createLicenseNum()

/* Your solution goes here */

public int getLicenseNum() {
return licenseNum;
}
}
// ===== end =====

// ===== Code from file CallDogLicense.java =====
public class CallDogLicense {
public static void main (String [] args) {
DogLicense dog1 = new DogLicense();

dog1.setYear(2014);
dog1.createLicenseNum(777);
System.out.println("Dog license: " + dog1.getLicenseNum());

return;
}
}
// ===== end =====

User SakiM
by
5.7k points

1 Answer

2 votes

Answer:

This is the missing method createLicenseNum()

public void createLicenseNum(int customID){

// the function createLicenseNum() with int type parameter customID

licenseNum = (100000 * customID) + licenseYear; }

//the formula for creating license number

Step-by-step explanation:

The whole program is given below:

public class DogLicense {

private int licenseYear;

private int licenseNum;

public void setYear(int yearRegistered) {

licenseYear = yearRegistered;

return; }

public void createLicenseNum(int customID){

licenseNum = (100000 * customID) + licenseYear; }

public int getLicenseNum() {

return licenseNum; } }

public class CallDogLicense {

public static void main (String [] args) {

DogLicense dog1 = new DogLicense();

dog1.setYear(2014);

dog1.createLicenseNum(777);

System.out.println("Dog license: " + dog1.getLicenseNum());

return; } }

The class DogLicense has two private int type variables licenseYear and licenseNum. It has three methods, setYear() which sets the licenseYear to yearRegistered, createLicenseNum() which is used to create a license number according to the given formula and has a parameter customID, getLicenseNum() which returns the license number which is created in the createLicenseNum().

The class CallDogLicense has a main function and an instance dog1 of class DogLicense. The object calls setYear() function to set the value of licenseYear as 2014 and calls createLicenseNum and passes value of customID as 777.

Finally getLicenseNum() function is called which returns the LicenseNum value and the output is Dog license: 77702014

The program output is attached as a screenshot.

Define the missing method. licenseNum is created as: (100000 * customID) + licenseYear-example-1
User Phts
by
5.6k points