) Book data type. Write a data type Book.java that implements a Book with a titl
ID: 3672561 • Letter: #
Question
) Book data type. Write a data type Book.java that implements a Book with a title, program, and condition (new or used). Include an equals() method.
a) Output sort by title and include program name and condition
b) Output sort by program and include title (sorted first) and condition
Books Program Condition
Algorithm 1 1
Networking1 2 2
C# Language 1 2
Heart Disease 3 2
Web Security 2 1
Java Love it 1 1
Nursing 2 1
Pascal 1 1
-------------------------------------------------------------------------------------
Programs:
1 = Programming
2 = IT
3 = Nursing
---------------------------------------------------------------
Book Condition
1 = new
2 = used
Explanation / Answer
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BookMain {
public static void main(String[] args)
{
List<Book> book=new ArrayList<Book>();
Book obj=new Book("Algorithm",1,1);
book.add(obj);
obj=new Book("Networking1",2,2);
book.add(obj);
obj=new Book("C# Language",1,2);
book.add(obj);
obj=new Book("Heart Disease",3,2);
book.add(obj);
obj=new Book("Web Security",2,1);
book.add(obj);
obj=new Book("Java Love it",1,1);
book.add(obj);
obj=new Book("Nursing",2,1);
book.add(obj);
String[] title=new String[book.size()];
int i=0;
System.out.println("Title Program Condition");
for(Book b:book)
{
System.out.println(b.getTitle()+" "+b.getProgram()+" "+b.getCondition());
}
}
}
public class Book
{
private String title;
private int program;
private int condition;
public String getTitle() {
return title;
}
public int getProgram() {
return program;
}
public int getCondition() {
return condition;
}
public void setTitle(String title) {
this.title = title;
}
public void setProgram(int program) {
this.program = program;
}
public void setCondition(int condition) {
this.condition = condition;
}
public Book(String title, int program, int condition) {
this.title = title;
this.program = program;
this.condition = condition;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.