Answer:
Class Locker
public class Locker {
int lockno;
String student;
int booksno;
private CombinationLock comblock = new CombinationLock();
public Locker() {
lockno = 0;
student= "No Name";
booksno = 0;
comblock.reset(); }
public Locker(int lockno, String student, int booksno,
CombinationLock comblock) {
super();
this.lockno= lockno;
this.student= student;
this.booksno= booksno;
this.comblock= comblock; }
public int getLockNo() {
return lockno; }
public void setLockNo(int lockno) {
this.lockno= lockno; }
public String getName() {
return student; }
public void setName(String student) {
this.student = student; }
public int getBooksNumber() {
return booksno; }
public void setBooksNumber(int booksno) {
this.booksno= booksno; }
public String getComblock() {
return comblock.toString(); }
public void setComblock(int no1, int no2, int no3) {
this.comblock.setNo1(no1);
this.comblock.setNo2(no2);
this.comblock.setNo3(no3); }
public String printValues() {
return "Locker [lockno=" + lockno+ ", student="
+ student+ ", booksno=" + booksno
+ ", comblock=" + comblock+ "]"; } }
The class Locker has attributes lockno for lock number, student for students names and bookno for recording number of books. Locker class also an attribute of type CombinationLock named as comblock. Locker class includes a constructor Locker() with no input argument and also a constructor Locker() that requires input arguments for all attributes lockno, student, booksno and comblock. super() calls on immediate parent class constructor. Class Locker contains the following set methods: setLockNo, setName, setBooksNumber and setComblock. Class Locker contains the following get methods: getLockNo, getName, getBooksNumber and getComblock. printValues() method displays the values of attributes.
Step-by-step explanation:
Class CombinationLock
*/ CombinationLock has attributes no1, no2 and no3. It has a constructor CombinationLock() with no input argument and also a constructor CombinationLock() that requires input arguments for attributes no1 no2 and no3. Class CombinationLock contains the following set methods: setNo1, setNo2 and setNo3. The class contains the following get methods: getNo1, getNo2 and getNo3. The class includes a method printValues() to print out all attributes.
public class CombinationLock {
int no1;
int no2;
int no3;
public CombinationLock() {
this.no1= 0;
this.no2= 0;
this.no3= 0; }
public CombinationLock(int no1, int no2, int no3) {
super();
this.no1= no1;
this.no2= no2;
this.no3= no3; }
public int getNo1() {
return no1; }
public void setNo1(int no1) {
this.no1= no1; }
public int getNo2() {
return no2; }
public void setNo2(int no2) {
this.no2= no2; }
public int getNo3() {
return no3; }
public void setNo3(int no3) {
this.no3= no3; }
public void reset() {
this.no1=0;
this.no2=0;
this.no3=0; }
public String printValues() {
return "CombinationLock [no1=" + no1+ ", no2=" + no2
+ ", no3=" + no3+ "]"; } }