Current location - Training Enrollment Network - Books and materials - Java programming: Create a Book class with two private properties, which are string types name (title) and publish (output).
Java programming: Create a Book class with two private properties, which are string types name (title) and publish (output).
I wrote one, the method may be a little troublesome, but the requirement has been realized.

Book category:

Public books {

Private string name;

Private string publishing;

Public string getName() {

Returns the name;

}

Public void setName {

this.name = name

}

Public string getPublish() {

Return to publication;

}

Public void setPublish (

this.publish = publish

}

Public book (string name, string publishing) (

super();

this.name = name

this.publish = publish

}

Public books () {

}

}

Test category:

Public class test manual {

Public static void main(String[] args) {

Book Book 1 = new books (Data Structure, Higher Education);

Book book2 = new book (Operating System, Electronic Industry Press);

Book book3 = new book (Java, Electronic Industry Press);

Book book4 = new book (Data Structure, Tsinghua University Publishing House);

Collection & ltBook & gtc 1 = new array list & lt& gt ();

Collection & ltBook & gtc2 = new array list & lt& gt ();

Collection & ltBook & gtc3 = new array list & lt& gt ();

c 1 . add(book 1);

c 1 . add(book2);

C 1.add (Volume III);

C2.add (Volume II);

C2.add (Volume IV);

Boolean cont = false

for(Book book:c 1){

if(book.getName()。 equals(" Java ")& amp; & ampBook.getPublish()。 Equal to ("Machinery Industry Press") (

cont = true

}

}

System.out.println (continued);

For (Book book02:c2){

Boolean a = true;

for(Book Book 0 1:c 1){

if(book0 1.getName()。 equals(book 02 . getname())& amp; & ampbook0 1.getPublish()。 equals(book 02 . get publish()){

A = false;

}

}

If (a){

C3 . add(book 02);

}

}

For (Book B: C3) (

c 1 . add(b);

}

Iterator & lt book & gt iterator = c1.iterator ();

while(iterator.hasNext()){

book b = iterator . next();

system . out . println(" Title:"+b . getname());

system . out . println(" publisher:"+b . get publish());

}

}

}